/* Generated by Cython 0.29.35 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/arrayscalars.h",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/npy_math.h",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include/numpy/ufuncobject.h",
            "discretize/_extensions/tree.h"
        ],
        "include_dirs": [
            "./discretize/_extensions",
            "/home/vsts/conda/envs/discretize-test/lib/python3.10/site-packages/numpy/core/include"
        ],
        "language": "c++",
        "name": "discretize._extensions.tree_ext",
        "sources": [
            "discretize/_extensions/tree_ext.pyx",
            "discretize/_extensions/tree.cpp"
        ]
    },
    "module_name": "discretize._extensions.tree_ext"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_29_35"
#define CYTHON_HEX_VERSION 0x001D23F0
#define CYTHON_FUTURE_DIVISION 1
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x02070000
    #define HAVE_LONG_LONG
  #endif
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #if PY_VERSION_HEX < 0x03090000
    #undef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PY_NOGIL)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #ifndef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5)
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 0
  #elif !defined(CYTHON_FAST_THREAD_STATE)
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030A0000)
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
  #ifndef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5))
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  #endif
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef __cplusplus
  #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
#endif
#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #else
    #define CYTHON_INLINE inline
  #endif
#endif
template<typename T>
void __Pyx_call_destructor(T& x) {
    x.~T();
}
template<typename T>
class __Pyx_FakeReference {
  public:
    __Pyx_FakeReference() : ptr(NULL) { }
    __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
    T *operator->() { return ptr; }
    T *operator&() { return ptr; }
    operator T&() { return *ptr; }
    template<typename U> bool operator ==(U other) { return *ptr == other; }
    template<typename U> bool operator !=(U other) { return *ptr != other; }
  private:
    T *ptr;
};

#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_DefaultClassType PyType_Type
#if PY_VERSION_HEX >= 0x030B00A1
    static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
        PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
        const char *fn_cstr=NULL;
        const char *name_cstr=NULL;
        PyCodeObject* co=NULL;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        if (!(kwds=PyDict_New())) goto end;
        if (!(argcount=PyLong_FromLong(a))) goto end;
        if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
        if (!(posonlyargcount=PyLong_FromLong(0))) goto end;
        if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
        if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
        if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
        if (!(nlocals=PyLong_FromLong(l))) goto end;
        if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
        if (!(stacksize=PyLong_FromLong(s))) goto end;
        if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
        if (!(flags=PyLong_FromLong(f))) goto end;
        if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
        if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
        if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
        if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
        if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
        if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
        if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
        Py_XDECREF((PyObject*)co);
        co = (PyCodeObject*)call_result;
        call_result = NULL;
        if (0) {
            cleanup_code_too:
            Py_XDECREF((PyObject*)co);
            co = NULL;
        }
        end:
        Py_XDECREF(kwds);
        Py_XDECREF(argcount);
        Py_XDECREF(posonlyargcount);
        Py_XDECREF(kwonlyargcount);
        Py_XDECREF(nlocals);
        Py_XDECREF(stacksize);
        Py_XDECREF(replace);
        Py_XDECREF(call_result);
        Py_XDECREF(empty);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return co;
    }
#else
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
  #define PyMem_RawFree(p)             PyMem_Free(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_READY(op)       (0)
  #else
    #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                                0 : _PyUnicode_Ready((PyObject *)(op)))
  #endif
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #else
    #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
    #else
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    #endif
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #if !defined(_USE_MATH_DEFINES)
    #define _USE_MATH_DEFINES
  #endif
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__discretize___extensions__tree_ext
#define __PYX_HAVE_API__discretize___extensions__tree_ext
/* Early includes */
#include <string.h>
#include <stdio.h>
#include "numpy/arrayobject.h"
#include "numpy/ndarrayobject.h"
#include "numpy/ndarraytypes.h"
#include "numpy/arrayscalars.h"
#include "numpy/ufuncobject.h"

    /* NumPy API declarations from "numpy/__init__.pxd" */
    
#include <stdlib.h>
#include "ios"
#include "new"
#include "stdexcept"
#include "typeinfo"
#include <vector>
#include "numpy/npy_math.h"
#include <utility>

    #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)
    // move should be defined for these versions of MSVC, but __cplusplus isn't set usefully
    #include <type_traits>

    namespace cython_std {
    template <typename T> typename std::remove_reference<T>::type&& move(T& t) noexcept { return std::move(t); }
    template <typename T> typename std::remove_reference<T>::type&& move(T&& t) noexcept { return std::move(t); }
    }

    #endif
    
#include <map>
#include "tree.h"
#include "pythread.h"
#include "pystate.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;

/* Header.proto */
#if !defined(CYTHON_CCOMPLEX)
  #if defined(__cplusplus)
    #define CYTHON_CCOMPLEX 1
  #elif defined(_Complex_I)
    #define CYTHON_CCOMPLEX 1
  #else
    #define CYTHON_CCOMPLEX 0
  #endif
#endif
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #include <complex>
  #else
    #include <complex.h>
  #endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
  #undef _Complex_I
  #define _Complex_I 1.0fj
#endif


static const char *__pyx_f[] = {
  "discretize/_extensions/tree_ext.pyx",
  "stringsource",
  "__init__.pxd",
  "type.pxd",
};
/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()

/* MemviewSliceStruct.proto */
struct __pyx_memoryview_obj;
typedef struct {
  struct __pyx_memoryview_obj *memview;
  char *data;
  Py_ssize_t shape[8];
  Py_ssize_t strides[8];
  Py_ssize_t suboffsets[8];
} __Pyx_memviewslice;
#define __Pyx_MemoryView_Len(m)  (m.shape[0])

/* Atomics.proto */
#include <pythread.h>
#ifndef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 1
#endif
#define __PYX_CYTHON_ATOMICS_ENABLED() CYTHON_ATOMICS
#define __pyx_atomic_int_type int
#if CYTHON_ATOMICS && (__GNUC__ >= 5 || (__GNUC__ == 4 &&\
                    (__GNUC_MINOR__ > 1 ||\
                    (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 2))))
    #define __pyx_atomic_incr_aligned(value) __sync_fetch_and_add(value, 1)
    #define __pyx_atomic_decr_aligned(value) __sync_fetch_and_sub(value, 1)
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Using GNU atomics"
    #endif
#elif CYTHON_ATOMICS && defined(_MSC_VER) && CYTHON_COMPILING_IN_NOGIL
    #include <intrin.h>
    #undef __pyx_atomic_int_type
    #define __pyx_atomic_int_type long
    #pragma intrinsic (_InterlockedExchangeAdd)
    #define __pyx_atomic_incr_aligned(value) _InterlockedExchangeAdd(value, 1)
    #define __pyx_atomic_decr_aligned(value) _InterlockedExchangeAdd(value, -1)
    #ifdef __PYX_DEBUG_ATOMICS
        #pragma message ("Using MSVC atomics")
    #endif
#else
    #undef CYTHON_ATOMICS
    #define CYTHON_ATOMICS 0
    #ifdef __PYX_DEBUG_ATOMICS
        #warning "Not using atomics"
    #endif
#endif
typedef volatile __pyx_atomic_int_type __pyx_atomic_int;
#if CYTHON_ATOMICS
    #define __pyx_add_acquisition_count(memview)\
             __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview))
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview))
#else
    #define __pyx_add_acquisition_count(memview)\
            __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
    #define __pyx_sub_acquisition_count(memview)\
            __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
#endif

/* BufferFormatStructs.proto */
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name;
  struct __Pyx_StructField_* fields;
  size_t size;
  size_t arraysize[8];
  int ndim;
  char typegroup;
  char is_unsigned;
  int flags;
} __Pyx_TypeInfo;
typedef struct __Pyx_StructField_ {
  __Pyx_TypeInfo* type;
  const char* name;
  size_t offset;
} __Pyx_StructField;
typedef struct {
  __Pyx_StructField* field;
  size_t parent_offset;
} __Pyx_BufFmt_StackElem;
typedef struct {
  __Pyx_StructField root;
  __Pyx_BufFmt_StackElem* head;
  size_t fmt_offset;
  size_t new_count, enc_count;
  size_t struct_alignment;
  int is_complex;
  char enc_type;
  char new_packmode;
  char enc_packmode;
  char is_valid_array;
} __Pyx_BufFmt_Context;


/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":689
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":690
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":691
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":692
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":696
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":697
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":698
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":699
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":703
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":704
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":713
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":714
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":715
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":717
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":718
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":719
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":721
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":722
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":724
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":725
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":726
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif
static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);


/*--- Type declarations ---*/
struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell;
struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh;
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine;
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx;
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx;
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx;
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx;
struct __pyx_array_obj;
struct __pyx_MemviewEnum_obj;
struct __pyx_memoryview_obj;
struct __pyx_memoryviewslice_obj;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":728
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":729
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":730
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":732
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;

/* "discretize/_extensions/tree_ext.pyx":18
 * 
 * 
 * cdef class TreeCell:             # <<<<<<<<<<<<<<
 *     """A class for defining cells within instances of :class:`~discretize.TreeMesh`.
 * 
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell {
  PyObject_HEAD
  struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_vtab;
  double _x;
  double _y;
  double _z;
  double _x0;
  double _y0;
  double _z0;
  double _wx;
  double _wy;
  double _wz;
  int_t _dim;
  Cell *_cell;
};


/* "discretize/_extensions/tree_ext.pyx":311
 *     return <int> func(pycell)
 * 
 * cdef class _TreeMesh:             # <<<<<<<<<<<<<<
 *     cdef c_Tree *tree
 *     cdef PyWrapper *wrapper
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh {
  PyObject_HEAD
  Tree *tree;
  PyWrapper *wrapper;
  int_t _dim;
  int_t ls[3];
  int _finalized;
  bool _diagonal_balance;
  __Pyx_memviewslice _xs;
  __Pyx_memviewslice _ys;
  __Pyx_memviewslice _zs;
  __Pyx_memviewslice _origin;
  PyObject *_cell_centers;
  PyObject *_nodes;
  PyObject *_hanging_nodes;
  PyObject *_edges_x;
  PyObject *_edges_y;
  PyObject *_edges_z;
  PyObject *_hanging_edges_x;
  PyObject *_hanging_edges_y;
  PyObject *_hanging_edges_z;
  PyObject *_faces_x;
  PyObject *_faces_y;
  PyObject *_faces_z;
  PyObject *_hanging_faces_x;
  PyObject *_hanging_faces_y;
  PyObject *_hanging_faces_z;
  PyObject *_h_gridded;
  PyObject *_cell_volumes;
  PyObject *_face_areas;
  PyObject *_edge_lengths;
  PyObject *_average_face_x_to_cell;
  PyObject *_average_face_y_to_cell;
  PyObject *_average_face_z_to_cell;
  PyObject *_average_face_to_cell;
  PyObject *_average_face_to_cell_vector;
  PyObject *_average_node_to_cell;
  PyObject *_average_node_to_edge;
  PyObject *_average_node_to_edge_x;
  PyObject *_average_node_to_edge_y;
  PyObject *_average_node_to_edge_z;
  PyObject *_average_node_to_face;
  PyObject *_average_node_to_face_x;
  PyObject *_average_node_to_face_y;
  PyObject *_average_node_to_face_z;
  PyObject *_average_edge_x_to_cell;
  PyObject *_average_edge_y_to_cell;
  PyObject *_average_edge_z_to_cell;
  PyObject *_average_edge_to_cell;
  PyObject *_average_edge_to_cell_vector;
  PyObject *_average_cell_to_face;
  PyObject *_average_cell_vector_to_face;
  PyObject *_average_cell_to_face_x;
  PyObject *_average_cell_to_face_y;
  PyObject *_average_cell_to_face_z;
  PyObject *_face_divergence;
  PyObject *_edge_curl;
  PyObject *_nodal_gradient;
  PyObject *__pyx___ubc_order;
  PyObject *__pyx___ubc_indArr;
};


/* "discretize/_extensions/tree_ext.pyx":448
 *         self.__ubc_indArr = None
 * 
 *     def refine(self, function, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` with user-defined function.
 * 
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine {
  PyObject_HEAD
  PyObject *__pyx_v_level;
};


/* "discretize/_extensions/tree_ext.pyx":5275
 *         return P*Rf
 * 
 *     def _getFacePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx {
  PyObject_HEAD
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self;
};


/* "discretize/_extensions/tree_ext.pyx":5280
 *         return Pxx
 * 
 *     def _getFacePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx {
  PyObject_HEAD
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self;
};


/* "discretize/_extensions/tree_ext.pyx":5331
 *         return P*Rf
 * 
 *     def _getEdgePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx {
  PyObject_HEAD
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self;
};


/* "discretize/_extensions/tree_ext.pyx":5336
 *         return Pxx
 * 
 *     def _getEdgePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 */
struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx {
  PyObject_HEAD
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self;
};


/* "View.MemoryView":106
 * 
 * @cname("__pyx_array")
 * cdef class array:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_array_obj {
  PyObject_HEAD
  struct __pyx_vtabstruct_array *__pyx_vtab;
  char *data;
  Py_ssize_t len;
  char *format;
  int ndim;
  Py_ssize_t *_shape;
  Py_ssize_t *_strides;
  Py_ssize_t itemsize;
  PyObject *mode;
  PyObject *_format;
  void (*callback_free_data)(void *);
  int free_data;
  int dtype_is_object;
};


/* "View.MemoryView":280
 * 
 * @cname('__pyx_MemviewEnum')
 * cdef class Enum(object):             # <<<<<<<<<<<<<<
 *     cdef object name
 *     def __init__(self, name):
 */
struct __pyx_MemviewEnum_obj {
  PyObject_HEAD
  PyObject *name;
};


/* "View.MemoryView":331
 * 
 * @cname('__pyx_memoryview')
 * cdef class memoryview(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef object obj
 */
struct __pyx_memoryview_obj {
  PyObject_HEAD
  struct __pyx_vtabstruct_memoryview *__pyx_vtab;
  PyObject *obj;
  PyObject *_size;
  PyObject *_array_interface;
  PyThread_type_lock lock;
  __pyx_atomic_int acquisition_count[2];
  __pyx_atomic_int *acquisition_count_aligned_p;
  Py_buffer view;
  int flags;
  int dtype_is_object;
  __Pyx_TypeInfo *typeinfo;
};


/* "View.MemoryView":967
 * 
 * @cname('__pyx_memoryviewslice')
 * cdef class _memoryviewslice(memoryview):             # <<<<<<<<<<<<<<
 *     "Internal class for passing memoryview slices to Python"
 * 
 */
struct __pyx_memoryviewslice_obj {
  struct __pyx_memoryview_obj __pyx_base;
  __Pyx_memviewslice from_slice;
  PyObject *from_object;
  PyObject *(*to_object_func)(char *);
  int (*to_dtype_func)(char *, PyObject *);
};



/* "discretize/_extensions/tree_ext.pyx":18
 * 
 * 
 * cdef class TreeCell:             # <<<<<<<<<<<<<<
 *     """A class for defining cells within instances of :class:`~discretize.TreeMesh`.
 * 
 */

struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell {
  void (*_set)(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *, Cell *);
};
static struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_vtabptr_10discretize_11_extensions_8tree_ext_TreeCell;


/* "View.MemoryView":106
 * 
 * @cname("__pyx_array")
 * cdef class array:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_array {
  PyObject *(*get_memview)(struct __pyx_array_obj *);
};
static struct __pyx_vtabstruct_array *__pyx_vtabptr_array;


/* "View.MemoryView":331
 * 
 * @cname('__pyx_memoryview')
 * cdef class memoryview(object):             # <<<<<<<<<<<<<<
 * 
 *     cdef object obj
 */

struct __pyx_vtabstruct_memoryview {
  char *(*get_item_pointer)(struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*is_slice)(struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*setitem_slice_assignment)(struct __pyx_memoryview_obj *, PyObject *, PyObject *);
  PyObject *(*setitem_slice_assign_scalar)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *);
  PyObject *(*setitem_indexed)(struct __pyx_memoryview_obj *, PyObject *, PyObject *);
  PyObject *(*convert_item_to_object)(struct __pyx_memoryview_obj *, char *);
  PyObject *(*assign_item_from_object)(struct __pyx_memoryview_obj *, char *, PyObject *);
};
static struct __pyx_vtabstruct_memoryview *__pyx_vtabptr_memoryview;


/* "View.MemoryView":967
 * 
 * @cname('__pyx_memoryviewslice')
 * cdef class _memoryviewslice(memoryview):             # <<<<<<<<<<<<<<
 *     "Internal class for passing memoryview slices to Python"
 * 
 */

struct __pyx_vtabstruct__memoryviewslice {
  struct __pyx_vtabstruct_memoryview __pyx_base;
};
static struct __pyx_vtabstruct__memoryviewslice *__pyx_vtabptr__memoryviewslice;

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* Profile.proto */
#ifndef CYTHON_PROFILE
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
  #define CYTHON_PROFILE 0
#else
  #define CYTHON_PROFILE 1
#endif
#endif
#ifndef CYTHON_TRACE_NOGIL
  #define CYTHON_TRACE_NOGIL 0
#else
  #if CYTHON_TRACE_NOGIL && !defined(CYTHON_TRACE)
    #define CYTHON_TRACE 1
  #endif
#endif
#ifndef CYTHON_TRACE
  #define CYTHON_TRACE 0
#endif
#if CYTHON_TRACE
  #undef CYTHON_PROFILE_REUSE_FRAME
#endif
#ifndef CYTHON_PROFILE_REUSE_FRAME
  #define CYTHON_PROFILE_REUSE_FRAME 0
#endif
#if CYTHON_PROFILE || CYTHON_TRACE
  #include "compile.h"
  #include "frameobject.h"
  #include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #if CYTHON_PROFILE_REUSE_FRAME
    #define CYTHON_FRAME_MODIFIER static
    #define CYTHON_FRAME_DEL(frame)
  #else
    #define CYTHON_FRAME_MODIFIER
    #define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame)
  #endif
  #define __Pyx_TraceDeclarations\
      static PyCodeObject *__pyx_frame_code = NULL;\
      CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;\
      int __Pyx_use_tracing = 0;
  #define __Pyx_TraceFrameInit(codeobj)\
      if (codeobj) __pyx_frame_code = (PyCodeObject*) codeobj;
#if PY_VERSION_HEX >= 0x030b00a2
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate) PyThreadState_EnterTracing(tstate)
  #define __Pyx_LeaveTracing(tstate) PyThreadState_LeaveTracing(tstate)
#elif PY_VERSION_HEX >= 0x030a00b1
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->cframe->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->cframe->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                 || tstate->c_profilefunc != NULL);\
      } while (0)
#else
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                         || tstate->c_profilefunc != NULL);\
      } while (0)
#endif
  #ifdef WITH_THREAD
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  if (nogil) {\
      if (CYTHON_TRACE_NOGIL) {\
          PyThreadState *tstate;\
          PyGILState_STATE state = PyGILState_Ensure();\
          tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 1, 1)) {\
              __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          }\
          PyGILState_Release(state);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  } else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #else
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  {   PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #endif
  #define __Pyx_TraceException()\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 1)) {\
          __Pyx_EnterTracing(tstate);\
          PyObject *exc_info = __Pyx_GetExceptionTuple(tstate);\
          if (exc_info) {\
              if (CYTHON_TRACE && tstate->c_tracefunc)\
                  tstate->c_tracefunc(\
                      tstate->c_traceobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
              tstate->c_profilefunc(\
                  tstate->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
              Py_DECREF(exc_info);\
          }\
          __Pyx_LeaveTracing(tstate);\
      }\
  }
  static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_EnterTracing(tstate);
      if (CYTHON_TRACE && tstate->c_tracefunc)
          tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
      if (tstate->c_profilefunc)
          tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
      CYTHON_FRAME_DEL(frame);
      __Pyx_LeaveTracing(tstate);
      __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              PyThreadState *tstate;\
              PyGILState_STATE state = PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0)) {\
                  __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
              }\
              PyGILState_Release(state);\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0)) {\
              __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
          }\
      }\
  }
  #else
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0)) {\
          __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
      }\
  }
  #endif
  static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno);
  static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno);
#else
  #define __Pyx_TraceDeclarations
  #define __Pyx_TraceFrameInit(codeobj)
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)   if ((1)); else goto_error;
  #define __Pyx_TraceException()
  #define __Pyx_TraceReturn(result, nogil)
#endif
#if CYTHON_TRACE
  static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
      int ret;
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_PyFrame_SetLineNumber(frame, lineno);
      __Pyx_EnterTracing(tstate);
      ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
      __Pyx_LeaveTracing(tstate);
      if (likely(!ret)) {
          __Pyx_ErrRestoreInState(tstate, type, value, traceback);
      } else {
          Py_XDECREF(type);
          Py_XDECREF(value);
          Py_XDECREF(traceback);
      }
      return ret;
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              int ret = 0;\
              PyThreadState *tstate;\
              PyGILState_STATE state = PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
                  ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              }\
              PyGILState_Release(state);\
              if (unlikely(ret)) goto_error;\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
              int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              if (unlikely(ret)) goto_error;\
          }\
      }\
  }
  #else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
          int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
          if (unlikely(ret)) goto_error;\
      }\
  }
  #endif
#else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)   if ((1)); else goto_error;
#endif

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* IncludeStringH.proto */
#include <string.h>

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  do {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  do {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if CYTHON_FAST_PYCALL
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif // CYTHON_FAST_PYCALL
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCall2Args.proto */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* SetItemInt.proto */
#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
               __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck);

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* KeywordStringCheck.proto */
static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

/* CythonFunctionShared.proto */
#define __Pyx_CyFunction_USED 1
#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
#define __Pyx_CYFUNCTION_CCLASS        0x04
#define __Pyx_CyFunction_GetClosure(f)\
    (((__pyx_CyFunctionObject *) (f))->func_closure)
#define __Pyx_CyFunction_GetClassObj(f)\
    (((__pyx_CyFunctionObject *) (f))->func_classobj)
#define __Pyx_CyFunction_Defaults(type, f)\
    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
    PyCFunctionObject func;
#if PY_VERSION_HEX < 0x030500A0
    PyObject *func_weakreflist;
#endif
    PyObject *func_dict;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
    PyObject *func_classobj;
    void *defaults;
    int defaults_pyobjects;
    size_t defaults_size;  // used by FusedFunction for copying defaults
    int flags;
    PyObject *defaults_tuple;
    PyObject *defaults_kwdict;
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations;
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_Check(obj)  (__Pyx_TypeCheck(obj, __pyx_CyFunctionType))
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *self,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
                                                         size_t size,
                                                         int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
                                                            PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __pyx_CyFunction_init(void);

/* CythonFunction.proto */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *closure,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* MemviewSliceInit.proto */
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
#define __Pyx_MEMVIEW_DIRECT   1
#define __Pyx_MEMVIEW_PTR      2
#define __Pyx_MEMVIEW_FULL     4
#define __Pyx_MEMVIEW_CONTIG   8
#define __Pyx_MEMVIEW_STRIDED  16
#define __Pyx_MEMVIEW_FOLLOW   32
#define __Pyx_IS_C_CONTIG 1
#define __Pyx_IS_F_CONTIG 2
static int __Pyx_init_memviewslice(
                struct __pyx_memoryview_obj *memview,
                int ndim,
                __Pyx_memviewslice *memviewslice,
                int memview_is_new_reference);
static CYTHON_INLINE int __pyx_add_acquisition_count_locked(
    __pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
    __pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p)
#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview))
#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__)
static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int);
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_TrueDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_TrueDivideObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceTrueDivide(op1, op2) : PyNumber_TrueDivide(op1, op2))
#endif

/* BufferIndexError.proto */
static void __Pyx_RaiseBufferIndexError(int axis);

/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);

/* PyObjectFormatSimple.proto */
#if CYTHON_COMPILING_IN_PYPY
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#elif PY_MAJOR_VERSION < 3
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\
        PyObject_Format(s, f))
#elif CYTHON_USE_TYPE_SLOTS
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\
        likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\
        PyObject_Format(s, f))
#else
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#endif

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

/* GCCDiagnostics.proto */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* BuildPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char);

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char);

/* DivInt[Py_ssize_t].proto */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t);

/* pyobject_as_double.proto */
static double __Pyx__PyObject_AsDouble(PyObject* obj);
#if CYTHON_COMPILING_IN_PYPY
#define __Pyx_PyObject_AsDouble(obj)\
(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) :\
 likely(PyInt_CheckExact(obj)) ?\
 PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
#else
#define __Pyx_PyObject_AsDouble(obj)\
((likely(PyFloat_CheckExact(obj))) ?\
 PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
#endif

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RshiftObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_RshiftObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceRshift(op1, op2) : PyNumber_Rshift(op1, op2))
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_RemainderObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceRemainder(op1, op2) : PyNumber_Remainder(op1, op2))
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);

/* MatrixMultiply.proto */
#if PY_VERSION_HEX >= 0x03050000
  #define __Pyx_PyNumber_MatrixMultiply(x,y)         PyNumber_MatrixMultiply(x,y)
  #define __Pyx_PyNumber_InPlaceMatrixMultiply(x,y)  PyNumber_InPlaceMatrixMultiply(x,y)
#else
#define __Pyx_PyNumber_MatrixMultiply(x,y)         __Pyx__PyNumber_MatrixMultiply(x, y, "@")
static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name);
static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y);
#endif

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* SliceObject.proto */
#define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)\
    __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
        PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_SubtractCObj(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_FloorDivideObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceFloorDivide(op1, op2) : PyNumber_FloorDivide(op1, op2))
#endif

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* UnaryNegOverflows.proto */
#define UNARY_NEG_WOULD_OVERFLOW(x)\
        (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))

static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *); /*proto*/
/* decode_c_string_utf16.proto */
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 0;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = -1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}

/* decode_c_string.proto */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* SwapException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
/* ListExtend.proto */
static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

/* DivInt[long].proto */
static CYTHON_INLINE long __Pyx_div_long(long, long);

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* SetVTable.proto */
static int __Pyx_SetVtable(PyObject *dict, void *vtable);

/* PyObjectGetAttrStrNoError.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);

/* SetupReduce.proto */
static int __Pyx_setup_reduce(PyObject* type_obj);

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto_0_29_35
#define __PYX_HAVE_RT_ImportType_proto_0_29_35
#if __STDC_VERSION__ >= 201112L
#include <stdalign.h>
#endif
#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
#define __PYX_GET_STRUCT_ALIGNMENT_0_29_35(s) alignof(s)
#else
#define __PYX_GET_STRUCT_ALIGNMENT_0_29_35(s) sizeof(void*)
#endif
enum __Pyx_ImportType_CheckSize_0_29_35 {
   __Pyx_ImportType_CheckSize_Error_0_29_35 = 0,
   __Pyx_ImportType_CheckSize_Warn_0_29_35 = 1,
   __Pyx_ImportType_CheckSize_Ignore_0_29_35 = 2
};
static PyTypeObject *__Pyx_ImportType_0_29_35(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_0_29_35 check_size);
#endif

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

#if PY_MAJOR_VERSION < 3
    static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
    static void __Pyx_ReleaseBuffer(Py_buffer *view);
#else
    #define __Pyx_GetBuffer PyObject_GetBuffer
    #define __Pyx_ReleaseBuffer PyBuffer_Release
#endif


/* BufferStructDeclare.proto */
typedef struct {
  Py_ssize_t shape, strides, suboffsets;
} __Pyx_Buf_DimInfo;
typedef struct {
  size_t refcount;
  Py_buffer pybuffer;
} __Pyx_Buffer;
typedef struct {
  __Pyx_Buffer *rcbuffer;
  char *data;
  __Pyx_Buf_DimInfo diminfo[8];
} __Pyx_LocalBuf_ND;

/* MemviewSliceIsContig.proto */
static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim);

/* OverlappingSlices.proto */
static int __pyx_slices_overlap(__Pyx_memviewslice *slice1,
                                __Pyx_memviewslice *slice2,
                                int ndim, size_t itemsize);

/* Capsule.proto */
static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig);

/* IsLittleEndian.proto */
static CYTHON_INLINE int __Pyx_Is_Little_Endian(void);

/* BufferFormatCheck.proto */
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type);

/* TypeInfoCompare.proto */
static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b);

/* MemviewSliceValidateAndInit.proto */
static int __Pyx_ValidateAndInit_memviewslice(
                int *axes_specs,
                int c_or_f_flag,
                int buf_flags,
                int ndim,
                __Pyx_TypeInfo *dtype,
                __Pyx_BufFmt_StackElem stack[],
                __Pyx_memviewslice *memviewslice,
                PyObject *original_obj);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_double(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_int(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(PyObject *, int writable_flag);

/* MemviewDtypeToObject.proto */
static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_int64_t(const char *itemp);
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_int64_t(const char *itemp, PyObject *obj);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int8_t(PyObject *, int writable_flag);

/* MemviewDtypeToObject.proto */
static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_int8_t(const char *itemp);
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_int8_t(const char *itemp, PyObject *obj);

/* CppExceptionConversion.proto */
#ifndef __Pyx_CppExn2PyErr
#include <new>
#include <typeinfo>
#include <stdexcept>
#include <ios>
static void __Pyx_CppExn2PyErr() {
  try {
    if (PyErr_Occurred())
      ; // let the latest Python exn pass through and ignore the current one
    else
      throw;
  } catch (const std::bad_alloc& exn) {
    PyErr_SetString(PyExc_MemoryError, exn.what());
  } catch (const std::bad_cast& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::bad_typeid& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::domain_error& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::invalid_argument& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::ios_base::failure& exn) {
    PyErr_SetString(PyExc_IOError, exn.what());
  } catch (const std::out_of_range& exn) {
    PyErr_SetString(PyExc_IndexError, exn.what());
  } catch (const std::overflow_error& exn) {
    PyErr_SetString(PyExc_OverflowError, exn.what());
  } catch (const std::range_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::underflow_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::exception& exn) {
    PyErr_SetString(PyExc_RuntimeError, exn.what());
  }
  catch (...)
  {
    PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
  }
}
#endif

/* MemviewDtypeToObject.proto */
static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_float64_t(const char *itemp);
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_float64_t(const char *itemp, PyObject *obj);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(PyObject *, int writable_flag);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int32_t(PyObject *, int writable_flag);

/* MemviewDtypeToObject.proto */
static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp);
static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj);

/* ObjectToMemviewSlice.proto */
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(PyObject *, int writable_flag);

/* RealImag.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(__cplusplus) && CYTHON_CCOMPLEX\
        && (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_float(a, b)   ((a)==(b))
    #define __Pyx_c_sum_float(a, b)  ((a)+(b))
    #define __Pyx_c_diff_float(a, b) ((a)-(b))
    #define __Pyx_c_prod_float(a, b) ((a)*(b))
    #define __Pyx_c_quot_float(a, b) ((a)/(b))
    #define __Pyx_c_neg_float(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_float(z) ((z)==(float)0)
    #define __Pyx_c_conj_float(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (::std::abs(z))
        #define __Pyx_c_pow_float(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_float(z) ((z)==0)
    #define __Pyx_c_conj_float(z)    (conjf(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (cabsf(z))
        #define __Pyx_c_pow_float(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_double(a, b)   ((a)==(b))
    #define __Pyx_c_sum_double(a, b)  ((a)+(b))
    #define __Pyx_c_diff_double(a, b) ((a)-(b))
    #define __Pyx_c_prod_double(a, b) ((a)*(b))
    #define __Pyx_c_quot_double(a, b) ((a)/(b))
    #define __Pyx_c_neg_double(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_double(z) ((z)==(double)0)
    #define __Pyx_c_conj_double(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (::std::abs(z))
        #define __Pyx_c_pow_double(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_double(z) ((z)==0)
    #define __Pyx_c_conj_double(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (cabs(z))
        #define __Pyx_c_pow_double(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

/* MemviewSliceCopyTemplate.proto */
static __Pyx_memviewslice
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
                                 const char *mode, int ndim,
                                 size_t sizeof_dtype, int contig_flag,
                                 int dtype_is_object);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int_t(int_t value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int_t __Pyx_PyInt_As_int_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int64(npy_int64 value);

/* CIntFromPy.proto */
static CYTHON_INLINE npy_int64 __Pyx_PyInt_As_npy_int64(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE npy_int8 __Pyx_PyInt_As_npy_int8(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int8(npy_int8 value);

/* CIntFromPy.proto */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* FunctionImport.proto */
static int __Pyx_ImportFunction_0_29_35(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static void __pyx_f_10discretize_11_extensions_8tree_ext_8TreeCell__set(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self, Cell *__pyx_v_cell); /* proto*/
static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self); /* proto*/
static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto*/
static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj); /* proto*/
static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src); /* proto*/
static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/
static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/
static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp); /* proto*/
static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value); /* proto*/

/* Module declarations from 'cython.view' */

/* Module declarations from 'cython' */

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'cpython' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_generic = 0;
static PyTypeObject *__pyx_ptype_5numpy_number = 0;
static PyTypeObject *__pyx_ptype_5numpy_integer = 0;
static PyTypeObject *__pyx_ptype_5numpy_signedinteger = 0;
static PyTypeObject *__pyx_ptype_5numpy_unsignedinteger = 0;
static PyTypeObject *__pyx_ptype_5numpy_inexact = 0;
static PyTypeObject *__pyx_ptype_5numpy_floating = 0;
static PyTypeObject *__pyx_ptype_5numpy_complexfloating = 0;
static PyTypeObject *__pyx_ptype_5numpy_flexible = 0;
static PyTypeObject *__pyx_ptype_5numpy_character = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'libcpp.vector' */

/* Module declarations from 'libcpp' */

/* Module declarations from 'numpy.math' */

/* Module declarations from 'libcpp.utility' */

/* Module declarations from 'libcpp.map' */

/* Module declarations from 'discretize._extensions.tree' */

/* Module declarations from 'discretize._extensions.interputils_cython' */
static __pyx_t_5numpy_int64_t (*__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_left)(__Pyx_memviewslice, __pyx_t_5numpy_float64_t); /*proto*/
static __pyx_t_5numpy_int64_t (*__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_right)(__Pyx_memviewslice, __pyx_t_5numpy_float64_t); /*proto*/

/* Module declarations from 'discretize._extensions.tree_ext' */
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext_TreeCell = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx = 0;
static PyTypeObject *__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx = 0;
static PyTypeObject *__pyx_array_type = 0;
static PyTypeObject *__pyx_MemviewEnum_type = 0;
static PyTypeObject *__pyx_memoryview_type = 0;
static PyTypeObject *__pyx_memoryviewslice_type = 0;
static PyObject *generic = 0;
static PyObject *strided = 0;
static PyObject *indirect = 0;
static PyObject *contiguous = 0;
static PyObject *indirect_contiguous = 0;
static int __pyx_memoryview_thread_locks_used;
static PyThread_type_lock __pyx_memoryview_thread_locks[8];
static int __pyx_f_10discretize_11_extensions_8tree_ext__evaluate_func(void *, Cell *); /*proto*/
static CYTHON_INLINE double __pyx_f_10discretize_11_extensions_8tree_ext__clip01(double); /*proto*/
static PyObject *__pyx_convert_vector_to_py_PY_LONG_LONG(const std::vector<PY_LONG_LONG>  &); /*proto*/
static PyObject *__pyx_convert_vector_to_py_int_t(const std::vector<int_t>  &); /*proto*/
static PyObject *__pyx_convert_vector_to_py_double(const std::vector<double>  &); /*proto*/
static struct __pyx_array_obj *__pyx_array_new(PyObject *, Py_ssize_t, char *, char *, char *); /*proto*/
static void *__pyx_align_pointer(void *, size_t); /*proto*/
static PyObject *__pyx_memoryview_new(PyObject *, int, int, __Pyx_TypeInfo *); /*proto*/
static CYTHON_INLINE int __pyx_memoryview_check(PyObject *); /*proto*/
static PyObject *_unellipsify(PyObject *, int); /*proto*/
static PyObject *assert_direct_dimensions(Py_ssize_t *, int); /*proto*/
static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *, PyObject *); /*proto*/
static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int *, Py_ssize_t, Py_ssize_t, Py_ssize_t, int, int, int, int); /*proto*/
static char *__pyx_pybuffer_index(Py_buffer *, char *, Py_ssize_t, Py_ssize_t); /*proto*/
static int __pyx_memslice_transpose(__Pyx_memviewslice *); /*proto*/
static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice, int, PyObject *(*)(char *), int (*)(char *, PyObject *), int); /*proto*/
static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *); /*proto*/
static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *, __Pyx_memviewslice *); /*proto*/
static Py_ssize_t abs_py_ssize_t(Py_ssize_t); /*proto*/
static char __pyx_get_best_slice_order(__Pyx_memviewslice *, int); /*proto*/
static void _copy_strided_to_strided(char *, Py_ssize_t *, char *, Py_ssize_t *, Py_ssize_t *, Py_ssize_t *, int, size_t); /*proto*/
static void copy_strided_to_strided(__Pyx_memviewslice *, __Pyx_memviewslice *, int, size_t); /*proto*/
static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *, int); /*proto*/
static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *, Py_ssize_t *, Py_ssize_t, int, char); /*proto*/
static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *, __Pyx_memviewslice *, char, int); /*proto*/
static int __pyx_memoryview_err_extents(int, Py_ssize_t, Py_ssize_t); /*proto*/
static int __pyx_memoryview_err_dim(PyObject *, char *, int); /*proto*/
static int __pyx_memoryview_err(PyObject *, char *); /*proto*/
static int __pyx_memoryview_copy_contents(__Pyx_memviewslice, __Pyx_memviewslice, int, int, int); /*proto*/
static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *, int, int); /*proto*/
static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *, int, int, int); /*proto*/
static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/
static void __pyx_memoryview_refcount_objects_in_slice(char *, Py_ssize_t *, Py_ssize_t *, int, int); /*proto*/
static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size_t, void *, int); /*proto*/
static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/
static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_int = { "int", NULL, sizeof(int), { 0 }, 0, IS_UNSIGNED(int) ? 'U' : 'I', IS_UNSIGNED(int), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t = { "float64_t", NULL, sizeof(__pyx_t_5numpy_float64_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t = { "int64_t", NULL, sizeof(__pyx_t_5numpy_int64_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int64_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int64_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t = { "int8_t", NULL, sizeof(__pyx_t_5numpy_int8_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int8_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int8_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int32_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int32_t), 0 };
#define __Pyx_MODULE_NAME "discretize._extensions.tree_ext"
extern int __pyx_module_is_main_discretize___extensions__tree_ext;
int __pyx_module_is_main_discretize___extensions__tree_ext = 0;

/* Implementation of 'discretize._extensions.tree_ext' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_super;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_Ellipsis;
static PyObject *__pyx_builtin_id;
static const char __pyx_k_C[] = "C";
static const char __pyx_k_F[] = "F";
static const char __pyx_k_O[] = "O";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_h[] = "h";
static const char __pyx_k_r[] = "r_";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_y[] = "y";
static const char __pyx_k_z[] = "z";
static const char __pyx_k_id[] = "id";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_sp[] = "sp";
static const char __pyx_k_x0[] = "x0";
static const char __pyx_k_x1[] = "x1";
static const char __pyx_k_xd[] = "xd";
static const char __pyx_k_xu[] = "xu";
static const char __pyx_k_yd[] = "yd";
static const char __pyx_k_yu[] = "yu";
static const char __pyx_k_zd[] = "zd";
static const char __pyx_k_zu[] = "zu";
static const char __pyx_k_Pxx[] = "Pxx";
static const char __pyx_k__11[] = ")";
static const char __pyx_k__18[] = ", ";
static const char __pyx_k__67[] = "*";
static const char __pyx_k_any[] = "any";
static const char __pyx_k_csr[] = "csr";
static const char __pyx_k_dim[] = "dim";
static const char __pyx_k_eps[] = "eps";
static const char __pyx_k_eye[] = "eye";
static const char __pyx_k_fXp[] = "fXp";
static const char __pyx_k_fYp[] = "fYp";
static const char __pyx_k_fZp[] = "fZp";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_num[] = "num";
static const char __pyx_k_obj[] = "obj";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_x0s[] = "x0s";
static const char __pyx_k_x1s[] = "x1s";
static const char __pyx_k_Pxxx[] = "Pxxx";
static const char __pyx_k_base[] = "base";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_full[] = "full";
static const char __pyx_k_init[] = "__init__";
static const char __pyx_k_int8[] = "int8";
static const char __pyx_k_locs[] = "locs";
static const char __pyx_k_log2[] = "log2";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_ndim[] = "ndim";
static const char __pyx_k_ones[] = "ones";
static const char __pyx_k_pack[] = "pack";
static const char __pyx_k_path[] = "path";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_step[] = "step";
static const char __pyx_k_stop[] = "stop";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_ASCII[] = "ASCII";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_class[] = "__class__";
static const char __pyx_k_diags[] = "diags";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_finfo[] = "finfo";
static const char __pyx_k_flags[] = "flags";
static const char __pyx_k_int32[] = "int32";
static const char __pyx_k_int64[] = "int64";
static const char __pyx_k_lower[] = "lower";
static const char __pyx_k_nodes[] = "nodes";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_order[] = "order";
static const char __pyx_k_radii[] = "radii";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_super[] = "super";
static const char __pyx_k_tetra[] = "tetra";
static const char __pyx_k_tocsr[] = "tocsr";
static const char __pyx_k_where[] = "where";
static const char __pyx_k_xEdge[] = "xEdge";
static const char __pyx_k_xFace[] = "xFace";
static const char __pyx_k_yEdge[] = "yEdge";
static const char __pyx_k_yFace[] = "yFace";
static const char __pyx_k_zEdge[] = "zEdge";
static const char __pyx_k_zFace[] = "zFace";
static const char __pyx_k_zeros[] = "zeros";
static const char __pyx_k_arange[] = "arange";
static const char __pyx_k_cumsum[] = "cumsum";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_getnnz[] = "getnnz";
static const char __pyx_k_hstack[] = "hstack";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_levels[] = "levels";
static const char __pyx_k_matmul[] = "__matmul__";
static const char __pyx_k_meshin[] = "meshin";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_origin[] = "origin";
static const char __pyx_k_output[] = "output";
static const char __pyx_k_pickle[] = "pickle";
static const char __pyx_k_points[] = "points";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_struct[] = "struct";
static const char __pyx_k_unpack[] = "unpack";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_vstack[] = "vstack";
static const char __pyx_k_asarray[] = "asarray";
static const char __pyx_k_edges_x[] = "edges_x";
static const char __pyx_k_edges_y[] = "edges_y";
static const char __pyx_k_edges_z[] = "edges_z";
static const char __pyx_k_faces_x[] = "faces_x";
static const char __pyx_k_faces_y[] = "faces_y";
static const char __pyx_k_faces_z[] = "faces_z";
static const char __pyx_k_float64[] = "float64";
static const char __pyx_k_fortran[] = "fortran";
static const char __pyx_k_imatmul[] = "__imatmul__";
static const char __pyx_k_indices[] = "indices";
static const char __pyx_k_is_pow2[] = "is_pow2";
static const char __pyx_k_lexsort[] = "lexsort";
static const char __pyx_k_memview[] = "memview";
static const char __pyx_k_n_cells[] = "n_cells";
static const char __pyx_k_n_edges[] = "n_edges";
static const char __pyx_k_n_faces[] = "n_faces";
static const char __pyx_k_n_nodes[] = "n_nodes";
static const char __pyx_k_nodes_x[] = "nodes_x";
static const char __pyx_k_nodes_y[] = "nodes_y";
static const char __pyx_k_nodes_z[] = "nodes_z";
static const char __pyx_k_nonzero[] = "nonzero";
static const char __pyx_k_require[] = "require";
static const char __pyx_k_reshape[] = "reshape";
static const char __pyx_k_rmatmul[] = "__rmatmul__";
static const char __pyx_k_Ellipsis[] = "Ellipsis";
static const char __pyx_k_TreeCell[] = "TreeCell";
static const char __pyx_k_TreeMesh[] = "_TreeMesh";
static const char __pyx_k_allclose[] = "allclose";
static const char __pyx_k_aveFy2CC[] = "aveFy2CC";
static const char __pyx_k_bincount[] = "bincount";
static const char __pyx_k_finalize[] = "finalize";
static const char __pyx_k_function[] = "function";
static const char __pyx_k_getEdgeP[] = "_getEdgeP";
static const char __pyx_k_getFaceP[] = "_getFaceP";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_itemsize[] = "itemsize";
static const char __pyx_k_pyx_type[] = "__pyx_type";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_triangle[] = "triangle";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_direction[] = "direction";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_max_level[] = "max_level";
static const char __pyx_k_n_edges_x[] = "n_edges_x";
static const char __pyx_k_n_edges_y[] = "n_edges_y";
static const char __pyx_k_n_edges_z[] = "n_edges_z";
static const char __pyx_k_n_faces_x[] = "n_faces_x";
static const char __pyx_k_n_faces_y[] = "n_faces_y";
static const char __pyx_k_n_faces_z[] = "n_faces_z";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_active_ind[] = "active_ind";
static const char __pyx_k_and_levels[] = " and levels ";
static const char __pyx_k_atleast_1d[] = "atleast_1d";
static const char __pyx_k_atleast_2d[] = "atleast_2d";
static const char __pyx_k_block_diag[] = "block_diag";
static const char __pyx_k_csr_matrix[] = "csr_matrix";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_ubc_indArr[] = "_ubc_indArr";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_and_heights[] = " and heights ";
static const char __pyx_k_clear_cache[] = "_clear_cache";
static const char __pyx_k_shape_cells[] = "shape_cells";
static const char __pyx_k_cell_centers[] = "cell_centers";
static const char __pyx_k_cell_volumes[] = "cell_volumes";
static const char __pyx_k_column_stack[] = "column_stack";
static const char __pyx_k_edge_lengths[] = "edge_lengths";
static const char __pyx_k_face_normals[] = "face_normals";
static const char __pyx_k_in_tens_mesh[] = "in_tens_mesh";
static const char __pyx_k_insert_cells[] = "insert_cells";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_requirements[] = "requirements";
static const char __pyx_k_scipy_sparse[] = "scipy.sparse";
static const char __pyx_k_stringsource[] = "stringsource";
static const char __pyx_k_deflate_edges[] = "_deflate_edges";
static const char __pyx_k_deflate_faces[] = "_deflate_faces";
static const char __pyx_k_deflate_nodes[] = "_deflate_nodes";
static const char __pyx_k_n_total_edges[] = "n_total_edges";
static const char __pyx_k_n_total_faces[] = "n_total_faces";
static const char __pyx_k_n_total_nodes[] = "n_total_nodes";
static const char __pyx_k_out_tens_mesh[] = "out_tens_mesh";
static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_zeros_outside[] = "zeros_outside";
static const char __pyx_k_Path_not_found[] = "Path not found";
static const char __pyx_k_View_MemoryView[] = "View.MemoryView";
static const char __pyx_k_allocate_buffer[] = "allocate_buffer";
static const char __pyx_k_deflate_edges_x[] = "_deflate_edges_x";
static const char __pyx_k_deflate_edges_y[] = "_deflate_edges_y";
static const char __pyx_k_deflate_edges_z[] = "_deflate_edges_z";
static const char __pyx_k_deflate_faces_x[] = "_deflate_faces_x";
static const char __pyx_k_deflate_faces_y[] = "_deflate_faces_y";
static const char __pyx_k_deflate_faces_z[] = "_deflate_faces_z";
static const char __pyx_k_dtype_is_object[] = "dtype_is_object";
static const char __pyx_k_hanging_edges_x[] = "hanging_edges_x";
static const char __pyx_k_hanging_edges_y[] = "hanging_edges_y";
static const char __pyx_k_n_hanging_edges[] = "n_hanging_edges";
static const char __pyx_k_n_hanging_faces[] = "n_hanging_faces";
static const char __pyx_k_n_hanging_nodes[] = "n_hanging_nodes";
static const char __pyx_k_n_total_edges_x[] = "n_total_edges_x";
static const char __pyx_k_n_total_edges_y[] = "n_total_edges_y";
static const char __pyx_k_n_total_edges_z[] = "n_total_edges_z";
static const char __pyx_k_n_total_faces_x[] = "n_total_faces_x";
static const char __pyx_k_n_total_faces_y[] = "n_total_faces_y";
static const char __pyx_k_n_total_faces_z[] = "n_total_faces_z";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_refine_triangle[] = "refine_triangle";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_diagonal_balance[] = "diagonal_balance";
static const char __pyx_k_n_hanging_edges_x[] = "n_hanging_edges_x";
static const char __pyx_k_n_hanging_edges_y[] = "n_hanging_edges_y";
static const char __pyx_k_n_hanging_edges_z[] = "n_hanging_edges_z";
static const char __pyx_k_n_hanging_faces_x[] = "n_hanging_faces_x";
static const char __pyx_k_n_hanging_faces_y[] = "n_hanging_faces_y";
static const char __pyx_k_n_hanging_faces_z[] = "n_hanging_faces_z";
static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_face_divergence_2D[] = "_face_divergence_2D";
static const char __pyx_k_face_divergence_3D[] = "_face_divergence_3D";
static const char __pyx_k_strided_and_direct[] = "<strided and direct>";
static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
static const char __pyx_k_x0s_array_must_be_N[] = "x0s array must be (N, ";
static const char __pyx_k_x1s_array_must_be_N[] = "x1s array must be (N, ";
static const char __pyx_k_average_edge_to_face[] = "_average_edge_to_face";
static const char __pyx_k_refine_locals_lambda[] = "refine.<locals>.<lambda>";
static const char __pyx_k_strided_and_indirect[] = "<strided and indirect>";
static const char __pyx_k_Invalid_argument_type[] = "Invalid argument type.";
static const char __pyx_k_cell_boundary_indices[] = "cell_boundary_indices";
static const char __pyx_k_contiguous_and_direct[] = "<contiguous and direct>";
static const char __pyx_k_getEdgePxx_locals_Pxx[] = "_getEdgePxx.<locals>.Pxx";
static const char __pyx_k_getFacePxx_locals_Pxx[] = "_getFacePxx.<locals>.Pxx";
static const char __pyx_k_init___locals_is_pow2[] = "__init__.<locals>.is_pow2";
static const char __pyx_k_tetra_array_must_be_N[] = "tetra array must be (N, ";
static const char __pyx_k_MemoryView_of_r_object[] = "<MemoryView of %r object>";
static const char __pyx_k_average_cell_to_face_x[] = "average_cell_to_face_x";
static const char __pyx_k_average_cell_to_face_y[] = "average_cell_to_face_y";
static const char __pyx_k_average_cell_to_face_z[] = "average_cell_to_face_z";
static const char __pyx_k_average_edge_x_to_cell[] = "average_edge_x_to_cell";
static const char __pyx_k_average_edge_y_to_cell[] = "average_edge_y_to_cell";
static const char __pyx_k_average_edge_z_to_cell[] = "average_edge_z_to_cell";
static const char __pyx_k_average_face_x_to_cell[] = "average_face_x_to_cell";
static const char __pyx_k_average_face_z_to_cell[] = "average_face_z_to_cell";
static const char __pyx_k_average_node_to_edge_x[] = "average_node_to_edge_x";
static const char __pyx_k_average_node_to_edge_y[] = "average_node_to_edge_y";
static const char __pyx_k_average_node_to_edge_z[] = "average_node_to_edge_z";
static const char __pyx_k_average_node_to_face_x[] = "average_node_to_face_x";
static const char __pyx_k_average_node_to_face_y[] = "average_node_to_face_y";
static const char __pyx_k_average_node_to_face_z[] = "average_node_to_face_z";
static const char __pyx_k_points_array_must_be_N[] = "points array must be (N, ";
static const char __pyx_k_MemoryView_of_r_at_0x_x[] = "<MemoryView of %r at 0x%x>";
static const char __pyx_k_contiguous_and_indirect[] = "<contiguous and indirect>";
static const char __pyx_k_getEdgePxxx_locals_Pxxx[] = "_getEdgePxxx.<locals>.Pxxx";
static const char __pyx_k_getFacePxxx_locals_Pxxx[] = "_getFacePxxx.<locals>.Pxxx";
static const char __pyx_k_stencil_cell_gradient_x[] = "_stencil_cell_gradient_x";
static const char __pyx_k_stencil_cell_gradient_y[] = "_stencil_cell_gradient_y";
static const char __pyx_k_stencil_cell_gradient_z[] = "_stencil_cell_gradient_z";
static const char __pyx_k_Cannot_index_with_type_s[] = "Cannot index with type '%s'";
static const char __pyx_k_TreeMesh_refine_line_448[] = "_TreeMesh.refine (line 448)";
static const char __pyx_k_Invalid_shape_in_axis_d_d[] = "Invalid shape in axis %d: %d.";
static const char __pyx_k_There_are_no_z_edges_in_2D[] = "There are no z-edges in 2D";
static const char __pyx_k_There_are_no_z_faces_in_2D[] = "There are no z-faces in 2D";
static const char __pyx_k_line_nodes_array_must_be_N[] = "line_nodes array must be (N, ";
static const char __pyx_k_triangle_array_must_be_N_3[] = "triangle array must be (N, 3, ";
static const char __pyx_k_get_containing_cell_indexes[] = "_get_containing_cell_indexes";
static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array";
static const char __pyx_k_All_heights_must_be_positive[] = "All heights must be positive.";
static const char __pyx_k_TreeMesh_refine_box_line_601[] = "_TreeMesh.refine_box (line 601)";
static const char __pyx_k_The_index_0_d_is_out_of_range[] = "The index ({0:d}) is out of range.";
static const char __pyx_k_TreeMesh_has_no_z_edges_in_2D[] = "TreeMesh has no z-edges in 2D";
static const char __pyx_k_TreeMesh_has_no_z_faces_in_2D[] = "TreeMesh has no z faces in 2D";
static const char __pyx_k_TreeMesh_refine_ball_line_512[] = "_TreeMesh.refine_ball (line 512)";
static const char __pyx_k_TreeMesh_refine_line_line_686[] = "_TreeMesh.refine_line (line 686)";
static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data.";
static const char __pyx_k_TreeMesh_cell_boundary_indices[] = "_TreeMesh.cell_boundary_indices.__get__ (line 2303)";
static const char __pyx_k_TreeMesh_face_boundary_indices[] = "_TreeMesh.face_boundary_indices.__get__ (line 2402)";
static const char __pyx_k_strided_and_direct_or_indirect[] = "<strided and direct or indirect>";
static const char __pyx_k_TreeMesh_has_no_z_faces_in_2D_2[] = "TreeMesh has no z-faces in 2D";
static const char __pyx_k_TreeMesh_insert_cells_line_1020[] = "_TreeMesh.insert_cells (line 1020)";
static const char __pyx_k_TreeMesh_refine_tetrahedron_lin[] = "_TreeMesh.refine_tetrahedron (line 936)";
static const char __pyx_k_TreeMesh_refine_triangle_line_7[] = "_TreeMesh.refine_triangle (line 762)";
static const char __pyx_k_TreeMesh_refine_vertical_triang[] = "_TreeMesh.refine_vertical_trianglular_prism (line 840)";
static const char __pyx_k_discretize__extensions_tree_ext[] = "discretize/_extensions/tree_ext.pyx";
static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import";
static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides";
static const char __pyx_k_Can_only_create_a_buffer_that_is[] = "Can only create a buffer that is contiguous in memory.";
static const char __pyx_k_Cannot_assign_to_read_only_memor[] = "Cannot assign to read-only memoryview";
static const char __pyx_k_Cannot_create_writable_memory_vi[] = "Cannot create writable memory view from read-only memoryview";
static const char __pyx_k_Empty_shape_tuple_for_cython_arr[] = "Empty shape tuple for cython.array";
static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))";
static const char __pyx_k_Indirect_dimensions_not_supporte[] = "Indirect dimensions not supported";
static const char __pyx_k_Insert_cells_into_the_class_disc[] = "Insert cells into the :class:`~discretize.TreeMesh` that contain given points.\n\n        Insert cell(s) into the :class:`~discretize.TreeMesh` that contain the given point(s) at the\n        assigned level(s).\n\n        Parameters\n        ----------\n        points : (N, dim) array_like\n        levels : (N) array_like of int\n        finalize : bool, optional\n            Whether to finalize after inserting point(s)\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        >>> from discretize import TreeMesh\n        >>> mesh = TreeMesh([32,32])\n        >>> mesh.insert_cells([0.5, 0.5], mesh.max_level)\n        >>> mesh\n        QuadTreeMesh: 3.91%% filled\n        Level : Number of cells               Mesh Extent               Cell Widths\n        -----------------------           min     ,     max            min   ,   max\n          2   :       12             ---------------------------   --------------------\n          3   :       13          x:      0.0     ,     1.0         0.03125  ,    0.25\n          4   :       11          y:      0.0     ,     1.0         0.03125  ,    0.25\n          5   :        4\n        -----------------------\n        Total :       40\n        ";
static const char __pyx_k_Invalid_direction_must_be_x_y_or[] = "Invalid direction, must be x, y, or z";
static const char __pyx_k_Invalid_mode_expected_c_or_fortr[] = "Invalid mode, expected 'c' or 'fortran', got %s";
static const char __pyx_k_Last_character_of_edge_string_mu[] = "Last character of edge string must be 0, 1, 2, or 3";
static const char __pyx_k_Nodal_Laplacian_has_not_been_imp[] = "Nodal Laplacian has not been implemented for TreeMesh";
static const char __pyx_k_Out_of_bounds_on_buffer_access_a[] = "Out of bounds on buffer access (axis %d)";
static const char __pyx_k_Refine_class_discretize_TreeMesh[] = "Refine :class:`~discretize.TreeMesh` with user-defined function.\n\n        Refines the :class:`~discretize.TreeMesh` according to a user-defined function.\n        The function is recursively called on each cell of the mesh. The user-defined\n        function **must** accept an object of type :class:`~discretize.tree_mesh.TreeCell`\n        and **must** return an integer-like object denoting the desired refinement\n        level. Instead of a function, the user may also supply an integer defining\n        the minimum refinement level for all cells.\n\n        Parameters\n        ----------\n        function : callable or int\n            a function defining the desired refinement level,\n            or an integer to refine all cells to at least that level.\n            The input argument of the function **must** be an instance of\n            :class:`~discretize.tree_mesh.TreeCell`.\n        finalize : bool, optional\n            whether to finalize the mesh\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        Here, we define a QuadTree mesh with a domain width of 1 along\n        the x and y axes. We then refine the mesh to its maximum level\n        at locations within a distance of 0.2 of point (0.5, 0.5). The\n        function accepts and instance of :class:`~discretize.tree_mesh.TreeCell`\n        and returns an integer value denoting its level of refinement.\n\n        >>> from discretize import TreeMesh\n        >>> from matplotlib import pyplot\n\n        Define a mesh and refine it radially outward using the custom defined function\n\n\n        >>> mesh = TreeMesh([32,32])\n        >>> def func(cell):\n        ...     r = np.linalg.norm(cell.center-0.5)\n        ...     return mesh.max_level if r<0.2 else mesh.max_level-2\n        >>> mesh.refine(func)\n\n     ""   >>> mesh.plot_grid()\n        >>> pyplot.show()\n\n        ";
static const char __pyx_k_Refine_the_class_discretize_Tree[] = "Refine the :class:`~discretize.TreeMesh` within the axis aligned boxes to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given axis aligned\n        box(es) to the prescribed level(s).\n\n        Parameters\n        ----------\n        x0s : (N, dim) array_like\n            The minimum location of the boxes\n        x1s : (N, dim) array_like\n            The maximum location of the boxes\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : None or bool, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the boxes are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the origins and furthest corners of the two rectangles, as\n        well as the level we want to refine them to, and refine the mesh.\n\n        >>> x0s = [[0.1, 0.1], [0.8, 0.8]]\n        >>> x1s = [[0.3, 0.2], [0.9, 1.0]]\n        >>> levels = [4, 5]\n        >>> tree_mesh.refine_box(x0s, x1s, levels)\n\n        Now lets look at the mesh, and overlay the boxes on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> rect = patches.Rectangle([0.1, 0.1], 0.2, 0.1, facecolor='none', edgecolor='r', linewidth=3)\n        >>> ax.add_patch(rect)\n        >>> rect = patches.Rectangle([0.8, 0.8], 0.1, 0.2, facecolor='none', edgecolor='k', linewidth=3)\n        >>> ax.add_patch(rect)\n     ""   >>> plt.show()\n        ";
static const char __pyx_k_Returns_the_indices_of_the_x_y_a[] = "Returns the indices of the x, y (and z) boundary cells.\n\n        This property returns the indices of the cells on the x, y (and z)\n        boundaries, respectively. Note that each axis direction will\n        have both a lower and upper boundary. The property will\n        return the indices corresponding to the lower and upper\n        boundaries separately.\n\n        E.g. for a 2D domain, there are 2 x-boundaries and 2 y-boundaries (4 in total).\n        In this case, the return is a list of length 4 organized\n        [ind_Bx1, ind_Bx2, ind_By1, ind_By2]::\n\n                       By2\n                + ------------- +\n                |               |\n                |               |\n            Bx1 |               | Bx2\n                |               |\n                |               |\n                + ------------- +\n                       By1\n\n\n        Returns\n        -------\n        ind_bx1 ind_bx2, ind_by1, ind_by2 : numpy.ndarray of int\n            The length of each array in the list is equal to the number of faces\n            on that particular boundary.\n        ind_bz1, ind_bz2 : numpy.ndarray of int, optional\n            Returned if `dim` is 3.\n\n        Examples\n        --------\n        Here, we construct a small 2D tree mesh and return the indices\n        of the x and y-boundary cells.\n\n        >>> from discretize import TreeMesh\n        >>> import numpy as np\n        >>> import matplotlib.pyplot as plt\n\n        >>> hx = np.ones(16)\n        >>> hy = np.ones(16)\n        >>> mesh = TreeMesh([hx, hy])\n        >>> mesh.refine_ball([4.0,4.0], [4.0], [4])\n        >>> ind_Bx1, ind_Bx2, ind_By1, ind_By2 = mesh.cell_boundary_indices\n\n        >>> ax = plt.subplot(111)\n        >>> mesh.plot_grid(ax=ax)\n        >>> ax.scatter(*mesh.cell_centers[ind_Bx1].T)\n        >>> plt.show()\n        ";
static const char __pyx_k_Unable_to_convert_item_to_object[] = "Unable to convert item to object";
static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing extents in dimension %d (got %d and %d)";
static const char __pyx_k_inconsistent_number_of_line_segm[] = "inconsistent number of line segments ";
static const char __pyx_k_inconsistent_number_of_triangles[] = "inconsistent number of triangles ";
static const char __pyx_k_length_of_cell_width_vectors_mus[] = "length of cell width vectors must be a power of 2";
static const char __pyx_k_level_length_must_match_the_poin[] = "level length must match the points array's first dimension";
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import";
static const char __pyx_k_origin_must_be_a_list_tuple_or_n[] = "origin must be a list, tuple or numpy array";
static const char __pyx_k_radii_length_must_match_the_poin[] = "radii length must match the points array's first dimension";
static const char __pyx_k_refine_vertical_trianglular_pris[] = "refine_vertical_trianglular_prism only implemented in 3D.";
static const char __pyx_k_self__cell_cannot_be_converted_t[] = "self._cell cannot be converted to a Python object for pickling";
static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides.";
static const char __pyx_k_x0s_and_x1s_must_have_the_same_l[] = "x0s and x1s must have the same length";
static const char __pyx_k_discretize__extensions_tree_ext_2[] = "discretize._extensions.tree_ext";
static const char __pyx_k_Refine_class_discretize_TreeMesh_2[] = "Refine :class:`~discretize.TreeMesh` using radial distance (ball) and refinement level for a cluster of points.\n\n        For each point in the array `points`, this method refines the tree mesh\n        based on the radial distance (ball) and refinement level supplied. The method\n        accomplishes this by determining which cells intersect ball(s) and refining them\n        to the prescribed level(s) of refinement.\n\n        Parameters\n        ----------\n        points : (N, dim) array_like\n            The centers of the refinement balls\n        radii : float or (N) array_like of float\n            A 1D array defining the radius for each ball\n        levels : int or (N) array_like of int\n            A 1D array defining the maximum refinement level for each ball\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the tree mesh such that all cells that\n        intersect the spherical balls are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the center and radius of the two spheres, as well as the level\n        we want to refine them to, and refine the mesh.\n\n        >>> centers = [[0.1, 0.3], [0.6, 0.8]]\n        >>> radii = [0.2, 0.3]\n        >>> levels = [4, 5]\n        >>> tree_mesh.refine_ball(centers, radii, levels)\n\n        Now lets look at the mesh, and overlay the balls on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> circ = patches.Circle(cente""rs[0], radii[0], facecolor='none', edgecolor='r', linewidth=3)\n        >>> ax.add_patch(circ)\n        >>> circ = patches.Circle(centers[1], radii[1], facecolor='none', edgecolor='k', linewidth=3)\n        >>> ax.add_patch(circ)\n        >>> plt.show()\n        ";
static const char __pyx_k_Refine_the_class_discretize_Tree_2[] = "Refine the :class:`~discretize.TreeMesh` along the line segment to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given line segment(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        path : (N+1, dim) array_like\n            The nodes of the line segment(s).\n            i.e. `[[x0, y0, z0], [x1, y1, z1], [x2, y2, z2]]` would be two segments.\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> segments = np.array([[0.1, 0.3], [0.3, 0.9], [0.8, 0.9]])\n        >>> levels = 5\n        >>> tree_mesh.refine_line(segments, levels)\n\n        Now lets look at the mesh, and overlay the line on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> ax.plot(*segments.T, color='C1')\n        >>> plt.show()\n\n        ";
static const char __pyx_k_Refine_the_class_discretize_Tree_3[] = "Refine the :class:`~discretize.TreeMesh` along the triangle to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given triangle(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        triangle : (N, 3, dim) array_like\n            The nodes of the triangle(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> triangle = [[0.14, 0.31], [0.32, 0.96], [0.23, 0.87]]\n        >>> levels = 5\n        >>> tree_mesh.refine_triangle(triangle, levels)\n\n        Now lets look at the mesh, and overlay the line on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> tri = patches.Polygon(triangle, fill=False)\n        >>> ax.add_patch(tri)\n        >>> plt.show()\n\n        ";
static const char __pyx_k_Refine_the_class_discretize_Tree_4[] = "Refine the :class:`~discretize.TreeMesh` along the trianglular prism to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given trianglular prism(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        triangle : (N, 3, dim) array_like\n            The nodes of the bottom triangle(s).\n        h : (N) array_like\n            The height of the prism(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        See Also\n        --------\n        refine_surface\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> mesh = discretize.TreeMesh([32, 32, 32])\n        >>> mesh.max_level\n        5\n\n        Next we define the bottom points of the prism, its heights, and the level we\n        want to refine to, then refine the mesh.\n\n        >>> triangle = [[0.14, 0.31, 0.21], [0.32, 0.96, 0.34], [0.87, 0.23, 0.12]]\n        >>> height = 0.35\n        >>> levels = 5\n        >>> tree_mesh.refine_vertical_trianglular_prism(triangle, height, levels)\n\n        Now lets look at the mesh.\n\n        >>> v = tree_mesh.cell_levels_by_index(np.arange(tree_mesh.n_cells))\n        >>> fig, axs = plt.subplots(1, 3, figsize=(12,4))\n        >>> tree_mesh.plot_slice(v, ax=axs[0], normal='x', grid=True, clim=[2, 5])\n        >>> tree_mesh.plot_slice(v, ax=axs[1], normal='y', grid=True, clim=[2, 5])\n    ""    >>> tree_mesh.plot_slice(v, ax=axs[2], normal='z', grid=True, clim=[2, 5])\n        >>> plt.show()\n\n        ";
static const char __pyx_k_Refine_the_class_discretize_Tree_5[] = "Refine the :class:`~discretize.TreeMesh` along the tetrahedron to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given triangle(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        tetra : (N, dim+1, dim) array_like\n            The nodes of the tetrahedron(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> tetra = [\n        ...     [0.32, 0.21, 0.15],\n        ...     [0.82, 0.19, 0.34],\n        ...     [0.14, 0.82, 0.29],\n        ...     [0.32, 0.27, 0.83],\n        ... ]\n        >>> levels = 5\n        >>> tree_mesh.refine_tetrahedron(tetra, levels)\n\n        Now lets look at the mesh, checking how the refine function proceeded.\n\n        >>> levels = tree_mesh.cell_levels_by_index(np.arange(tree_mesh.n_cells))\n        >>> ax = plt.gca()\n        >>> tree_mesh.plot_slice(levels, normal='z', slice_loc=0.2, grid=True, ax=ax)\n        >>> plt.show()\n\n        ";
static const char __pyx_k_Returns_the_indices_of_the_x_y_a_2[] = "Returns the indices of the x, y (and z) boundary faces.\n\n        This property returns the indices of the faces on the x, y (and z)\n        boundaries, respectively. Note that each axis direction will\n        have both a lower and upper boundary. The property will\n        return the indices corresponding to the lower and upper\n        boundaries separately.\n\n        E.g. for a 2D domain, there are 2 x-boundaries and 2 y-boundaries (4 in total).\n        In this case, the return is a list of length 4 organized\n        [ind_Bx1, ind_Bx2, ind_By1, ind_By2]::\n\n                       By2\n                + ------------- +\n                |               |\n                |               |\n            Bx1 |               | Bx2\n                |               |\n                |               |\n                + ------------- +\n                       By1\n\n\n        Returns\n        -------\n        ind_bx1 ind_bx2, ind_by1, ind_by2 : numpy.ndarray of int\n            The length of each array in the list is equal to the number of faces\n            on that particular boundary.\n        ind_bz1, ind_bz2 : numpy.ndarray of int, optional\n\n        Examples\n        --------\n        Here, we construct a small 2D tree mesh and return the indices\n        of the x and y-boundary faces.\n\n        >>> from discretize import TreeMesh\n        >>> import numpy as np\n        >>> import matplotlib.pyplot as plt\n\n        >>> hx = np.ones(16)\n        >>> hy = np.ones(16)\n        >>> mesh = TreeMesh([hx, hy])\n        >>> mesh.refine_ball([4.0,4.0], [4.0], [4])\n        >>> ind_Bx1, ind_Bx2, ind_By1, ind_By2 = mesh.face_boundary_indices\n\n        >>> ax = plt.subplot(111)\n        >>> mesh.plot_grid(ax=ax)\n        >>> ax.scatter(*mesh.faces_x[ind_Bx1].T)\n        >>> plt.show()\n        ";
static PyObject *__pyx_n_s_ASCII;
static PyObject *__pyx_kp_u_All_heights_must_be_positive;
static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri;
static PyObject *__pyx_n_u_C;
static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is;
static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor;
static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi;
static PyObject *__pyx_kp_s_Cannot_index_with_type_s;
static PyObject *__pyx_n_s_Ellipsis;
static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr;
static PyObject *__pyx_n_u_F;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte;
static PyObject *__pyx_kp_u_Insert_cells_into_the_class_disc;
static PyObject *__pyx_kp_u_Invalid_argument_type;
static PyObject *__pyx_kp_u_Invalid_direction_must_be_x_y_or;
static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr;
static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d;
static PyObject *__pyx_kp_u_Last_character_of_edge_string_mu;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_kp_s_MemoryView_of_r_at_0x_x;
static PyObject *__pyx_kp_s_MemoryView_of_r_object;
static PyObject *__pyx_kp_u_Nodal_Laplacian_has_not_been_imp;
static PyObject *__pyx_n_s_NotImplementedError;
static PyObject *__pyx_n_b_O;
static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a;
static PyObject *__pyx_kp_u_Path_not_found;
static PyObject *__pyx_n_s_PickleError;
static PyObject *__pyx_n_s_Pxx;
static PyObject *__pyx_n_s_Pxxx;
static PyObject *__pyx_kp_u_Refine_class_discretize_TreeMesh;
static PyObject *__pyx_kp_u_Refine_class_discretize_TreeMesh_2;
static PyObject *__pyx_kp_u_Refine_the_class_discretize_Tree;
static PyObject *__pyx_kp_u_Refine_the_class_discretize_Tree_2;
static PyObject *__pyx_kp_u_Refine_the_class_discretize_Tree_3;
static PyObject *__pyx_kp_u_Refine_the_class_discretize_Tree_4;
static PyObject *__pyx_kp_u_Refine_the_class_discretize_Tree_5;
static PyObject *__pyx_kp_u_Returns_the_indices_of_the_x_y_a;
static PyObject *__pyx_kp_u_Returns_the_indices_of_the_x_y_a_2;
static PyObject *__pyx_kp_u_The_index_0_d_is_out_of_range;
static PyObject *__pyx_kp_u_There_are_no_z_edges_in_2D;
static PyObject *__pyx_kp_u_There_are_no_z_faces_in_2D;
static PyObject *__pyx_n_s_TreeCell;
static PyObject *__pyx_n_s_TreeMesh;
static PyObject *__pyx_kp_u_TreeMesh_cell_boundary_indices;
static PyObject *__pyx_kp_u_TreeMesh_face_boundary_indices;
static PyObject *__pyx_kp_u_TreeMesh_has_no_z_edges_in_2D;
static PyObject *__pyx_kp_u_TreeMesh_has_no_z_faces_in_2D;
static PyObject *__pyx_kp_u_TreeMesh_has_no_z_faces_in_2D_2;
static PyObject *__pyx_kp_u_TreeMesh_insert_cells_line_1020;
static PyObject *__pyx_kp_u_TreeMesh_refine_ball_line_512;
static PyObject *__pyx_kp_u_TreeMesh_refine_box_line_601;
static PyObject *__pyx_kp_u_TreeMesh_refine_line_448;
static PyObject *__pyx_kp_u_TreeMesh_refine_line_line_686;
static PyObject *__pyx_kp_u_TreeMesh_refine_tetrahedron_lin;
static PyObject *__pyx_kp_u_TreeMesh_refine_triangle_line_7;
static PyObject *__pyx_kp_u_TreeMesh_refine_vertical_triang;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_View_MemoryView;
static PyObject *__pyx_kp_u__11;
static PyObject *__pyx_kp_u__18;
static PyObject *__pyx_n_s__67;
static PyObject *__pyx_n_s_active_ind;
static PyObject *__pyx_n_s_allclose;
static PyObject *__pyx_n_s_allocate_buffer;
static PyObject *__pyx_kp_u_and_heights;
static PyObject *__pyx_kp_u_and_levels;
static PyObject *__pyx_n_s_any;
static PyObject *__pyx_n_s_arange;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_asarray;
static PyObject *__pyx_n_s_atleast_1d;
static PyObject *__pyx_n_s_atleast_2d;
static PyObject *__pyx_n_s_aveFy2CC;
static PyObject *__pyx_n_s_average_cell_to_face_x;
static PyObject *__pyx_n_s_average_cell_to_face_y;
static PyObject *__pyx_n_s_average_cell_to_face_z;
static PyObject *__pyx_n_s_average_edge_to_face;
static PyObject *__pyx_n_s_average_edge_x_to_cell;
static PyObject *__pyx_n_s_average_edge_y_to_cell;
static PyObject *__pyx_n_s_average_edge_z_to_cell;
static PyObject *__pyx_n_s_average_face_x_to_cell;
static PyObject *__pyx_n_s_average_face_z_to_cell;
static PyObject *__pyx_n_s_average_node_to_edge_x;
static PyObject *__pyx_n_s_average_node_to_edge_y;
static PyObject *__pyx_n_s_average_node_to_edge_z;
static PyObject *__pyx_n_s_average_node_to_face_x;
static PyObject *__pyx_n_s_average_node_to_face_y;
static PyObject *__pyx_n_s_average_node_to_face_z;
static PyObject *__pyx_n_s_base;
static PyObject *__pyx_n_s_bincount;
static PyObject *__pyx_n_s_block_diag;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_n_u_c;
static PyObject *__pyx_n_s_cell_boundary_indices;
static PyObject *__pyx_n_s_cell_centers;
static PyObject *__pyx_n_s_cell_volumes;
static PyObject *__pyx_n_s_class;
static PyObject *__pyx_n_s_clear_cache;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_column_stack;
static PyObject *__pyx_kp_s_contiguous_and_direct;
static PyObject *__pyx_kp_s_contiguous_and_indirect;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_u_csr;
static PyObject *__pyx_n_s_csr_matrix;
static PyObject *__pyx_n_s_cumsum;
static PyObject *__pyx_n_s_deflate_edges;
static PyObject *__pyx_n_s_deflate_edges_x;
static PyObject *__pyx_n_s_deflate_edges_y;
static PyObject *__pyx_n_s_deflate_edges_z;
static PyObject *__pyx_n_s_deflate_faces;
static PyObject *__pyx_n_s_deflate_faces_x;
static PyObject *__pyx_n_s_deflate_faces_y;
static PyObject *__pyx_n_s_deflate_faces_z;
static PyObject *__pyx_n_s_deflate_nodes;
static PyObject *__pyx_n_s_diagonal_balance;
static PyObject *__pyx_n_s_diags;
static PyObject *__pyx_n_s_dict;
static PyObject *__pyx_n_s_dim;
static PyObject *__pyx_n_s_direction;
static PyObject *__pyx_kp_s_discretize__extensions_tree_ext;
static PyObject *__pyx_n_s_discretize__extensions_tree_ext_2;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_dtype_is_object;
static PyObject *__pyx_n_s_edge_lengths;
static PyObject *__pyx_n_s_edges_x;
static PyObject *__pyx_n_s_edges_y;
static PyObject *__pyx_n_s_edges_z;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_eps;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_eye;
static PyObject *__pyx_n_u_fXp;
static PyObject *__pyx_n_u_fYp;
static PyObject *__pyx_n_u_fZp;
static PyObject *__pyx_n_s_face_divergence_2D;
static PyObject *__pyx_n_s_face_divergence_3D;
static PyObject *__pyx_n_s_face_normals;
static PyObject *__pyx_n_s_faces_x;
static PyObject *__pyx_n_s_faces_y;
static PyObject *__pyx_n_s_faces_z;
static PyObject *__pyx_n_s_finalize;
static PyObject *__pyx_n_s_finfo;
static PyObject *__pyx_n_s_flags;
static PyObject *__pyx_n_s_float64;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_fortran;
static PyObject *__pyx_n_u_fortran;
static PyObject *__pyx_n_s_full;
static PyObject *__pyx_n_s_function;
static PyObject *__pyx_n_s_getEdgeP;
static PyObject *__pyx_n_s_getEdgePxx_locals_Pxx;
static PyObject *__pyx_n_s_getEdgePxxx_locals_Pxxx;
static PyObject *__pyx_n_s_getFaceP;
static PyObject *__pyx_n_s_getFacePxx_locals_Pxx;
static PyObject *__pyx_n_s_getFacePxxx_locals_Pxxx;
static PyObject *__pyx_n_s_get_containing_cell_indexes;
static PyObject *__pyx_n_s_getnnz;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_hanging_edges_x;
static PyObject *__pyx_n_s_hanging_edges_y;
static PyObject *__pyx_n_s_hstack;
static PyObject *__pyx_n_s_id;
static PyObject *__pyx_n_s_imatmul;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_in_tens_mesh;
static PyObject *__pyx_kp_u_inconsistent_number_of_line_segm;
static PyObject *__pyx_kp_u_inconsistent_number_of_triangles;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_n_s_init___locals_is_pow2;
static PyObject *__pyx_n_s_insert_cells;
static PyObject *__pyx_n_s_int32;
static PyObject *__pyx_n_s_int64;
static PyObject *__pyx_n_s_int8;
static PyObject *__pyx_n_s_is_pow2;
static PyObject *__pyx_n_s_itemsize;
static PyObject *__pyx_kp_s_itemsize_0_for_cython_array;
static PyObject *__pyx_kp_u_length_of_cell_width_vectors_mus;
static PyObject *__pyx_kp_u_level_length_must_match_the_poin;
static PyObject *__pyx_n_s_levels;
static PyObject *__pyx_n_s_lexsort;
static PyObject *__pyx_kp_u_line_nodes_array_must_be_N;
static PyObject *__pyx_n_s_locs;
static PyObject *__pyx_n_s_log2;
static PyObject *__pyx_n_s_lower;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_matmul;
static PyObject *__pyx_n_s_max_level;
static PyObject *__pyx_n_s_memview;
static PyObject *__pyx_n_s_meshin;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_n_cells;
static PyObject *__pyx_n_s_n_edges;
static PyObject *__pyx_n_s_n_edges_x;
static PyObject *__pyx_n_s_n_edges_y;
static PyObject *__pyx_n_s_n_edges_z;
static PyObject *__pyx_n_s_n_faces;
static PyObject *__pyx_n_s_n_faces_x;
static PyObject *__pyx_n_s_n_faces_y;
static PyObject *__pyx_n_s_n_faces_z;
static PyObject *__pyx_n_s_n_hanging_edges;
static PyObject *__pyx_n_s_n_hanging_edges_x;
static PyObject *__pyx_n_s_n_hanging_edges_y;
static PyObject *__pyx_n_s_n_hanging_edges_z;
static PyObject *__pyx_n_s_n_hanging_faces;
static PyObject *__pyx_n_s_n_hanging_faces_x;
static PyObject *__pyx_n_s_n_hanging_faces_y;
static PyObject *__pyx_n_s_n_hanging_faces_z;
static PyObject *__pyx_n_s_n_hanging_nodes;
static PyObject *__pyx_n_s_n_nodes;
static PyObject *__pyx_n_s_n_total_edges;
static PyObject *__pyx_n_s_n_total_edges_x;
static PyObject *__pyx_n_s_n_total_edges_y;
static PyObject *__pyx_n_s_n_total_edges_z;
static PyObject *__pyx_n_s_n_total_faces;
static PyObject *__pyx_n_s_n_total_faces_x;
static PyObject *__pyx_n_s_n_total_faces_y;
static PyObject *__pyx_n_s_n_total_faces_z;
static PyObject *__pyx_n_s_n_total_nodes;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_name_2;
static PyObject *__pyx_n_s_ndim;
static PyObject *__pyx_n_s_new;
static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
static PyObject *__pyx_n_s_nodes;
static PyObject *__pyx_n_s_nodes_x;
static PyObject *__pyx_n_s_nodes_y;
static PyObject *__pyx_n_s_nodes_z;
static PyObject *__pyx_n_s_nonzero;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_num;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_kp_u_numpy_core_multiarray_failed_to;
static PyObject *__pyx_kp_u_numpy_core_umath_failed_to_impor;
static PyObject *__pyx_n_s_obj;
static PyObject *__pyx_n_s_ones;
static PyObject *__pyx_n_s_order;
static PyObject *__pyx_n_s_origin;
static PyObject *__pyx_kp_u_origin_must_be_a_list_tuple_or_n;
static PyObject *__pyx_n_s_out_tens_mesh;
static PyObject *__pyx_n_s_output;
static PyObject *__pyx_n_s_pack;
static PyObject *__pyx_n_s_path;
static PyObject *__pyx_n_s_pickle;
static PyObject *__pyx_n_s_points;
static PyObject *__pyx_kp_u_points_array_must_be_N;
static PyObject *__pyx_n_s_pyx_PickleError;
static PyObject *__pyx_n_s_pyx_checksum;
static PyObject *__pyx_n_s_pyx_getbuffer;
static PyObject *__pyx_n_s_pyx_result;
static PyObject *__pyx_n_s_pyx_state;
static PyObject *__pyx_n_s_pyx_type;
static PyObject *__pyx_n_s_pyx_unpickle_Enum;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_radii;
static PyObject *__pyx_kp_u_radii_length_must_match_the_poin;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_s_refine_locals_lambda;
static PyObject *__pyx_n_s_refine_triangle;
static PyObject *__pyx_kp_u_refine_vertical_trianglular_pris;
static PyObject *__pyx_n_s_require;
static PyObject *__pyx_n_s_requirements;
static PyObject *__pyx_n_s_reshape;
static PyObject *__pyx_n_s_rmatmul;
static PyObject *__pyx_n_s_scipy_sparse;
static PyObject *__pyx_kp_s_self__cell_cannot_be_converted_t;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_shape_cells;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_sp;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_stencil_cell_gradient_x;
static PyObject *__pyx_n_u_stencil_cell_gradient_x;
static PyObject *__pyx_n_s_stencil_cell_gradient_y;
static PyObject *__pyx_n_u_stencil_cell_gradient_y;
static PyObject *__pyx_n_s_stencil_cell_gradient_z;
static PyObject *__pyx_n_u_stencil_cell_gradient_z;
static PyObject *__pyx_n_s_step;
static PyObject *__pyx_n_s_stop;
static PyObject *__pyx_kp_s_strided_and_direct;
static PyObject *__pyx_kp_s_strided_and_direct_or_indirect;
static PyObject *__pyx_kp_s_strided_and_indirect;
static PyObject *__pyx_kp_s_stringsource;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_super;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_tetra;
static PyObject *__pyx_kp_u_tetra_array_must_be_N;
static PyObject *__pyx_n_s_tocsr;
static PyObject *__pyx_n_s_triangle;
static PyObject *__pyx_kp_u_triangle_array_must_be_N_3;
static PyObject *__pyx_n_s_ubc_indArr;
static PyObject *__pyx_kp_s_unable_to_allocate_array_data;
static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str;
static PyObject *__pyx_n_s_unpack;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_n_s_vstack;
static PyObject *__pyx_n_s_where;
static PyObject *__pyx_n_u_x;
static PyObject *__pyx_n_s_x0;
static PyObject *__pyx_n_s_x0s;
static PyObject *__pyx_kp_u_x0s_and_x1s_must_have_the_same_l;
static PyObject *__pyx_kp_u_x0s_array_must_be_N;
static PyObject *__pyx_n_s_x1;
static PyObject *__pyx_n_s_x1s;
static PyObject *__pyx_kp_u_x1s_array_must_be_N;
static PyObject *__pyx_n_s_xEdge;
static PyObject *__pyx_n_s_xFace;
static PyObject *__pyx_n_u_xd;
static PyObject *__pyx_n_u_xu;
static PyObject *__pyx_n_u_y;
static PyObject *__pyx_n_s_yEdge;
static PyObject *__pyx_n_s_yFace;
static PyObject *__pyx_n_u_yd;
static PyObject *__pyx_n_u_yu;
static PyObject *__pyx_n_u_z;
static PyObject *__pyx_n_s_zEdge;
static PyObject *__pyx_n_s_zFace;
static PyObject *__pyx_n_u_zd;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_n_s_zeros_outside;
static PyObject *__pyx_n_u_zu;
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6center___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6origin___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2x0___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_1h___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_3dim___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5index___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh___cinit__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___is_pow2(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num); /* proto */
static int __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_2__init__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_h, PyObject *__pyx_v_origin, bool __pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4_clear_cache(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_cell); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_function, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8refine_ball(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_points, PyObject *__pyx_v_radii, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10refine_box(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_x0s, PyObject *__pyx_v_x1s, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12refine_line(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_path, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14refine_triangle(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_triangle, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_16refine_vertical_trianglular_prism(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_triangle, PyObject *__pyx_v_h, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_18refine_tetrahedron(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_tetra, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20insert_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_points, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22finalize(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_24number(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_26_set_origin(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_origin); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_28get_boundary_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_active_ind, PyObject *__pyx_v_direction); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_30get_cells_along_line(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_x0, PyObject *__pyx_v_x1); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_32_face_divergence_2D(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_34_face_divergence_3D(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian___get__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_36average_cell_to_total_face_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_38average_cell_to_total_face_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_40average_cell_to_total_face_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_42_deflate_edges_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_44_deflate_edges_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_46_deflate_edges_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_48_deflate_edges(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_50_deflate_faces(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_52_deflate_faces_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_54_deflate_faces_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_56_deflate_faces_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_58_deflate_nodes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_60_get_containing_cell_index(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_62_get_containing_cell_indexes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_64_count_cells_per_index(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_66_cell_levels_by_indexes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_index); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_68_getFaceP(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace, PyObject *__pyx_v_zFace); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_Pxx(PyObject *__pyx_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_70_getFacePxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_Pxxx(PyObject *__pyx_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace, PyObject *__pyx_v_zFace); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_72_getFacePxxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_74_getEdgeP(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge, PyObject *__pyx_v_zEdge); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_Pxx(PyObject *__pyx_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_76_getEdgePxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_Pxxx(PyObject *__pyx_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge, PyObject *__pyx_v_zEdge); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_78_getEdgePxxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_80_getEdgeIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside, PyObject *__pyx_v_direction); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_82_getFaceIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside, PyObject *__pyx_v_direction); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_84_getNodeIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_86_getCellIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_88__getstate__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_90__setstate__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static void __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_94__dealloc__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_96_vol_avg_from_tree(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_meshin, PyObject *__pyx_v_values, PyObject *__pyx_v_output); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_98_vol_avg_to_tens(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_out_tens_mesh, PyObject *__pyx_v_values, PyObject *__pyx_v_output); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_100_vol_avg_from_tens(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_in_tens_mesh, PyObject *__pyx_v_values, PyObject *__pyx_v_output); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_102get_overlapping_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_rectangle); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_104__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_106__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr); /* proto */
static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name); /* proto */
static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object); /* proto */
static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /* proto */
static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self); /* proto */
static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext_TreeCell(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext__TreeMesh(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_float_0_0;
static PyObject *__pyx_float_1_0;
static PyObject *__pyx_float_0_25;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_6;
static PyObject *__pyx_int_100;
static PyObject *__pyx_int_112105877;
static PyObject *__pyx_int_136983863;
static PyObject *__pyx_int_184977713;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__6;
static PyObject *__pyx_slice__7;
static PyObject *__pyx_slice__8;
static PyObject *__pyx_slice__9;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_slice__20;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__66;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__70;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__72;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_codeobj__4;
static PyObject *__pyx_codeobj__32;
static PyObject *__pyx_codeobj__34;
static PyObject *__pyx_codeobj__37;
static PyObject *__pyx_codeobj__39;
static PyObject *__pyx_codeobj__65;
/* Late includes */

/* "discretize/_extensions/tree_ext.pyx":54
 *     cdef int_t _dim
 *     cdef c_Cell* _cell
 *     cdef void _set(self, c_Cell* cell):             # <<<<<<<<<<<<<<
 *         self._cell = cell
 *         self._dim = cell.n_dim
 */

static void __pyx_f_10discretize_11_extensions_8tree_ext_8TreeCell__set(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self, Cell *__pyx_v_cell) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_set", 0);
  __Pyx_TraceCall("_set", __pyx_f[0], 54, 0, __PYX_ERR(0, 54, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":55
 *     cdef c_Cell* _cell
 *     cdef void _set(self, c_Cell* cell):
 *         self._cell = cell             # <<<<<<<<<<<<<<
 *         self._dim = cell.n_dim
 *         self._x = cell.location[0]
 */
  __Pyx_TraceLine(55,0,__PYX_ERR(0, 55, __pyx_L1_error))
  __pyx_v_self->_cell = __pyx_v_cell;

  /* "discretize/_extensions/tree_ext.pyx":56
 *     cdef void _set(self, c_Cell* cell):
 *         self._cell = cell
 *         self._dim = cell.n_dim             # <<<<<<<<<<<<<<
 *         self._x = cell.location[0]
 *         self._x0 = cell.points[0].location[0]
 */
  __Pyx_TraceLine(56,0,__PYX_ERR(0, 56, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_cell->n_dim;
  __pyx_v_self->_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":57
 *         self._cell = cell
 *         self._dim = cell.n_dim
 *         self._x = cell.location[0]             # <<<<<<<<<<<<<<
 *         self._x0 = cell.points[0].location[0]
 * 
 */
  __Pyx_TraceLine(57,0,__PYX_ERR(0, 57, __pyx_L1_error))
  __pyx_v_self->_x = (__pyx_v_cell->location[0]);

  /* "discretize/_extensions/tree_ext.pyx":58
 *         self._dim = cell.n_dim
 *         self._x = cell.location[0]
 *         self._x0 = cell.points[0].location[0]             # <<<<<<<<<<<<<<
 * 
 *         self._y = cell.location[1]
 */
  __Pyx_TraceLine(58,0,__PYX_ERR(0, 58, __pyx_L1_error))
  __pyx_v_self->_x0 = ((__pyx_v_cell->points[0])->location[0]);

  /* "discretize/_extensions/tree_ext.pyx":60
 *         self._x0 = cell.points[0].location[0]
 * 
 *         self._y = cell.location[1]             # <<<<<<<<<<<<<<
 *         self._y0 = cell.points[0].location[1]
 * 
 */
  __Pyx_TraceLine(60,0,__PYX_ERR(0, 60, __pyx_L1_error))
  __pyx_v_self->_y = (__pyx_v_cell->location[1]);

  /* "discretize/_extensions/tree_ext.pyx":61
 * 
 *         self._y = cell.location[1]
 *         self._y0 = cell.points[0].location[1]             # <<<<<<<<<<<<<<
 * 
 *         self._wx = cell.points[3].location[0] - self._x0
 */
  __Pyx_TraceLine(61,0,__PYX_ERR(0, 61, __pyx_L1_error))
  __pyx_v_self->_y0 = ((__pyx_v_cell->points[0])->location[1]);

  /* "discretize/_extensions/tree_ext.pyx":63
 *         self._y0 = cell.points[0].location[1]
 * 
 *         self._wx = cell.points[3].location[0] - self._x0             # <<<<<<<<<<<<<<
 *         self._wy = cell.points[3].location[1] - self._y0
 *         if(self._dim > 2):
 */
  __Pyx_TraceLine(63,0,__PYX_ERR(0, 63, __pyx_L1_error))
  __pyx_v_self->_wx = (((__pyx_v_cell->points[3])->location[0]) - __pyx_v_self->_x0);

  /* "discretize/_extensions/tree_ext.pyx":64
 * 
 *         self._wx = cell.points[3].location[0] - self._x0
 *         self._wy = cell.points[3].location[1] - self._y0             # <<<<<<<<<<<<<<
 *         if(self._dim > 2):
 *             self._z = cell.location[2]
 */
  __Pyx_TraceLine(64,0,__PYX_ERR(0, 64, __pyx_L1_error))
  __pyx_v_self->_wy = (((__pyx_v_cell->points[3])->location[1]) - __pyx_v_self->_y0);

  /* "discretize/_extensions/tree_ext.pyx":65
 *         self._wx = cell.points[3].location[0] - self._x0
 *         self._wy = cell.points[3].location[1] - self._y0
 *         if(self._dim > 2):             # <<<<<<<<<<<<<<
 *             self._z = cell.location[2]
 *             self._z0 = cell.points[0].location[2]
 */
  __Pyx_TraceLine(65,0,__PYX_ERR(0, 65, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim > 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":66
 *         self._wy = cell.points[3].location[1] - self._y0
 *         if(self._dim > 2):
 *             self._z = cell.location[2]             # <<<<<<<<<<<<<<
 *             self._z0 = cell.points[0].location[2]
 *             self._wz = cell.points[7].location[2] - self._z0
 */
    __Pyx_TraceLine(66,0,__PYX_ERR(0, 66, __pyx_L1_error))
    __pyx_v_self->_z = (__pyx_v_cell->location[2]);

    /* "discretize/_extensions/tree_ext.pyx":67
 *         if(self._dim > 2):
 *             self._z = cell.location[2]
 *             self._z0 = cell.points[0].location[2]             # <<<<<<<<<<<<<<
 *             self._wz = cell.points[7].location[2] - self._z0
 * 
 */
    __Pyx_TraceLine(67,0,__PYX_ERR(0, 67, __pyx_L1_error))
    __pyx_v_self->_z0 = ((__pyx_v_cell->points[0])->location[2]);

    /* "discretize/_extensions/tree_ext.pyx":68
 *             self._z = cell.location[2]
 *             self._z0 = cell.points[0].location[2]
 *             self._wz = cell.points[7].location[2] - self._z0             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
    __Pyx_TraceLine(68,0,__PYX_ERR(0, 68, __pyx_L1_error))
    __pyx_v_self->_wz = (((__pyx_v_cell->points[7])->location[2]) - __pyx_v_self->_z0);

    /* "discretize/_extensions/tree_ext.pyx":65
 *         self._wx = cell.points[3].location[0] - self._x0
 *         self._wy = cell.points[3].location[1] - self._y0
 *         if(self._dim > 2):             # <<<<<<<<<<<<<<
 *             self._z = cell.location[2]
 *             self._z0 = cell.points[0].location[2]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":54
 *     cdef int_t _dim
 *     cdef c_Cell* _cell
 *     cdef void _set(self, c_Cell* cell):             # <<<<<<<<<<<<<<
 *         self._cell = cell
 *         self._dim = cell.n_dim
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("discretize._extensions.tree_ext.TreeCell._set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "discretize/_extensions/tree_ext.pyx":71
 * 
 *     @property
 *     def nodes(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's nodes within its parent tree mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  Node *__pyx_v_points[8];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Node **__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 71, 0, __PYX_ERR(0, 71, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":83
 *         """
 *         cdef Node *points[8]
 *         points = self._cell.points             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             return [points[0].index, points[1].index,
 */
  __Pyx_TraceLine(83,0,__PYX_ERR(0, 83, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_cell->points;
  memcpy(&(__pyx_v_points[0]), __pyx_t_1, sizeof(__pyx_v_points[0]) * (8 - 0));

  /* "discretize/_extensions/tree_ext.pyx":84
 *         cdef Node *points[8]
 *         points = self._cell.points
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             return [points[0].index, points[1].index,
 *                     points[2].index, points[3].index,
 */
  __Pyx_TraceLine(84,0,__PYX_ERR(0, 84, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":85
 *         points = self._cell.points
 *         if self._dim == 3:
 *             return [points[0].index, points[1].index,             # <<<<<<<<<<<<<<
 *                     points[2].index, points[3].index,
 *                     points[4].index, points[5].index,
 */
    __Pyx_TraceLine(85,0,__PYX_ERR(0, 85, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_points[0])->index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_points[1])->index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "discretize/_extensions/tree_ext.pyx":86
 *         if self._dim == 3:
 *             return [points[0].index, points[1].index,
 *                     points[2].index, points[3].index,             # <<<<<<<<<<<<<<
 *                     points[4].index, points[5].index,
 *                     points[6].index, points[7].index]
 */
    __Pyx_TraceLine(86,0,__PYX_ERR(0, 86, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_points[2])->index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_points[3])->index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "discretize/_extensions/tree_ext.pyx":87
 *             return [points[0].index, points[1].index,
 *                     points[2].index, points[3].index,
 *                     points[4].index, points[5].index,             # <<<<<<<<<<<<<<
 *                     points[6].index, points[7].index]
 *         return [points[0].index, points[1].index,
 */
    __Pyx_TraceLine(87,0,__PYX_ERR(0, 87, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyInt_From_int_t((__pyx_v_points[4])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_From_int_t((__pyx_v_points[5])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "discretize/_extensions/tree_ext.pyx":88
 *                     points[2].index, points[3].index,
 *                     points[4].index, points[5].index,
 *                     points[6].index, points[7].index]             # <<<<<<<<<<<<<<
 *         return [points[0].index, points[1].index,
 *                 points[2].index, points[3].index]
 */
    __Pyx_TraceLine(88,0,__PYX_ERR(0, 88, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyInt_From_int_t((__pyx_v_points[6])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = __Pyx_PyInt_From_int_t((__pyx_v_points[7])->index); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);

    /* "discretize/_extensions/tree_ext.pyx":85
 *         points = self._cell.points
 *         if self._dim == 3:
 *             return [points[0].index, points[1].index,             # <<<<<<<<<<<<<<
 *                     points[2].index, points[3].index,
 *                     points[4].index, points[5].index,
 */
    __Pyx_TraceLine(85,0,__PYX_ERR(0, 85, __pyx_L1_error))
    __pyx_t_11 = PyList_New(8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_11, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_11, 3, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_11, 4, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_11, 5, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_11, 6, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_11, 7, __pyx_t_10);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_t_10 = 0;
    __pyx_r = __pyx_t_11;
    __pyx_t_11 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":84
 *         cdef Node *points[8]
 *         points = self._cell.points
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             return [points[0].index, points[1].index,
 *                     points[2].index, points[3].index,
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":89
 *                     points[4].index, points[5].index,
 *                     points[6].index, points[7].index]
 *         return [points[0].index, points[1].index,             # <<<<<<<<<<<<<<
 *                 points[2].index, points[3].index]
 * 
 */
  __Pyx_TraceLine(89,0,__PYX_ERR(0, 89, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_11 = __Pyx_PyInt_From_int_t((__pyx_v_points[0])->index); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = __Pyx_PyInt_From_int_t((__pyx_v_points[1])->index); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);

  /* "discretize/_extensions/tree_ext.pyx":90
 *                     points[6].index, points[7].index]
 *         return [points[0].index, points[1].index,
 *                 points[2].index, points[3].index]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(90,0,__PYX_ERR(0, 90, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyInt_From_int_t((__pyx_v_points[2])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 90, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyInt_From_int_t((__pyx_v_points[3])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 90, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "discretize/_extensions/tree_ext.pyx":89
 *                     points[4].index, points[5].index,
 *                     points[6].index, points[7].index]
 *         return [points[0].index, points[1].index,             # <<<<<<<<<<<<<<
 *                 points[2].index, points[3].index]
 * 
 */
  __Pyx_TraceLine(89,0,__PYX_ERR(0, 89, __pyx_L1_error))
  __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_11);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_10);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_8);
  __pyx_t_11 = 0;
  __pyx_t_10 = 0;
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":71
 * 
 *     @property
 *     def nodes(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's nodes within its parent tree mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":93
 * 
 *     @property
 *     def edges(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's edges within its parent tree mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5edges_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5edges_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5edges___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  Edge *__pyx_v_edges[12];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Edge **__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 93, 0, __PYX_ERR(0, 93, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":105
 *         """
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             return [edges[0].index, edges[1].index,
 */
  __Pyx_TraceLine(105,0,__PYX_ERR(0, 105, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_cell->edges;
  memcpy(&(__pyx_v_edges[0]), __pyx_t_1, sizeof(__pyx_v_edges[0]) * (12 - 0));

  /* "discretize/_extensions/tree_ext.pyx":106
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return [edges[0].index, edges[1].index,
 *                     edges[2].index, edges[3].index]
 */
  __Pyx_TraceLine(106,0,__PYX_ERR(0, 106, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":107
 *         edges = self._cell.edges
 *         if self._dim == 2:
 *             return [edges[0].index, edges[1].index,             # <<<<<<<<<<<<<<
 *                     edges[2].index, edges[3].index]
 *         return [
 */
    __Pyx_TraceLine(107,0,__PYX_ERR(0, 107, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_edges[0])->index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_edges[1])->index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "discretize/_extensions/tree_ext.pyx":108
 *         if self._dim == 2:
 *             return [edges[0].index, edges[1].index,
 *                     edges[2].index, edges[3].index]             # <<<<<<<<<<<<<<
 *         return [
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,
 */
    __Pyx_TraceLine(108,0,__PYX_ERR(0, 108, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_edges[2])->index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_edges[3])->index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "discretize/_extensions/tree_ext.pyx":107
 *         edges = self._cell.edges
 *         if self._dim == 2:
 *             return [edges[0].index, edges[1].index,             # <<<<<<<<<<<<<<
 *                     edges[2].index, edges[3].index]
 *         return [
 */
    __Pyx_TraceLine(107,0,__PYX_ERR(0, 107, __pyx_L1_error))
    __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_6);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":106
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return [edges[0].index, edges[1].index,
 *                     edges[2].index, edges[3].index]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":109
 *             return [edges[0].index, edges[1].index,
 *                     edges[2].index, edges[3].index]
 *         return [             # <<<<<<<<<<<<<<
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,
 *             edges[4].index, edges[5].index, edges[6].index, edges[7].index,
 */
  __Pyx_TraceLine(109,0,__PYX_ERR(0, 109, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);

  /* "discretize/_extensions/tree_ext.pyx":110
 *                     edges[2].index, edges[3].index]
 *         return [
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,             # <<<<<<<<<<<<<<
 *             edges[4].index, edges[5].index, edges[6].index, edges[7].index,
 *             edges[8].index, edges[9].index, edges[10].index, edges[11].index,
 */
  __Pyx_TraceLine(110,0,__PYX_ERR(0, 110, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyInt_From_int_t((__pyx_v_edges[0])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_edges[1])->index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_edges[2])->index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_edges[3])->index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "discretize/_extensions/tree_ext.pyx":111
 *         return [
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,
 *             edges[4].index, edges[5].index, edges[6].index, edges[7].index,             # <<<<<<<<<<<<<<
 *             edges[8].index, edges[9].index, edges[10].index, edges[11].index,
 *         ]
 */
  __Pyx_TraceLine(111,0,__PYX_ERR(0, 111, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_edges[4])->index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyInt_From_int_t((__pyx_v_edges[5])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyInt_From_int_t((__pyx_v_edges[6])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyInt_From_int_t((__pyx_v_edges[7])->index); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);

  /* "discretize/_extensions/tree_ext.pyx":112
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,
 *             edges[4].index, edges[5].index, edges[6].index, edges[7].index,
 *             edges[8].index, edges[9].index, edges[10].index, edges[11].index,             # <<<<<<<<<<<<<<
 *         ]
 * 
 */
  __Pyx_TraceLine(112,0,__PYX_ERR(0, 112, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyInt_From_int_t((__pyx_v_edges[8])->index); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_12 = __Pyx_PyInt_From_int_t((__pyx_v_edges[9])->index); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_13 = __Pyx_PyInt_From_int_t((__pyx_v_edges[10])->index); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_14 = __Pyx_PyInt_From_int_t((__pyx_v_edges[11])->index); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);

  /* "discretize/_extensions/tree_ext.pyx":109
 *             return [edges[0].index, edges[1].index,
 *                     edges[2].index, edges[3].index]
 *         return [             # <<<<<<<<<<<<<<
 *             edges[0].index, edges[1].index, edges[2].index, edges[3].index,
 *             edges[4].index, edges[5].index, edges[6].index, edges[7].index,
 */
  __Pyx_TraceLine(109,0,__PYX_ERR(0, 109, __pyx_L1_error))
  __pyx_t_15 = PyList_New(12); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_15, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_15, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_15, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_15, 4, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_15, 5, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_15, 6, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_10);
  PyList_SET_ITEM(__pyx_t_15, 7, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_11);
  PyList_SET_ITEM(__pyx_t_15, 8, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_12);
  PyList_SET_ITEM(__pyx_t_15, 9, __pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_13);
  PyList_SET_ITEM(__pyx_t_15, 10, __pyx_t_13);
  __Pyx_GIVEREF(__pyx_t_14);
  PyList_SET_ITEM(__pyx_t_15, 11, __pyx_t_14);
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;
  __pyx_t_8 = 0;
  __pyx_t_9 = 0;
  __pyx_t_10 = 0;
  __pyx_t_11 = 0;
  __pyx_t_12 = 0;
  __pyx_t_13 = 0;
  __pyx_t_14 = 0;
  __pyx_r = __pyx_t_15;
  __pyx_t_15 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":93
 * 
 *     @property
 *     def edges(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's edges within its parent tree mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":116
 * 
 *     @property
 *     def faces(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's faces within its parent tree mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5faces_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5faces_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5faces___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  Face *__pyx_v_faces[6];
  Edge *__pyx_v_edges[12];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Face **__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  Edge **__pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 116, 0, __PYX_ERR(0, 116, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":128
 *         """
 *         cdef Face *faces[6]
 *         faces = self._cell.faces             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             return [
 */
  __Pyx_TraceLine(128,0,__PYX_ERR(0, 128, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_cell->faces;
  memcpy(&(__pyx_v_faces[0]), __pyx_t_1, sizeof(__pyx_v_faces[0]) * (6 - 0));

  /* "discretize/_extensions/tree_ext.pyx":129
 *         cdef Face *faces[6]
 *         faces = self._cell.faces
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             return [
 *                 faces[0].index, faces[1].index,
 */
  __Pyx_TraceLine(129,0,__PYX_ERR(0, 129, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":130
 *         faces = self._cell.faces
 *         if self._dim == 3:
 *             return [             # <<<<<<<<<<<<<<
 *                 faces[0].index, faces[1].index,
 *                 faces[2].index, faces[3].index,
 */
    __Pyx_TraceLine(130,0,__PYX_ERR(0, 130, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);

    /* "discretize/_extensions/tree_ext.pyx":131
 *         if self._dim == 3:
 *             return [
 *                 faces[0].index, faces[1].index,             # <<<<<<<<<<<<<<
 *                 faces[2].index, faces[3].index,
 *                 faces[4].index, faces[5].index
 */
    __Pyx_TraceLine(131,0,__PYX_ERR(0, 131, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_faces[0])->index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_faces[1])->index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "discretize/_extensions/tree_ext.pyx":132
 *             return [
 *                 faces[0].index, faces[1].index,
 *                 faces[2].index, faces[3].index,             # <<<<<<<<<<<<<<
 *                 faces[4].index, faces[5].index
 *             ]
 */
    __Pyx_TraceLine(132,0,__PYX_ERR(0, 132, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_faces[2])->index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_faces[3])->index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "discretize/_extensions/tree_ext.pyx":133
 *                 faces[0].index, faces[1].index,
 *                 faces[2].index, faces[3].index,
 *                 faces[4].index, faces[5].index             # <<<<<<<<<<<<<<
 *             ]
 *         cdef Edge *edges[12]
 */
    __Pyx_TraceLine(133,0,__PYX_ERR(0, 133, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyInt_From_int_t((__pyx_v_faces[4])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_From_int_t((__pyx_v_faces[5])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "discretize/_extensions/tree_ext.pyx":130
 *         faces = self._cell.faces
 *         if self._dim == 3:
 *             return [             # <<<<<<<<<<<<<<
 *                 faces[0].index, faces[1].index,
 *                 faces[2].index, faces[3].index,
 */
    __Pyx_TraceLine(130,0,__PYX_ERR(0, 130, __pyx_L1_error))
    __pyx_t_9 = PyList_New(6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_9, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_9, 3, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_9, 4, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_9, 5, __pyx_t_8);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_r = __pyx_t_9;
    __pyx_t_9 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":129
 *         cdef Face *faces[6]
 *         faces = self._cell.faces
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             return [
 *                 faces[0].index, faces[1].index,
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":136
 *             ]
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges             # <<<<<<<<<<<<<<
 *         return [edges[2].index, edges[3].index,
 *                 edges[0].index, edges[1].index]
 */
  __Pyx_TraceLine(136,0,__PYX_ERR(0, 136, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_cell->edges;
  memcpy(&(__pyx_v_edges[0]), __pyx_t_10, sizeof(__pyx_v_edges[0]) * (12 - 0));

  /* "discretize/_extensions/tree_ext.pyx":137
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges
 *         return [edges[2].index, edges[3].index,             # <<<<<<<<<<<<<<
 *                 edges[0].index, edges[1].index]
 * 
 */
  __Pyx_TraceLine(137,0,__PYX_ERR(0, 137, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_9 = __Pyx_PyInt_From_int_t((__pyx_v_edges[2])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_PyInt_From_int_t((__pyx_v_edges[3])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "discretize/_extensions/tree_ext.pyx":138
 *         edges = self._cell.edges
 *         return [edges[2].index, edges[3].index,
 *                 edges[0].index, edges[1].index]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(138,0,__PYX_ERR(0, 138, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyInt_From_int_t((__pyx_v_edges[0])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_edges[1])->index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "discretize/_extensions/tree_ext.pyx":137
 *         cdef Edge *edges[12]
 *         edges = self._cell.edges
 *         return [edges[2].index, edges[3].index,             # <<<<<<<<<<<<<<
 *                 edges[0].index, edges[1].index]
 * 
 */
  __Pyx_TraceLine(137,0,__PYX_ERR(0, 137, __pyx_L1_error))
  __pyx_t_5 = PyList_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_5, 2, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_5, 3, __pyx_t_6);
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":116
 * 
 *     @property
 *     def faces(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's faces within its parent tree mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.faces.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":141
 * 
 *     @property
 *     def center(self):             # <<<<<<<<<<<<<<
 *         """Cell center location for the tree cell.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6center_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6center_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6center___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6center___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 141, 0, __PYX_ERR(0, 141, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":149
 *             Cell center location for the tree cell
 *         """
 *         if self._dim == 2: return np.array([self._x, self._y])             # <<<<<<<<<<<<<<
 *         return np.array([self._x, self._y, self._z])
 * 
 */
  __Pyx_TraceLine(149,0,__PYX_ERR(0, 149, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":150
 *         """
 *         if self._dim == 2: return np.array([self._x, self._y])
 *         return np.array([self._x, self._y, self._z])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(150,0,__PYX_ERR(0, 150, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_self->_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_z); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":141
 * 
 *     @property
 *     def center(self):             # <<<<<<<<<<<<<<
 *         """Cell center location for the tree cell.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.center.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":153
 * 
 *     @property
 *     def origin(self):             # <<<<<<<<<<<<<<
 *         """Origin location ('anchor point') for the tree cell.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6origin_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6origin_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6origin___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6origin___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 153, 0, __PYX_ERR(0, 153, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":165
 *             Origin location ('anchor point') for the tree cell
 *         """
 *         if self._dim == 2: return np.array([self._x0, self._y0])             # <<<<<<<<<<<<<<
 *         return np.array([self._x0, self._y0, self._z0])
 * 
 */
  __Pyx_TraceLine(165,0,__PYX_ERR(0, 165, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_x0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_y0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":166
 *         """
 *         if self._dim == 2: return np.array([self._x0, self._y0])
 *         return np.array([self._x0, self._y0, self._z0])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(166,0,__PYX_ERR(0, 166, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_self->_x0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_y0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_z0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":153
 * 
 *     @property
 *     def origin(self):             # <<<<<<<<<<<<<<
 *         """Origin location ('anchor point') for the tree cell.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.origin.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":169
 * 
 *     @property
 *     def x0(self):             # <<<<<<<<<<<<<<
 *         """Origin location ('anchor point') for the tree cell.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_2x0_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_2x0_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2x0___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2x0___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 169, 0, __PYX_ERR(0, 169, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":181
 *             Origin location ('anchor point') for the tree cell
 *         """
 *         return self.origin             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(181,0,__PYX_ERR(0, 181, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_origin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":169
 * 
 *     @property
 *     def x0(self):             # <<<<<<<<<<<<<<
 *         """Origin location ('anchor point') for the tree cell.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.x0.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":184
 * 
 *     @property
 *     def h(self):             # <<<<<<<<<<<<<<
 *         """Cell dimension along each axis direction.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1h_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1h_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_1h___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_1h___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 184, 0, __PYX_ERR(0, 184, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":195
 *             Cell dimension along each axis direction
 *         """
 *         if self._dim == 2: return np.array([self._wx, self._wy])             # <<<<<<<<<<<<<<
 *         return np.array([self._wx, self._wy, self._wz])
 * 
 */
  __Pyx_TraceLine(195,0,__PYX_ERR(0, 195, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_wx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_wy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":196
 *         """
 *         if self._dim == 2: return np.array([self._wx, self._wy])
 *         return np.array([self._wx, self._wy, self._wz])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(196,0,__PYX_ERR(0, 196, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_self->_wx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->_wy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->_wz); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":184
 * 
 *     @property
 *     def h(self):             # <<<<<<<<<<<<<<
 *         """Cell dimension along each axis direction.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.h.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":199
 * 
 *     @property
 *     def dim(self):             # <<<<<<<<<<<<<<
 *         """Dimension of the tree cell; 1, 2 or 3.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3dim_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3dim_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_3dim___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_3dim___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 199, 0, __PYX_ERR(0, 199, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":207
 *             Dimension of the tree cell; 1, 2 or 3
 *         """
 *         return self._dim             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(207,0,__PYX_ERR(0, 207, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":199
 * 
 *     @property
 *     def dim(self):             # <<<<<<<<<<<<<<
 *         """Dimension of the tree cell; 1, 2 or 3.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.dim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":210
 * 
 *     @property
 *     def index(self):             # <<<<<<<<<<<<<<
 *         """Index of the tree cell within its parent tree mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5index_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5index_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5index___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_5index___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 210, 0, __PYX_ERR(0, 210, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":218
 *             Index of the tree cell within its parent tree mesh
 *         """
 *         return self._cell.index             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(218,0,__PYX_ERR(0, 218, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_self->_cell->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":210
 * 
 *     @property
 *     def index(self):             # <<<<<<<<<<<<<<
 *         """Index of the tree cell within its parent tree mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.index.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":221
 * 
 *     @property
 *     def neighbors(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's neighbors within its parent tree mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_v_neighbors = NULL;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  long __pyx_t_3;
  long __pyx_t_4;
  long __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 221, 0, __PYX_ERR(0, 221, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":238
 *             Indices for this cell's neighbors within its parent tree mesh
 *         """
 *         neighbors = [-1]*self._dim*2             # <<<<<<<<<<<<<<
 * 
 *         for i in range(self._dim*2):
 */
  __Pyx_TraceLine(238,0,__PYX_ERR(0, 238, __pyx_L1_error))
  __pyx_t_1 = PyList_New(1 * ((__pyx_v_self->_dim<0) ? 0:__pyx_v_self->_dim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  { Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < __pyx_v_self->_dim; __pyx_temp++) {
      __Pyx_INCREF(__pyx_int_neg_1);
      __Pyx_GIVEREF(__pyx_int_neg_1);
      PyList_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_int_neg_1);
    }
  }
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 238, __pyx_L1_error)
  __pyx_v_neighbors = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":240
 *         neighbors = [-1]*self._dim*2
 * 
 *         for i in range(self._dim*2):             # <<<<<<<<<<<<<<
 *             if self._cell.neighbors[i] is NULL:
 *                 continue
 */
  __Pyx_TraceLine(240,0,__PYX_ERR(0, 240, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_self->_dim * 2);
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_i = __pyx_t_5;

    /* "discretize/_extensions/tree_ext.pyx":241
 * 
 *         for i in range(self._dim*2):
 *             if self._cell.neighbors[i] is NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif self._cell.neighbors[i].is_leaf():
 */
    __Pyx_TraceLine(241,0,__PYX_ERR(0, 241, __pyx_L1_error))
    __pyx_t_6 = (((__pyx_v_self->_cell->neighbors[__pyx_v_i]) == NULL) != 0);
    if (__pyx_t_6) {

      /* "discretize/_extensions/tree_ext.pyx":242
 *         for i in range(self._dim*2):
 *             if self._cell.neighbors[i] is NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             elif self._cell.neighbors[i].is_leaf():
 *                 neighbors[i] = self._cell.neighbors[i].index
 */
      __Pyx_TraceLine(242,0,__PYX_ERR(0, 242, __pyx_L1_error))
      goto __pyx_L3_continue;

      /* "discretize/_extensions/tree_ext.pyx":241
 * 
 *         for i in range(self._dim*2):
 *             if self._cell.neighbors[i] is NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif self._cell.neighbors[i].is_leaf():
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":243
 *             if self._cell.neighbors[i] is NULL:
 *                 continue
 *             elif self._cell.neighbors[i].is_leaf():             # <<<<<<<<<<<<<<
 *                 neighbors[i] = self._cell.neighbors[i].index
 *             else:
 */
    __Pyx_TraceLine(243,0,__PYX_ERR(0, 243, __pyx_L1_error))
    __pyx_t_6 = ((__pyx_v_self->_cell->neighbors[__pyx_v_i])->is_leaf() != 0);
    if (__pyx_t_6) {

      /* "discretize/_extensions/tree_ext.pyx":244
 *                 continue
 *             elif self._cell.neighbors[i].is_leaf():
 *                 neighbors[i] = self._cell.neighbors[i].index             # <<<<<<<<<<<<<<
 *             else:
 *                 if self._dim==2:
 */
      __Pyx_TraceLine(244,0,__PYX_ERR(0, 244, __pyx_L1_error))
      __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG((__pyx_v_self->_cell->neighbors[__pyx_v_i])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(__pyx_v_neighbors == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 244, __pyx_L1_error)
      }
      if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 244, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discretize/_extensions/tree_ext.pyx":243
 *             if self._cell.neighbors[i] is NULL:
 *                 continue
 *             elif self._cell.neighbors[i].is_leaf():             # <<<<<<<<<<<<<<
 *                 neighbors[i] = self._cell.neighbors[i].index
 *             else:
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":246
 *                 neighbors[i] = self._cell.neighbors[i].index
 *             else:
 *                 if self._dim==2:             # <<<<<<<<<<<<<<
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 */
    __Pyx_TraceLine(246,0,__PYX_ERR(0, 246, __pyx_L1_error))
    /*else*/ {
      __pyx_t_6 = ((__pyx_v_self->_dim == 2) != 0);
      if (__pyx_t_6) {

        /* "discretize/_extensions/tree_ext.pyx":247
 *             else:
 *                 if self._dim==2:
 *                     if i==0:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index]
 */
        __Pyx_TraceLine(247,0,__PYX_ERR(0, 247, __pyx_L1_error))
        switch (__pyx_v_i) {
          case 0:

          /* "discretize/_extensions/tree_ext.pyx":248
 *                 if self._dim==2:
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index]
 *                     elif i==1:
 */
          __Pyx_TraceLine(248,0,__PYX_ERR(0, 248, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[1])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "discretize/_extensions/tree_ext.pyx":249
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index]             # <<<<<<<<<<<<<<
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 */
          __Pyx_TraceLine(249,0,__PYX_ERR(0, 249, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[3])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 249, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":248
 *                 if self._dim==2:
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index]
 *                     elif i==1:
 */
          __Pyx_TraceLine(248,0,__PYX_ERR(0, 248, __pyx_L1_error))
          __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 248, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 248, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_7, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 248, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":247
 *             else:
 *                 if self._dim==2:
 *                     if i==0:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index]
 */
          break;
          case 1:

          /* "discretize/_extensions/tree_ext.pyx":251
 *                                         self._cell.neighbors[i].children[3].index]
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[2].index]
 *                     elif i==2:
 */
          __Pyx_TraceLine(251,0,__PYX_ERR(0, 251, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[0])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 251, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":252
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index]             # <<<<<<<<<<<<<<
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 */
          __Pyx_TraceLine(252,0,__PYX_ERR(0, 252, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[2])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":251
 *                                         self._cell.neighbors[i].children[3].index]
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[2].index]
 *                     elif i==2:
 */
          __Pyx_TraceLine(251,0,__PYX_ERR(0, 251, __pyx_L1_error))
          __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
          __pyx_t_7 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 251, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 251, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":250
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index]
 *                     elif i==1:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index]
 */
          break;
          case 2:

          /* "discretize/_extensions/tree_ext.pyx":254
 *                                         self._cell.neighbors[i].children[2].index]
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index]
 *                     else:
 */
          __Pyx_TraceLine(254,0,__PYX_ERR(0, 254, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[2])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "discretize/_extensions/tree_ext.pyx":255
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index]             # <<<<<<<<<<<<<<
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 */
          __Pyx_TraceLine(255,0,__PYX_ERR(0, 255, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[3])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":254
 *                                         self._cell.neighbors[i].children[2].index]
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index]
 *                     else:
 */
          __Pyx_TraceLine(254,0,__PYX_ERR(0, 254, __pyx_L1_error))
          __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 254, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 254, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_7, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 254, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":253
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index]
 *                     elif i==2:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index]
 */
          break;
          default:

          /* "discretize/_extensions/tree_ext.pyx":257
 *                                         self._cell.neighbors[i].children[3].index]
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index]
 *                 else:
 */
          __Pyx_TraceLine(257,0,__PYX_ERR(0, 257, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[0])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 257, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":258
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index]             # <<<<<<<<<<<<<<
 *                 else:
 *                     if i==0:
 */
          __Pyx_TraceLine(258,0,__PYX_ERR(0, 258, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[1])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":257
 *                                         self._cell.neighbors[i].children[3].index]
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index]
 *                 else:
 */
          __Pyx_TraceLine(257,0,__PYX_ERR(0, 257, __pyx_L1_error))
          __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
          __pyx_t_7 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 257, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 257, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          break;
        }

        /* "discretize/_extensions/tree_ext.pyx":246
 *                 neighbors[i] = self._cell.neighbors[i].index
 *             else:
 *                 if self._dim==2:             # <<<<<<<<<<<<<<
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":260
 *                                         self._cell.neighbors[i].children[1].index]
 *                 else:
 *                     if i==0:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index,
 */
      __Pyx_TraceLine(260,0,__PYX_ERR(0, 260, __pyx_L1_error))
      /*else*/ {

        /* "discretize/_extensions/tree_ext.pyx":280
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index]
 *                     elif i==4:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index,
 */
        __Pyx_TraceLine(280,0,__PYX_ERR(0, 280, __pyx_L1_error))
        switch (__pyx_v_i) {
          case 0:

          /* "discretize/_extensions/tree_ext.pyx":261
 *                 else:
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[5].index,
 */
          __Pyx_TraceLine(261,0,__PYX_ERR(0, 261, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[1])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "discretize/_extensions/tree_ext.pyx":262
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[7].index]
 */
          __Pyx_TraceLine(262,0,__PYX_ERR(0, 262, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[3])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":263
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[5].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==1:
 */
          __Pyx_TraceLine(263,0,__PYX_ERR(0, 263, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[5])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 263, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":264
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[7].index]             # <<<<<<<<<<<<<<
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 */
          __Pyx_TraceLine(264,0,__PYX_ERR(0, 264, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[7])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 264, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":261
 *                 else:
 *                     if i==0:
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[5].index,
 */
          __Pyx_TraceLine(261,0,__PYX_ERR(0, 261, __pyx_L1_error))
          __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_9, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_9, 3, __pyx_t_8);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 261, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 261, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "discretize/_extensions/tree_ext.pyx":260
 *                                         self._cell.neighbors[i].children[1].index]
 *                 else:
 *                     if i==0:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[3].index,
 */
          break;
          case 1:

          /* "discretize/_extensions/tree_ext.pyx":266
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[4].index,
 */
          __Pyx_TraceLine(266,0,__PYX_ERR(0, 266, __pyx_L1_error))
          __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[0])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 266, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);

          /* "discretize/_extensions/tree_ext.pyx":267
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[6].index]
 */
          __Pyx_TraceLine(267,0,__PYX_ERR(0, 267, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[2])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 267, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":268
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[4].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[6].index]
 *                     elif i==2:
 */
          __Pyx_TraceLine(268,0,__PYX_ERR(0, 268, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[4])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":269
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[6].index]             # <<<<<<<<<<<<<<
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 */
          __Pyx_TraceLine(269,0,__PYX_ERR(0, 269, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[6])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":266
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==1:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[4].index,
 */
          __Pyx_TraceLine(266,0,__PYX_ERR(0, 266, __pyx_L1_error))
          __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_2, 3, __pyx_t_1);
          __pyx_t_9 = 0;
          __pyx_t_8 = 0;
          __pyx_t_7 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 266, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 266, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":265
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==1:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[2].index,
 */
          break;
          case 2:

          /* "discretize/_extensions/tree_ext.pyx":271
 *                                         self._cell.neighbors[i].children[6].index]
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[6].index,
 */
          __Pyx_TraceLine(271,0,__PYX_ERR(0, 271, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[2])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "discretize/_extensions/tree_ext.pyx":272
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[6].index,
 *                                         self._cell.neighbors[i].children[7].index]
 */
          __Pyx_TraceLine(272,0,__PYX_ERR(0, 272, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[3])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":273
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[6].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==3:
 */
          __Pyx_TraceLine(273,0,__PYX_ERR(0, 273, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[6])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":274
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[6].index,
 *                                         self._cell.neighbors[i].children[7].index]             # <<<<<<<<<<<<<<
 *                     elif i==3:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 */
          __Pyx_TraceLine(274,0,__PYX_ERR(0, 274, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[7])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 274, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":271
 *                                         self._cell.neighbors[i].children[6].index]
 *                     elif i==2:
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index,
 *                                         self._cell.neighbors[i].children[6].index,
 */
          __Pyx_TraceLine(271,0,__PYX_ERR(0, 271, __pyx_L1_error))
          __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 271, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_9, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_9, 3, __pyx_t_8);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 271, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 271, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "discretize/_extensions/tree_ext.pyx":270
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[6].index]
 *                     elif i==2:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index,
 */
          break;
          case 3:

          /* "discretize/_extensions/tree_ext.pyx":276
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==3:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[4].index,
 */
          __Pyx_TraceLine(276,0,__PYX_ERR(0, 276, __pyx_L1_error))
          __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[0])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);

          /* "discretize/_extensions/tree_ext.pyx":277
 *                     elif i==3:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index]
 */
          __Pyx_TraceLine(277,0,__PYX_ERR(0, 277, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[1])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 277, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":278
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[4].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[5].index]
 *                     elif i==4:
 */
          __Pyx_TraceLine(278,0,__PYX_ERR(0, 278, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[4])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":279
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index]             # <<<<<<<<<<<<<<
 *                     elif i==4:
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,
 */
          __Pyx_TraceLine(279,0,__PYX_ERR(0, 279, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[5])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":276
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==3:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[4].index,
 */
          __Pyx_TraceLine(276,0,__PYX_ERR(0, 276, __pyx_L1_error))
          __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_2, 3, __pyx_t_1);
          __pyx_t_9 = 0;
          __pyx_t_8 = 0;
          __pyx_t_7 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 276, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":275
 *                                         self._cell.neighbors[i].children[6].index,
 *                                         self._cell.neighbors[i].children[7].index]
 *                     elif i==3:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index,
 */
          break;
          case 4:

          /* "discretize/_extensions/tree_ext.pyx":281
 *                                         self._cell.neighbors[i].children[5].index]
 *                     elif i==4:
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[6].index,
 */
          __Pyx_TraceLine(281,0,__PYX_ERR(0, 281, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[4])->index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "discretize/_extensions/tree_ext.pyx":282
 *                     elif i==4:
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[6].index,
 *                                         self._cell.neighbors[i].children[7].index]
 */
          __Pyx_TraceLine(282,0,__PYX_ERR(0, 282, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[5])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":283
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[6].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[7].index]
 *                     else:
 */
          __Pyx_TraceLine(283,0,__PYX_ERR(0, 283, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[6])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 283, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":284
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[6].index,
 *                                         self._cell.neighbors[i].children[7].index]             # <<<<<<<<<<<<<<
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 */
          __Pyx_TraceLine(284,0,__PYX_ERR(0, 284, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[7])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 284, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":281
 *                                         self._cell.neighbors[i].children[5].index]
 *                     elif i==4:
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[5].index,
 *                                         self._cell.neighbors[i].children[6].index,
 */
          __Pyx_TraceLine(281,0,__PYX_ERR(0, 281, __pyx_L1_error))
          __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_2);
          PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_9, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_9, 3, __pyx_t_8);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 281, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 281, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "discretize/_extensions/tree_ext.pyx":280
 *                                         self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index]
 *                     elif i==4:             # <<<<<<<<<<<<<<
 *                         neighbors[i] = [self._cell.neighbors[i].children[4].index,
 *                                         self._cell.neighbors[i].children[5].index,
 */
          break;
          default:

          /* "discretize/_extensions/tree_ext.pyx":286
 *                                         self._cell.neighbors[i].children[7].index]
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[2].index,
 */
          __Pyx_TraceLine(286,0,__PYX_ERR(0, 286, __pyx_L1_error))
          __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[0])->index); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 286, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);

          /* "discretize/_extensions/tree_ext.pyx":287
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index]
 */
          __Pyx_TraceLine(287,0,__PYX_ERR(0, 287, __pyx_L1_error))
          __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[1])->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 287, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "discretize/_extensions/tree_ext.pyx":288
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[2].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[3].index]
 *         return neighbors
 */
          __Pyx_TraceLine(288,0,__PYX_ERR(0, 288, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[2])->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 288, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "discretize/_extensions/tree_ext.pyx":289
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index]             # <<<<<<<<<<<<<<
 *         return neighbors
 * 
 */
          __Pyx_TraceLine(289,0,__PYX_ERR(0, 289, __pyx_L1_error))
          __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(((__pyx_v_self->_cell->neighbors[__pyx_v_i])->children[3])->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 289, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);

          /* "discretize/_extensions/tree_ext.pyx":286
 *                                         self._cell.neighbors[i].children[7].index]
 *                     else:
 *                         neighbors[i] = [self._cell.neighbors[i].children[0].index,             # <<<<<<<<<<<<<<
 *                                         self._cell.neighbors[i].children[1].index,
 *                                         self._cell.neighbors[i].children[2].index,
 */
          __Pyx_TraceLine(286,0,__PYX_ERR(0, 286, __pyx_L1_error))
          __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 286, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_9);
          PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_8);
          PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_7);
          PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_1);
          PyList_SET_ITEM(__pyx_t_2, 3, __pyx_t_1);
          __pyx_t_9 = 0;
          __pyx_t_8 = 0;
          __pyx_t_7 = 0;
          __pyx_t_1 = 0;
          if (unlikely(__pyx_v_neighbors == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 286, __pyx_L1_error)
          }
          if (unlikely(__Pyx_SetItemInt(__pyx_v_neighbors, __pyx_v_i, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 1, 1, 1) < 0)) __PYX_ERR(0, 286, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          break;
        }
      }
      __pyx_L6:;
    }
    __pyx_L5:;
    __pyx_L3_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":290
 *                                         self._cell.neighbors[i].children[2].index,
 *                                         self._cell.neighbors[i].children[3].index]
 *         return neighbors             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(290,0,__PYX_ERR(0, 290, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_neighbors);
  __pyx_r = __pyx_v_neighbors;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":221
 * 
 *     @property
 *     def neighbors(self):             # <<<<<<<<<<<<<<
 *         """Indices for this cell's neighbors within its parent tree mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.neighbors.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_neighbors);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":293
 * 
 *     @property
 *     def _index_loc(self):             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 293, 0, __PYX_ERR(0, 293, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":294
 *     @property
 *     def _index_loc(self):
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],
 */
  __Pyx_TraceLine(294,0,__PYX_ERR(0, 294, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":295
 *     def _index_loc(self):
 *         if self._dim == 2:
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))             # <<<<<<<<<<<<<<
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],
 *                       self._cell.location_ind[2]))
 */
    __Pyx_TraceLine(295,0,__PYX_ERR(0, 295, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_int_t((__pyx_v_self->_cell->location_ind[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_self->_cell->location_ind[1])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":294
 *     @property
 *     def _index_loc(self):
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":296
 *         if self._dim == 2:
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],             # <<<<<<<<<<<<<<
 *                       self._cell.location_ind[2]))
 * 
 */
  __Pyx_TraceLine(296,0,__PYX_ERR(0, 296, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_self->_cell->location_ind[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_self->_cell->location_ind[1])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "discretize/_extensions/tree_ext.pyx":297
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],
 *                       self._cell.location_ind[2]))             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(297,0,__PYX_ERR(0, 297, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyInt_From_int_t((__pyx_v_self->_cell->location_ind[2])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 297, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "discretize/_extensions/tree_ext.pyx":296
 *         if self._dim == 2:
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 *         return tuple((self._cell.location_ind[0], self._cell.location_ind[1],             # <<<<<<<<<<<<<<
 *                       self._cell.location_ind[2]))
 * 
 */
  __Pyx_TraceLine(296,0,__PYX_ERR(0, 296, __pyx_L1_error))
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":293
 * 
 *     @property
 *     def _index_loc(self):             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             return tuple((self._cell.location_ind[0], self._cell.location_ind[1]))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell._index_loc.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":300
 * 
 *     @property
 *     def _level(self):             # <<<<<<<<<<<<<<
 *         return self._cell.level
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6_level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6_level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6_level___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_6_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 300, 0, __PYX_ERR(0, 300, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":301
 *     @property
 *     def _level(self):
 *         return self._cell.level             # <<<<<<<<<<<<<<
 * 
 * cdef int _evaluate_func(void* function, c_Cell* cell) with gil:
 */
  __Pyx_TraceLine(301,0,__PYX_ERR(0, 301, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int_t(__pyx_v_self->_cell->level); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 301, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":300
 * 
 *     @property
 *     def _level(self):             # <<<<<<<<<<<<<<
 *         return self._cell.level
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell._level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_8TreeCell___reduce_cython__[] = "TreeCell.__reduce_cython__(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell___reduce_cython__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 */
  __Pyx_TraceLine(2,0,__PYX_ERR(1, 2, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_8TreeCell_2__setstate_cython__[] = "TreeCell.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2__setstate_cython__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_8TreeCell_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext.TreeCell.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":303
 *         return self._cell.level
 * 
 * cdef int _evaluate_func(void* function, c_Cell* cell) with gil:             # <<<<<<<<<<<<<<
 *     # Wraps a function to be called in C++
 *     func = <object> function
 */

static int __pyx_f_10discretize_11_extensions_8tree_ext__evaluate_func(void *__pyx_v_function, Cell *__pyx_v_cell) {
  PyObject *__pyx_v_func = NULL;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_pycell = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_val = NULL;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_evaluate_func", 0);
  __Pyx_TraceCall("_evaluate_func", __pyx_f[0], 303, 0, __PYX_ERR(0, 303, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":305
 * cdef int _evaluate_func(void* function, c_Cell* cell) with gil:
 *     # Wraps a function to be called in C++
 *     func = <object> function             # <<<<<<<<<<<<<<
 *     pycell = TreeCell()
 *     pycell._set(cell)
 */
  __Pyx_TraceLine(305,0,__PYX_ERR(0, 305, __pyx_L1_error))
  __pyx_t_1 = ((PyObject *)__pyx_v_function);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_func = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":306
 *     # Wraps a function to be called in C++
 *     func = <object> function
 *     pycell = TreeCell()             # <<<<<<<<<<<<<<
 *     pycell._set(cell)
 *     val = func(pycell)
 */
  __Pyx_TraceLine(306,0,__PYX_ERR(0, 306, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_10discretize_11_extensions_8tree_ext_TreeCell)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 306, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pycell = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":307
 *     func = <object> function
 *     pycell = TreeCell()
 *     pycell._set(cell)             # <<<<<<<<<<<<<<
 *     val = func(pycell)
 *     return <int> func(pycell)
 */
  __Pyx_TraceLine(307,0,__PYX_ERR(0, 307, __pyx_L1_error))
  ((struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_pycell->__pyx_vtab)->_set(__pyx_v_pycell, __pyx_v_cell);

  /* "discretize/_extensions/tree_ext.pyx":308
 *     pycell = TreeCell()
 *     pycell._set(cell)
 *     val = func(pycell)             # <<<<<<<<<<<<<<
 *     return <int> func(pycell)
 * 
 */
  __Pyx_TraceLine(308,0,__PYX_ERR(0, 308, __pyx_L1_error))
  __Pyx_INCREF(__pyx_v_func);
  __pyx_t_2 = __pyx_v_func; __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_v_pycell)) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_pycell));
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_val = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":309
 *     pycell._set(cell)
 *     val = func(pycell)
 *     return <int> func(pycell)             # <<<<<<<<<<<<<<
 * 
 * cdef class _TreeMesh:
 */
  __Pyx_TraceLine(309,0,__PYX_ERR(0, 309, __pyx_L1_error))
  __Pyx_INCREF(__pyx_v_func);
  __pyx_t_2 = __pyx_v_func; __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_v_pycell)) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_pycell));
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = ((int)__pyx_t_4);
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":303
 *         return self._cell.level
 * 
 * cdef int _evaluate_func(void* function, c_Cell* cell) with gil:             # <<<<<<<<<<<<<<
 *     # Wraps a function to be called in C++
 *     func = <object> function
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("discretize._extensions.tree_ext._evaluate_func", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_func);
  __Pyx_XDECREF((PyObject *)__pyx_v_pycell);
  __Pyx_XDECREF(__pyx_v_val);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":338
 *     cdef object __ubc_order, __ubc_indArr
 * 
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         self.wrapper = new PyWrapper()
 *         self.tree = new c_Tree()
 */

/* Python wrapper */
static int __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh___cinit__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

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

static int __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh___cinit__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 338, 0, __PYX_ERR(0, 338, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":339
 * 
 *     def __cinit__(self, *args, **kwargs):
 *         self.wrapper = new PyWrapper()             # <<<<<<<<<<<<<<
 *         self.tree = new c_Tree()
 * 
 */
  __Pyx_TraceLine(339,0,__PYX_ERR(0, 339, __pyx_L1_error))
  __pyx_v_self->wrapper = new PyWrapper();

  /* "discretize/_extensions/tree_ext.pyx":340
 *     def __cinit__(self, *args, **kwargs):
 *         self.wrapper = new PyWrapper()
 *         self.tree = new c_Tree()             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 */
  __Pyx_TraceLine(340,0,__PYX_ERR(0, 340, __pyx_L1_error))
  __pyx_v_self->tree = new Tree();

  /* "discretize/_extensions/tree_ext.pyx":338
 *     cdef object __ubc_order, __ubc_indArr
 * 
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         self.wrapper = new PyWrapper()
 *         self.tree = new c_Tree()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":342
 *         self.tree = new c_Tree()
 * 
 *     def __init__(self, h, origin, bool diagonal_balance=False):             # <<<<<<<<<<<<<<
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):
 */

/* Python wrapper */
static int __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_h = 0;
  PyObject *__pyx_v_origin = 0;
  bool __pyx_v_diagonal_balance;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_h,&__pyx_n_s_origin,&__pyx_n_s_diagonal_balance,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_h)) != 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_origin)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 342, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 342, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_h = values[0];
    __pyx_v_origin = values[1];
    if (values[2]) {
      __pyx_v_diagonal_balance = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_diagonal_balance == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 342, __pyx_L3_error)
    } else {
      __pyx_v_diagonal_balance = ((bool)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 342, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_2__init__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_h, __pyx_v_origin, __pyx_v_diagonal_balance);

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

/* "discretize/_extensions/tree_ext.pyx":344
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):             # <<<<<<<<<<<<<<
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___1is_pow2(PyObject *__pyx_self, PyObject *__pyx_v_num); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___1is_pow2 = {"is_pow2", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___1is_pow2, METH_O, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___1is_pow2(PyObject *__pyx_self, PyObject *__pyx_v_num) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_pow2 (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___is_pow2(__pyx_self, ((PyObject *)__pyx_v_num));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___is_pow2(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_pow2", 0);
  __Pyx_TraceCall("is_pow2", __pyx_f[0], 344, 0, __PYX_ERR(0, 344, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":345
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):
 *             return ((num & (num - 1)) == 0) and num != 0             # <<<<<<<<<<<<<<
 *         for n in self.shape_cells:
 *             if not is_pow2(n):
 */
  __Pyx_TraceLine(345,0,__PYX_ERR(0, 345, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_num, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_v_num, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 345, __pyx_L1_error)
  if (__pyx_t_4) {
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyInt_NeObjC(__pyx_v_num, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_1 = __pyx_t_2;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":344
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):             # <<<<<<<<<<<<<<
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__init__.is_pow2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":342
 *         self.tree = new c_Tree()
 * 
 *     def __init__(self, h, origin, bool diagonal_balance=False):             # <<<<<<<<<<<<<<
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):
 */

static int __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_2__init__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_h, PyObject *__pyx_v_origin, bool __pyx_v_diagonal_balance) {
  PyObject *__pyx_v_is_pow2 = 0;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_nx2 = NULL;
  PyObject *__pyx_v_ny2 = NULL;
  PyObject *__pyx_v_xs = NULL;
  PyObject *__pyx_v_ys = NULL;
  PyObject *__pyx_v_nz2 = NULL;
  PyObject *__pyx_v_zs = NULL;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  int __pyx_t_6;
  int __pyx_t_7;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 342, 0, __PYX_ERR(0, 342, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_h);
  __Pyx_INCREF(__pyx_v_origin);

  /* "discretize/_extensions/tree_ext.pyx":343
 * 
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 *         super().__init__(h=h, origin=origin)             # <<<<<<<<<<<<<<
 *         def is_pow2(num):
 *             return ((num & (num - 1)) == 0) and num != 0
 */
  __Pyx_TraceLine(343,0,__PYX_ERR(0, 343, __pyx_L1_error))
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh));
  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self));
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_h, __pyx_v_h) < 0) __PYX_ERR(0, 343, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_origin, __pyx_v_origin) < 0) __PYX_ERR(0, 343, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 343, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":344
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):             # <<<<<<<<<<<<<<
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 */
  __Pyx_TraceLine(344,0,__PYX_ERR(0, 344, __pyx_L1_error))
  __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___1is_pow2, 0, __pyx_n_s_init___locals_is_pow2, NULL, __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_is_pow2 = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":346
 *         def is_pow2(num):
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:             # <<<<<<<<<<<<<<
 *             if not is_pow2(n):
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 */
  __Pyx_TraceLine(346,0,__PYX_ERR(0, 346, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_shape_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 346, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 346, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 346, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 346, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":347
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 *             if not is_pow2(n):             # <<<<<<<<<<<<<<
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 *         h = self.h
 */
    __Pyx_TraceLine(347,0,__PYX_ERR(0, 347, __pyx_L1_error))
    __pyx_t_3 = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8__init___is_pow2(__pyx_v_is_pow2, __pyx_v_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = ((!__pyx_t_6) != 0);
    if (unlikely(__pyx_t_7)) {

      /* "discretize/_extensions/tree_ext.pyx":348
 *         for n in self.shape_cells:
 *             if not is_pow2(n):
 *                 raise ValueError("length of cell width vectors must be a power of 2")             # <<<<<<<<<<<<<<
 *         h = self.h
 *         origin = self.origin
 */
      __Pyx_TraceLine(348,0,__PYX_ERR(0, 348, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 348, __pyx_L1_error)

      /* "discretize/_extensions/tree_ext.pyx":347
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 *             if not is_pow2(n):             # <<<<<<<<<<<<<<
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 *         h = self.h
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":346
 *         def is_pow2(num):
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:             # <<<<<<<<<<<<<<
 *             if not is_pow2(n):
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 */
    __Pyx_TraceLine(346,0,__PYX_ERR(0, 346, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":349
 *             if not is_pow2(n):
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 *         h = self.h             # <<<<<<<<<<<<<<
 *         origin = self.origin
 * 
 */
  __Pyx_TraceLine(349,0,__PYX_ERR(0, 349, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_h); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":350
 *                 raise ValueError("length of cell width vectors must be a power of 2")
 *         h = self.h
 *         origin = self.origin             # <<<<<<<<<<<<<<
 * 
 *         nx2 = 2*len(h[0])
 */
  __Pyx_TraceLine(350,0,__PYX_ERR(0, 350, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_origin); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_origin, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":352
 *         origin = self.origin
 * 
 *         nx2 = 2*len(h[0])             # <<<<<<<<<<<<<<
 *         ny2 = 2*len(h[1])
 *         self._dim = len(origin)
 */
  __Pyx_TraceLine(352,0,__PYX_ERR(0, 352, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_h, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromSsize_t((2 * __pyx_t_4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_nx2 = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":353
 * 
 *         nx2 = 2*len(h[0])
 *         ny2 = 2*len(h[1])             # <<<<<<<<<<<<<<
 *         self._dim = len(origin)
 *         self._origin = origin
 */
  __Pyx_TraceLine(353,0,__PYX_ERR(0, 353, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_h, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromSsize_t((2 * __pyx_t_4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_ny2 = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":354
 *         nx2 = 2*len(h[0])
 *         ny2 = 2*len(h[1])
 *         self._dim = len(origin)             # <<<<<<<<<<<<<<
 *         self._origin = origin
 * 
 */
  __Pyx_TraceLine(354,0,__PYX_ERR(0, 354, __pyx_L1_error))
  __pyx_t_4 = PyObject_Length(__pyx_v_origin); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 354, __pyx_L1_error)
  __pyx_v_self->_dim = __pyx_t_4;

  /* "discretize/_extensions/tree_ext.pyx":355
 *         ny2 = 2*len(h[1])
 *         self._dim = len(origin)
 *         self._origin = origin             # <<<<<<<<<<<<<<
 * 
 *         xs = np.empty(nx2 + 1, dtype=float)
 */
  __Pyx_TraceLine(355,0,__PYX_ERR(0, 355, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_origin, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 355, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_v_self->_origin, 0);
  __pyx_v_self->_origin = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":357
 *         self._origin = origin
 * 
 *         xs = np.empty(nx2 + 1, dtype=float)             # <<<<<<<<<<<<<<
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2
 */
  __Pyx_TraceLine(357,0,__PYX_ERR(0, 357, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_nx2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 357, __pyx_L1_error)
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_xs = __pyx_t_9;
  __pyx_t_9 = 0;

  /* "discretize/_extensions/tree_ext.pyx":358
 * 
 *         xs = np.empty(nx2 + 1, dtype=float)
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])             # <<<<<<<<<<<<<<
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2
 *         self._xs = xs
 */
  __Pyx_TraceLine(358,0,__PYX_ERR(0, 358, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_cumsum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_r); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_origin, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_h, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
  __pyx_t_2 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_9 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_xs, __pyx_slice__6, __pyx_t_9) < 0)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "discretize/_extensions/tree_ext.pyx":359
 *         xs = np.empty(nx2 + 1, dtype=float)
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2             # <<<<<<<<<<<<<<
 *         self._xs = xs
 *         self.ls[0] = int(np.log2(len(h[0])))
 */
  __Pyx_TraceLine(359,0,__PYX_ERR(0, 359, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_xs, __pyx_slice__7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_xs, __pyx_slice__8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_TrueDivideObjC(__pyx_t_10, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_xs, __pyx_slice__9, __pyx_t_1) < 0)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":360
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2
 *         self._xs = xs             # <<<<<<<<<<<<<<
 *         self.ls[0] = int(np.log2(len(h[0])))
 * 
 */
  __Pyx_TraceLine(360,0,__PYX_ERR(0, 360, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_xs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 360, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_v_self->_xs, 0);
  __pyx_v_self->_xs = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":361
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2
 *         self._xs = xs
 *         self.ls[0] = int(np.log2(len(h[0])))             # <<<<<<<<<<<<<<
 * 
 *         ys = np.empty(ny2 + 1, dtype=float)
 */
  __Pyx_TraceLine(361,0,__PYX_ERR(0, 361, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_log2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_h, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = PyObject_Length(__pyx_t_10); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_11, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int_t(__pyx_t_9); if (unlikely((__pyx_t_12 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  (__pyx_v_self->ls[0]) = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":363
 *         self.ls[0] = int(np.log2(len(h[0])))
 * 
 *         ys = np.empty(ny2 + 1, dtype=float)             # <<<<<<<<<<<<<<
 *         ys[::2] = np.cumsum(np.r_[origin[1],h[1]])
 *         ys[1::2] = (ys[:-1:2] + ys[2::2])/2
 */
  __Pyx_TraceLine(363,0,__PYX_ERR(0, 363, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_ny2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 363, __pyx_L1_error)
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_ys = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "discretize/_extensions/tree_ext.pyx":364
 * 
 *         ys = np.empty(ny2 + 1, dtype=float)
 *         ys[::2] = np.cumsum(np.r_[origin[1],h[1]])             # <<<<<<<<<<<<<<
 *         ys[1::2] = (ys[:-1:2] + ys[2::2])/2
 *         self._ys = ys
 */
  __Pyx_TraceLine(364,0,__PYX_ERR(0, 364, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_cumsum); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_r); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_origin, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_h, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __pyx_t_9 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_10);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_10, function);
    }
  }
  __pyx_t_11 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_ys, __pyx_slice__6, __pyx_t_11) < 0)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "discretize/_extensions/tree_ext.pyx":365
 *         ys = np.empty(ny2 + 1, dtype=float)
 *         ys[::2] = np.cumsum(np.r_[origin[1],h[1]])
 *         ys[1::2] = (ys[:-1:2] + ys[2::2])/2             # <<<<<<<<<<<<<<
 *         self._ys = ys
 *         self.ls[1] = int(np.log2(len(h[1])))
 */
  __Pyx_TraceLine(365,0,__PYX_ERR(0, 365, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_ys, __pyx_slice__7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_ys, __pyx_slice__8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_3 = PyNumber_Add(__pyx_t_11, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyInt_TrueDivideObjC(__pyx_t_3, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_ys, __pyx_slice__9, __pyx_t_10) < 0)) __PYX_ERR(0, 365, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "discretize/_extensions/tree_ext.pyx":366
 *         ys[::2] = np.cumsum(np.r_[origin[1],h[1]])
 *         ys[1::2] = (ys[:-1:2] + ys[2::2])/2
 *         self._ys = ys             # <<<<<<<<<<<<<<
 *         self.ls[1] = int(np.log2(len(h[1])))
 * 
 */
  __Pyx_TraceLine(366,0,__PYX_ERR(0, 366, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_ys, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 366, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_v_self->_ys, 0);
  __pyx_v_self->_ys = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":367
 *         ys[1::2] = (ys[:-1:2] + ys[2::2])/2
 *         self._ys = ys
 *         self.ls[1] = int(np.log2(len(h[1])))             # <<<<<<<<<<<<<<
 * 
 *         if self._dim > 2:
 */
  __Pyx_TraceLine(367,0,__PYX_ERR(0, 367, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_h, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  __pyx_t_10 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyNumber_Int(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int_t(__pyx_t_11); if (unlikely((__pyx_t_12 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  (__pyx_v_self->ls[1]) = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":369
 *         self.ls[1] = int(np.log2(len(h[1])))
 * 
 *         if self._dim > 2:             # <<<<<<<<<<<<<<
 *             nz2 = 2*len(h[2])
 * 
 */
  __Pyx_TraceLine(369,0,__PYX_ERR(0, 369, __pyx_L1_error))
  __pyx_t_7 = ((__pyx_v_self->_dim > 2) != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":370
 * 
 *         if self._dim > 2:
 *             nz2 = 2*len(h[2])             # <<<<<<<<<<<<<<
 * 
 *             zs = np.empty(nz2 + 1, dtype=float)
 */
    __Pyx_TraceLine(370,0,__PYX_ERR(0, 370, __pyx_L1_error))
    __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_h, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_4 = PyObject_Length(__pyx_t_11); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 370, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyInt_FromSsize_t((2 * __pyx_t_4)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_v_nz2 = __pyx_t_11;
    __pyx_t_11 = 0;

    /* "discretize/_extensions/tree_ext.pyx":372
 *             nz2 = 2*len(h[2])
 * 
 *             zs = np.empty(nz2 + 1, dtype=float)             # <<<<<<<<<<<<<<
 *             zs[::2] = np.cumsum(np.r_[origin[2],h[2]])
 *             zs[1::2] = (zs[:-1:2] + zs[2::2])/2
 */
    __Pyx_TraceLine(372,0,__PYX_ERR(0, 372, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_empty); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_v_nz2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 372, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_v_zs = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":373
 * 
 *             zs = np.empty(nz2 + 1, dtype=float)
 *             zs[::2] = np.cumsum(np.r_[origin[2],h[2]])             # <<<<<<<<<<<<<<
 *             zs[1::2] = (zs[:-1:2] + zs[2::2])/2
 *             self._zs = zs
 */
    __Pyx_TraceLine(373,0,__PYX_ERR(0, 373, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_cumsum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_r); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_origin, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_h, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
    __pyx_t_11 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_zs, __pyx_slice__6, __pyx_t_2) < 0)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":374
 *             zs = np.empty(nz2 + 1, dtype=float)
 *             zs[::2] = np.cumsum(np.r_[origin[2],h[2]])
 *             zs[1::2] = (zs[:-1:2] + zs[2::2])/2             # <<<<<<<<<<<<<<
 *             self._zs = zs
 *             self.ls[2] = int(np.log2(len(h[2])))
 */
    __Pyx_TraceLine(374,0,__PYX_ERR(0, 374, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_zs, __pyx_slice__7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_zs, __pyx_slice__8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_TrueDivideObjC(__pyx_t_1, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_zs, __pyx_slice__9, __pyx_t_3) < 0)) __PYX_ERR(0, 374, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":375
 *             zs[::2] = np.cumsum(np.r_[origin[2],h[2]])
 *             zs[1::2] = (zs[:-1:2] + zs[2::2])/2
 *             self._zs = zs             # <<<<<<<<<<<<<<
 *             self.ls[2] = int(np.log2(len(h[2])))
 *         else:
 */
    __Pyx_TraceLine(375,0,__PYX_ERR(0, 375, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_zs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 375, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_self->_zs, 0);
    __pyx_v_self->_zs = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":376
 *             zs[1::2] = (zs[:-1:2] + zs[2::2])/2
 *             self._zs = zs
 *             self.ls[2] = int(np.log2(len(h[2])))             # <<<<<<<<<<<<<<
 *         else:
 *             self._zs = np.zeros(1, dtype=float)
 */
    __Pyx_TraceLine(376,0,__PYX_ERR(0, 376, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_log2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_h, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_12 = __Pyx_PyInt_As_int_t(__pyx_t_2); if (unlikely((__pyx_t_12 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    (__pyx_v_self->ls[2]) = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":369
 *         self.ls[1] = int(np.log2(len(h[1])))
 * 
 *         if self._dim > 2:             # <<<<<<<<<<<<<<
 *             nz2 = 2*len(h[2])
 * 
 */
    goto __pyx_L6;
  }

  /* "discretize/_extensions/tree_ext.pyx":378
 *             self.ls[2] = int(np.log2(len(h[2])))
 *         else:
 *             self._zs = np.zeros(1, dtype=float)             # <<<<<<<<<<<<<<
 *             self.ls[2] = 1
 * 
 */
  __Pyx_TraceLine(378,0,__PYX_ERR(0, 378, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 378, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__10, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_v_self->_zs, 0);
    __pyx_v_self->_zs = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":379
 *         else:
 *             self._zs = np.zeros(1, dtype=float)
 *             self.ls[2] = 1             # <<<<<<<<<<<<<<
 * 
 *         self.tree.set_dimension(self._dim)
 */
    __Pyx_TraceLine(379,0,__PYX_ERR(0, 379, __pyx_L1_error))
    (__pyx_v_self->ls[2]) = 1;
  }
  __pyx_L6:;

  /* "discretize/_extensions/tree_ext.pyx":381
 *             self.ls[2] = 1
 * 
 *         self.tree.set_dimension(self._dim)             # <<<<<<<<<<<<<<
 *         self.tree.set_levels(self.ls[0], self.ls[1], self.ls[2])
 *         self.tree.set_xs(&self._xs[0], &self._ys[0], &self._zs[0])
 */
  __Pyx_TraceLine(381,0,__PYX_ERR(0, 381, __pyx_L1_error))
  __pyx_v_self->tree->set_dimension(__pyx_v_self->_dim);

  /* "discretize/_extensions/tree_ext.pyx":382
 * 
 *         self.tree.set_dimension(self._dim)
 *         self.tree.set_levels(self.ls[0], self.ls[1], self.ls[2])             # <<<<<<<<<<<<<<
 *         self.tree.set_xs(&self._xs[0], &self._ys[0], &self._zs[0])
 *         self.tree.initialize_roots()
 */
  __Pyx_TraceLine(382,0,__PYX_ERR(0, 382, __pyx_L1_error))
  __pyx_v_self->tree->set_levels((__pyx_v_self->ls[0]), (__pyx_v_self->ls[1]), (__pyx_v_self->ls[2]));

  /* "discretize/_extensions/tree_ext.pyx":383
 *         self.tree.set_dimension(self._dim)
 *         self.tree.set_levels(self.ls[0], self.ls[1], self.ls[2])
 *         self.tree.set_xs(&self._xs[0], &self._ys[0], &self._zs[0])             # <<<<<<<<<<<<<<
 *         self.tree.initialize_roots()
 *         self._finalized = False
 */
  __Pyx_TraceLine(383,0,__PYX_ERR(0, 383, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 383, __pyx_L1_error)}
  __pyx_t_13 = 0;
  __pyx_t_14 = -1;
  if (__pyx_t_13 < 0) {
    __pyx_t_13 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
  } else if (unlikely(__pyx_t_13 >= __pyx_v_self->_xs.shape[0])) __pyx_t_14 = 0;
  if (unlikely(__pyx_t_14 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_14);
    __PYX_ERR(0, 383, __pyx_L1_error)
  }
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 383, __pyx_L1_error)}
  __pyx_t_15 = 0;
  __pyx_t_14 = -1;
  if (__pyx_t_15 < 0) {
    __pyx_t_15 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_15 < 0)) __pyx_t_14 = 0;
  } else if (unlikely(__pyx_t_15 >= __pyx_v_self->_ys.shape[0])) __pyx_t_14 = 0;
  if (unlikely(__pyx_t_14 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_14);
    __PYX_ERR(0, 383, __pyx_L1_error)
  }
  if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 383, __pyx_L1_error)}
  __pyx_t_16 = 0;
  __pyx_t_14 = -1;
  if (__pyx_t_16 < 0) {
    __pyx_t_16 += __pyx_v_self->_zs.shape[0];
    if (unlikely(__pyx_t_16 < 0)) __pyx_t_14 = 0;
  } else if (unlikely(__pyx_t_16 >= __pyx_v_self->_zs.shape[0])) __pyx_t_14 = 0;
  if (unlikely(__pyx_t_14 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_14);
    __PYX_ERR(0, 383, __pyx_L1_error)
  }
  __pyx_v_self->tree->set_xs((&(*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_13 * __pyx_v_self->_xs.strides[0]) )))), (&(*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_15 * __pyx_v_self->_ys.strides[0]) )))), (&(*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_16 * __pyx_v_self->_zs.strides[0]) )))));

  /* "discretize/_extensions/tree_ext.pyx":384
 *         self.tree.set_levels(self.ls[0], self.ls[1], self.ls[2])
 *         self.tree.set_xs(&self._xs[0], &self._ys[0], &self._zs[0])
 *         self.tree.initialize_roots()             # <<<<<<<<<<<<<<
 *         self._finalized = False
 *         self._diagonal_balance = diagonal_balance
 */
  __Pyx_TraceLine(384,0,__PYX_ERR(0, 384, __pyx_L1_error))
  __pyx_v_self->tree->initialize_roots();

  /* "discretize/_extensions/tree_ext.pyx":385
 *         self.tree.set_xs(&self._xs[0], &self._ys[0], &self._zs[0])
 *         self.tree.initialize_roots()
 *         self._finalized = False             # <<<<<<<<<<<<<<
 *         self._diagonal_balance = diagonal_balance
 *         self._clear_cache()
 */
  __Pyx_TraceLine(385,0,__PYX_ERR(0, 385, __pyx_L1_error))
  __pyx_v_self->_finalized = 0;

  /* "discretize/_extensions/tree_ext.pyx":386
 *         self.tree.initialize_roots()
 *         self._finalized = False
 *         self._diagonal_balance = diagonal_balance             # <<<<<<<<<<<<<<
 *         self._clear_cache()
 * 
 */
  __Pyx_TraceLine(386,0,__PYX_ERR(0, 386, __pyx_L1_error))
  __pyx_v_self->_diagonal_balance = __pyx_v_diagonal_balance;

  /* "discretize/_extensions/tree_ext.pyx":387
 *         self._finalized = False
 *         self._diagonal_balance = diagonal_balance
 *         self._clear_cache()             # <<<<<<<<<<<<<<
 * 
 *     def _clear_cache(self):
 */
  __Pyx_TraceLine(387,0,__PYX_ERR(0, 387, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clear_cache); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":342
 *         self.tree = new c_Tree()
 * 
 *     def __init__(self, h, origin, bool diagonal_balance=False):             # <<<<<<<<<<<<<<
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_is_pow2);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_nx2);
  __Pyx_XDECREF(__pyx_v_ny2);
  __Pyx_XDECREF(__pyx_v_xs);
  __Pyx_XDECREF(__pyx_v_ys);
  __Pyx_XDECREF(__pyx_v_nz2);
  __Pyx_XDECREF(__pyx_v_zs);
  __Pyx_XDECREF(__pyx_v_h);
  __Pyx_XDECREF(__pyx_v_origin);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":389
 *         self._clear_cache()
 * 
 *     def _clear_cache(self):             # <<<<<<<<<<<<<<
 *         self._cell_centers = None
 *         self._nodes = None
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5_clear_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_4_clear_cache[] = "_TreeMesh._clear_cache(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5_clear_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_clear_cache (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4_clear_cache(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4_clear_cache(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_clear_cache", 0);
  __Pyx_TraceCall("_clear_cache", __pyx_f[0], 389, 0, __PYX_ERR(0, 389, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":390
 * 
 *     def _clear_cache(self):
 *         self._cell_centers = None             # <<<<<<<<<<<<<<
 *         self._nodes = None
 *         self._hanging_nodes = None
 */
  __Pyx_TraceLine(390,0,__PYX_ERR(0, 390, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_cell_centers);
  __Pyx_DECREF(__pyx_v_self->_cell_centers);
  __pyx_v_self->_cell_centers = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":391
 *     def _clear_cache(self):
 *         self._cell_centers = None
 *         self._nodes = None             # <<<<<<<<<<<<<<
 *         self._hanging_nodes = None
 *         self._h_gridded = None
 */
  __Pyx_TraceLine(391,0,__PYX_ERR(0, 391, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_nodes);
  __Pyx_DECREF(__pyx_v_self->_nodes);
  __pyx_v_self->_nodes = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":392
 *         self._cell_centers = None
 *         self._nodes = None
 *         self._hanging_nodes = None             # <<<<<<<<<<<<<<
 *         self._h_gridded = None
 * 
 */
  __Pyx_TraceLine(392,0,__PYX_ERR(0, 392, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_nodes);
  __Pyx_DECREF(__pyx_v_self->_hanging_nodes);
  __pyx_v_self->_hanging_nodes = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":393
 *         self._nodes = None
 *         self._hanging_nodes = None
 *         self._h_gridded = None             # <<<<<<<<<<<<<<
 * 
 *         self._edges_x = None
 */
  __Pyx_TraceLine(393,0,__PYX_ERR(0, 393, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_h_gridded);
  __Pyx_DECREF(__pyx_v_self->_h_gridded);
  __pyx_v_self->_h_gridded = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":395
 *         self._h_gridded = None
 * 
 *         self._edges_x = None             # <<<<<<<<<<<<<<
 *         self._edges_y = None
 *         self._edges_z = None
 */
  __Pyx_TraceLine(395,0,__PYX_ERR(0, 395, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_edges_x);
  __Pyx_DECREF(__pyx_v_self->_edges_x);
  __pyx_v_self->_edges_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":396
 * 
 *         self._edges_x = None
 *         self._edges_y = None             # <<<<<<<<<<<<<<
 *         self._edges_z = None
 *         self._hanging_edges_x = None
 */
  __Pyx_TraceLine(396,0,__PYX_ERR(0, 396, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_edges_y);
  __Pyx_DECREF(__pyx_v_self->_edges_y);
  __pyx_v_self->_edges_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":397
 *         self._edges_x = None
 *         self._edges_y = None
 *         self._edges_z = None             # <<<<<<<<<<<<<<
 *         self._hanging_edges_x = None
 *         self._hanging_edges_y = None
 */
  __Pyx_TraceLine(397,0,__PYX_ERR(0, 397, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_edges_z);
  __Pyx_DECREF(__pyx_v_self->_edges_z);
  __pyx_v_self->_edges_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":398
 *         self._edges_y = None
 *         self._edges_z = None
 *         self._hanging_edges_x = None             # <<<<<<<<<<<<<<
 *         self._hanging_edges_y = None
 *         self._hanging_edges_z = None
 */
  __Pyx_TraceLine(398,0,__PYX_ERR(0, 398, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_edges_x);
  __Pyx_DECREF(__pyx_v_self->_hanging_edges_x);
  __pyx_v_self->_hanging_edges_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":399
 *         self._edges_z = None
 *         self._hanging_edges_x = None
 *         self._hanging_edges_y = None             # <<<<<<<<<<<<<<
 *         self._hanging_edges_z = None
 * 
 */
  __Pyx_TraceLine(399,0,__PYX_ERR(0, 399, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_edges_y);
  __Pyx_DECREF(__pyx_v_self->_hanging_edges_y);
  __pyx_v_self->_hanging_edges_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":400
 *         self._hanging_edges_x = None
 *         self._hanging_edges_y = None
 *         self._hanging_edges_z = None             # <<<<<<<<<<<<<<
 * 
 *         self._faces_x = None
 */
  __Pyx_TraceLine(400,0,__PYX_ERR(0, 400, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_edges_z);
  __Pyx_DECREF(__pyx_v_self->_hanging_edges_z);
  __pyx_v_self->_hanging_edges_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":402
 *         self._hanging_edges_z = None
 * 
 *         self._faces_x = None             # <<<<<<<<<<<<<<
 *         self._faces_y = None
 *         self._faces_z = None
 */
  __Pyx_TraceLine(402,0,__PYX_ERR(0, 402, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_faces_x);
  __Pyx_DECREF(__pyx_v_self->_faces_x);
  __pyx_v_self->_faces_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":403
 * 
 *         self._faces_x = None
 *         self._faces_y = None             # <<<<<<<<<<<<<<
 *         self._faces_z = None
 *         self._hanging_faces_x = None
 */
  __Pyx_TraceLine(403,0,__PYX_ERR(0, 403, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_faces_y);
  __Pyx_DECREF(__pyx_v_self->_faces_y);
  __pyx_v_self->_faces_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":404
 *         self._faces_x = None
 *         self._faces_y = None
 *         self._faces_z = None             # <<<<<<<<<<<<<<
 *         self._hanging_faces_x = None
 *         self._hanging_faces_y = None
 */
  __Pyx_TraceLine(404,0,__PYX_ERR(0, 404, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_faces_z);
  __Pyx_DECREF(__pyx_v_self->_faces_z);
  __pyx_v_self->_faces_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":405
 *         self._faces_y = None
 *         self._faces_z = None
 *         self._hanging_faces_x = None             # <<<<<<<<<<<<<<
 *         self._hanging_faces_y = None
 *         self._hanging_faces_z = None
 */
  __Pyx_TraceLine(405,0,__PYX_ERR(0, 405, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_faces_x);
  __Pyx_DECREF(__pyx_v_self->_hanging_faces_x);
  __pyx_v_self->_hanging_faces_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":406
 *         self._faces_z = None
 *         self._hanging_faces_x = None
 *         self._hanging_faces_y = None             # <<<<<<<<<<<<<<
 *         self._hanging_faces_z = None
 * 
 */
  __Pyx_TraceLine(406,0,__PYX_ERR(0, 406, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_faces_y);
  __Pyx_DECREF(__pyx_v_self->_hanging_faces_y);
  __pyx_v_self->_hanging_faces_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":407
 *         self._hanging_faces_x = None
 *         self._hanging_faces_y = None
 *         self._hanging_faces_z = None             # <<<<<<<<<<<<<<
 * 
 *         self._cell_volumes = None
 */
  __Pyx_TraceLine(407,0,__PYX_ERR(0, 407, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_hanging_faces_z);
  __Pyx_DECREF(__pyx_v_self->_hanging_faces_z);
  __pyx_v_self->_hanging_faces_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":409
 *         self._hanging_faces_z = None
 * 
 *         self._cell_volumes = None             # <<<<<<<<<<<<<<
 *         self._face_areas = None
 *         self._edge_lengths = None
 */
  __Pyx_TraceLine(409,0,__PYX_ERR(0, 409, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_cell_volumes);
  __Pyx_DECREF(__pyx_v_self->_cell_volumes);
  __pyx_v_self->_cell_volumes = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":410
 * 
 *         self._cell_volumes = None
 *         self._face_areas = None             # <<<<<<<<<<<<<<
 *         self._edge_lengths = None
 * 
 */
  __Pyx_TraceLine(410,0,__PYX_ERR(0, 410, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_face_areas);
  __Pyx_DECREF(__pyx_v_self->_face_areas);
  __pyx_v_self->_face_areas = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":411
 *         self._cell_volumes = None
 *         self._face_areas = None
 *         self._edge_lengths = None             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_to_face = None
 */
  __Pyx_TraceLine(411,0,__PYX_ERR(0, 411, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_edge_lengths);
  __Pyx_DECREF(__pyx_v_self->_edge_lengths);
  __pyx_v_self->_edge_lengths = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":413
 *         self._edge_lengths = None
 * 
 *         self._average_cell_to_face = None             # <<<<<<<<<<<<<<
 *         self._average_cell_to_face_x = None
 *         self._average_cell_to_face_y = None
 */
  __Pyx_TraceLine(413,0,__PYX_ERR(0, 413, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face);
  __pyx_v_self->_average_cell_to_face = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":414
 * 
 *         self._average_cell_to_face = None
 *         self._average_cell_to_face_x = None             # <<<<<<<<<<<<<<
 *         self._average_cell_to_face_y = None
 *         self._average_cell_to_face_z = None
 */
  __Pyx_TraceLine(414,0,__PYX_ERR(0, 414, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_x);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_x);
  __pyx_v_self->_average_cell_to_face_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":415
 *         self._average_cell_to_face = None
 *         self._average_cell_to_face_x = None
 *         self._average_cell_to_face_y = None             # <<<<<<<<<<<<<<
 *         self._average_cell_to_face_z = None
 * 
 */
  __Pyx_TraceLine(415,0,__PYX_ERR(0, 415, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_y);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_y);
  __pyx_v_self->_average_cell_to_face_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":416
 *         self._average_cell_to_face_x = None
 *         self._average_cell_to_face_y = None
 *         self._average_cell_to_face_z = None             # <<<<<<<<<<<<<<
 * 
 *         self._average_face_x_to_cell = None
 */
  __Pyx_TraceLine(416,0,__PYX_ERR(0, 416, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_z);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_z);
  __pyx_v_self->_average_cell_to_face_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":418
 *         self._average_cell_to_face_z = None
 * 
 *         self._average_face_x_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_face_y_to_cell = None
 *         self._average_face_z_to_cell = None
 */
  __Pyx_TraceLine(418,0,__PYX_ERR(0, 418, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_face_x_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_x_to_cell);
  __pyx_v_self->_average_face_x_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":419
 * 
 *         self._average_face_x_to_cell = None
 *         self._average_face_y_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_face_z_to_cell = None
 *         self._average_face_to_cell = None
 */
  __Pyx_TraceLine(419,0,__PYX_ERR(0, 419, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_face_y_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_y_to_cell);
  __pyx_v_self->_average_face_y_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":420
 *         self._average_face_x_to_cell = None
 *         self._average_face_y_to_cell = None
 *         self._average_face_z_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_face_to_cell = None
 *         self._average_face_to_cell_vector = None
 */
  __Pyx_TraceLine(420,0,__PYX_ERR(0, 420, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_face_z_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_z_to_cell);
  __pyx_v_self->_average_face_z_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":421
 *         self._average_face_y_to_cell = None
 *         self._average_face_z_to_cell = None
 *         self._average_face_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_face_to_cell_vector = None
 * 
 */
  __Pyx_TraceLine(421,0,__PYX_ERR(0, 421, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_face_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_to_cell);
  __pyx_v_self->_average_face_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":422
 *         self._average_face_z_to_cell = None
 *         self._average_face_to_cell = None
 *         self._average_face_to_cell_vector = None             # <<<<<<<<<<<<<<
 * 
 *         self._average_edge_x_to_cell = None
 */
  __Pyx_TraceLine(422,0,__PYX_ERR(0, 422, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_face_to_cell_vector);
  __Pyx_DECREF(__pyx_v_self->_average_face_to_cell_vector);
  __pyx_v_self->_average_face_to_cell_vector = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":424
 *         self._average_face_to_cell_vector = None
 * 
 *         self._average_edge_x_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_edge_y_to_cell = None
 *         self._average_edge_z_to_cell = None
 */
  __Pyx_TraceLine(424,0,__PYX_ERR(0, 424, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_x_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_x_to_cell);
  __pyx_v_self->_average_edge_x_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":425
 * 
 *         self._average_edge_x_to_cell = None
 *         self._average_edge_y_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_edge_z_to_cell = None
 *         self._average_edge_to_cell = None
 */
  __Pyx_TraceLine(425,0,__PYX_ERR(0, 425, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_y_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_y_to_cell);
  __pyx_v_self->_average_edge_y_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":426
 *         self._average_edge_x_to_cell = None
 *         self._average_edge_y_to_cell = None
 *         self._average_edge_z_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_edge_to_cell = None
 *         self._average_edge_to_cell_vector = None
 */
  __Pyx_TraceLine(426,0,__PYX_ERR(0, 426, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_z_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_z_to_cell);
  __pyx_v_self->_average_edge_z_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":427
 *         self._average_edge_y_to_cell = None
 *         self._average_edge_z_to_cell = None
 *         self._average_edge_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_edge_to_cell_vector = None
 *         self._average_edge_to_face = None
 */
  __Pyx_TraceLine(427,0,__PYX_ERR(0, 427, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_to_cell);
  __pyx_v_self->_average_edge_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":428
 *         self._average_edge_z_to_cell = None
 *         self._average_edge_to_cell = None
 *         self._average_edge_to_cell_vector = None             # <<<<<<<<<<<<<<
 *         self._average_edge_to_face = None
 * 
 */
  __Pyx_TraceLine(428,0,__PYX_ERR(0, 428, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_to_cell_vector);
  __Pyx_DECREF(__pyx_v_self->_average_edge_to_cell_vector);
  __pyx_v_self->_average_edge_to_cell_vector = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":429
 *         self._average_edge_to_cell = None
 *         self._average_edge_to_cell_vector = None
 *         self._average_edge_to_face = None             # <<<<<<<<<<<<<<
 * 
 *         self._average_node_to_cell = None
 */
  __Pyx_TraceLine(429,0,__PYX_ERR(0, 429, __pyx_L1_error))
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_to_face, Py_None) < 0) __PYX_ERR(0, 429, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":431
 *         self._average_edge_to_face = None
 * 
 *         self._average_node_to_cell = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge = None
 *         self._average_node_to_face = None
 */
  __Pyx_TraceLine(431,0,__PYX_ERR(0, 431, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_cell);
  __pyx_v_self->_average_node_to_cell = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":432
 * 
 *         self._average_node_to_cell = None
 *         self._average_node_to_edge = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_face = None
 *         self._average_node_to_edge_x = None
 */
  __Pyx_TraceLine(432,0,__PYX_ERR(0, 432, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge);
  __pyx_v_self->_average_node_to_edge = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":433
 *         self._average_node_to_cell = None
 *         self._average_node_to_edge = None
 *         self._average_node_to_face = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_x = None
 *         self._average_node_to_edge_y = None
 */
  __Pyx_TraceLine(433,0,__PYX_ERR(0, 433, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face);
  __pyx_v_self->_average_node_to_face = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":434
 *         self._average_node_to_edge = None
 *         self._average_node_to_face = None
 *         self._average_node_to_edge_x = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_y = None
 *         self._average_node_to_edge_z = None
 */
  __Pyx_TraceLine(434,0,__PYX_ERR(0, 434, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_x);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_x);
  __pyx_v_self->_average_node_to_edge_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":435
 *         self._average_node_to_face = None
 *         self._average_node_to_edge_x = None
 *         self._average_node_to_edge_y = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_z = None
 *         self._average_node_to_face_x = None
 */
  __Pyx_TraceLine(435,0,__PYX_ERR(0, 435, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_y);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_y);
  __pyx_v_self->_average_node_to_edge_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":436
 *         self._average_node_to_edge_x = None
 *         self._average_node_to_edge_y = None
 *         self._average_node_to_edge_z = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_x = None
 *         self._average_node_to_face_y = None
 */
  __Pyx_TraceLine(436,0,__PYX_ERR(0, 436, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_z);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_z);
  __pyx_v_self->_average_node_to_edge_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":437
 *         self._average_node_to_edge_y = None
 *         self._average_node_to_edge_z = None
 *         self._average_node_to_face_x = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_y = None
 *         self._average_node_to_face_z = None
 */
  __Pyx_TraceLine(437,0,__PYX_ERR(0, 437, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_x);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_x);
  __pyx_v_self->_average_node_to_face_x = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":438
 *         self._average_node_to_edge_z = None
 *         self._average_node_to_face_x = None
 *         self._average_node_to_face_y = None             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_z = None
 * 
 */
  __Pyx_TraceLine(438,0,__PYX_ERR(0, 438, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_y);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_y);
  __pyx_v_self->_average_node_to_face_y = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":439
 *         self._average_node_to_face_x = None
 *         self._average_node_to_face_y = None
 *         self._average_node_to_face_z = None             # <<<<<<<<<<<<<<
 * 
 *         self._face_divergence = None
 */
  __Pyx_TraceLine(439,0,__PYX_ERR(0, 439, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_z);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_z);
  __pyx_v_self->_average_node_to_face_z = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":441
 *         self._average_node_to_face_z = None
 * 
 *         self._face_divergence = None             # <<<<<<<<<<<<<<
 *         self._nodal_gradient = None
 *         self._edge_curl = None
 */
  __Pyx_TraceLine(441,0,__PYX_ERR(0, 441, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_face_divergence);
  __Pyx_DECREF(__pyx_v_self->_face_divergence);
  __pyx_v_self->_face_divergence = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":442
 * 
 *         self._face_divergence = None
 *         self._nodal_gradient = None             # <<<<<<<<<<<<<<
 *         self._edge_curl = None
 * 
 */
  __Pyx_TraceLine(442,0,__PYX_ERR(0, 442, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_nodal_gradient);
  __Pyx_DECREF(__pyx_v_self->_nodal_gradient);
  __pyx_v_self->_nodal_gradient = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":443
 *         self._face_divergence = None
 *         self._nodal_gradient = None
 *         self._edge_curl = None             # <<<<<<<<<<<<<<
 * 
 *         self.__ubc_order = None
 */
  __Pyx_TraceLine(443,0,__PYX_ERR(0, 443, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_edge_curl);
  __Pyx_DECREF(__pyx_v_self->_edge_curl);
  __pyx_v_self->_edge_curl = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":445
 *         self._edge_curl = None
 * 
 *         self.__ubc_order = None             # <<<<<<<<<<<<<<
 *         self.__ubc_indArr = None
 * 
 */
  __Pyx_TraceLine(445,0,__PYX_ERR(0, 445, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx___ubc_order);
  __Pyx_DECREF(__pyx_v_self->__pyx___ubc_order);
  __pyx_v_self->__pyx___ubc_order = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":446
 * 
 *         self.__ubc_order = None
 *         self.__ubc_indArr = None             # <<<<<<<<<<<<<<
 * 
 *     def refine(self, function, finalize=True, diagonal_balance=None):
 */
  __Pyx_TraceLine(446,0,__PYX_ERR(0, 446, __pyx_L1_error))
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx___ubc_indArr);
  __Pyx_DECREF(__pyx_v_self->__pyx___ubc_indArr);
  __pyx_v_self->__pyx___ubc_indArr = Py_None;

  /* "discretize/_extensions/tree_ext.pyx":389
 *         self._clear_cache()
 * 
 *     def _clear_cache(self):             # <<<<<<<<<<<<<<
 *         self._cell_centers = None
 *         self._nodes = None
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._clear_cache", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":448
 *         self.__ubc_indArr = None
 * 
 *     def refine(self, function, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` with user-defined function.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7refine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine[] = "_TreeMesh.refine(self, function, finalize=True, diagonal_balance=None)\nRefine :class:`~discretize.TreeMesh` with user-defined function.\n\n        Refines the :class:`~discretize.TreeMesh` according to a user-defined function.\n        The function is recursively called on each cell of the mesh. The user-defined\n        function **must** accept an object of type :class:`~discretize.tree_mesh.TreeCell`\n        and **must** return an integer-like object denoting the desired refinement\n        level. Instead of a function, the user may also supply an integer defining\n        the minimum refinement level for all cells.\n\n        Parameters\n        ----------\n        function : callable or int\n            a function defining the desired refinement level,\n            or an integer to refine all cells to at least that level.\n            The input argument of the function **must** be an instance of\n            :class:`~discretize.tree_mesh.TreeCell`.\n        finalize : bool, optional\n            whether to finalize the mesh\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        Here, we define a QuadTree mesh with a domain width of 1 along\n        the x and y axes. We then refine the mesh to its maximum level\n        at locations within a distance of 0.2 of point (0.5, 0.5). The\n        function accepts and instance of :class:`~discretize.tree_mesh.TreeCell`\n        and returns an integer value denoting its level of refinement.\n\n        >>> from discretize import TreeMesh\n        >>> from matplotlib import pyplot\n\n        Define a mesh and refine it radially outward using the custom defined function\n\n\n        >>> mesh = TreeMesh([32,32])\n        >>> def func(cell):\n        ...     r = np.linalg.norm(cell.center-0.5)\n        ...     return mesh.max_leve""l if r<0.2 else mesh.max_level-2\n        >>> mesh.refine(func)\n\n        >>> mesh.plot_grid()\n        >>> pyplot.show()\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7refine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_function = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_function,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_None);
    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_function)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine") < 0)) __PYX_ERR(0, 448, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_function = values[0];
    __pyx_v_finalize = values[1];
    __pyx_v_diagonal_balance = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 448, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_function, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

/* "discretize/_extensions/tree_ext.pyx":497
 *         if isinstance(function, int):
 *             level = function
 *             function = lambda cell: level             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine_lambda(PyObject *__pyx_self, PyObject *__pyx_v_cell); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine_lambda = {"lambda", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine_lambda, METH_O, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine_lambda(PyObject *__pyx_self, PyObject *__pyx_v_cell) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lambda (wrapper)", 0);
  __pyx_r = __pyx_lambda_funcdef_lambda(__pyx_self, ((PyObject *)__pyx_v_cell));

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

static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_cell) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *__pyx_cur_scope;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("lambda", 0);
  __pyx_outer_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_TraceCall("lambda", __pyx_f[0], 497, 0, __PYX_ERR(0, 497, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_level)) { __Pyx_RaiseClosureNameError("level"); __PYX_ERR(0, 497, __pyx_L1_error) }
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_level);
  __pyx_r = __pyx_cur_scope->__pyx_v_level;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine.lambda", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":448
 *         self.__ubc_indArr = None
 * 
 *     def refine(self, function, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` with user-defined function.
 * 
 */

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_function, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *__pyx_cur_scope;
  bool __pyx_v_diag_balance;
  void *__pyx_v_func_ptr;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  bool __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine", 0);
  __pyx_cur_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 448, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __Pyx_TraceCall("refine", __pyx_f[0], 448, 0, __PYX_ERR(0, 448, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_function);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":495
 * 
 *         """
 *         if isinstance(function, int):             # <<<<<<<<<<<<<<
 *             level = function
 *             function = lambda cell: level
 */
  __Pyx_TraceLine(495,0,__PYX_ERR(0, 495, __pyx_L1_error))
  __pyx_t_1 = PyInt_Check(__pyx_v_function); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":496
 *         """
 *         if isinstance(function, int):
 *             level = function             # <<<<<<<<<<<<<<
 *             function = lambda cell: level
 * 
 */
    __Pyx_TraceLine(496,0,__PYX_ERR(0, 496, __pyx_L1_error))
    __Pyx_INCREF(__pyx_v_function);
    __Pyx_GIVEREF(__pyx_v_function);
    __pyx_cur_scope->__pyx_v_level = __pyx_v_function;

    /* "discretize/_extensions/tree_ext.pyx":497
 *         if isinstance(function, int):
 *             level = function
 *             function = lambda cell: level             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
    __Pyx_TraceLine(497,0,__PYX_ERR(0, 497, __pyx_L1_error))
    __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine_lambda, 0, __pyx_n_s_refine_locals_lambda, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_function, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":495
 * 
 *         """
 *         if isinstance(function, int):             # <<<<<<<<<<<<<<
 *             level = function
 *             function = lambda cell: level
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":499
 *             function = lambda cell: level
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(499,0,__PYX_ERR(0, 499, __pyx_L1_error))
  __pyx_t_2 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":500
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(500,0,__PYX_ERR(0, 500, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":499
 *             function = lambda cell: level
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":501
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         #Wrapping function so it can be called in c++
 */
  __Pyx_TraceLine(501,0,__PYX_ERR(0, 501, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_4 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 501, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_4;

  /* "discretize/_extensions/tree_ext.pyx":504
 * 
 *         #Wrapping function so it can be called in c++
 *         cdef void * func_ptr = <void *> function             # <<<<<<<<<<<<<<
 *         self.wrapper.set(func_ptr, _evaluate_func)
 *         #Then tell c++ to build the tree
 */
  __Pyx_TraceLine(504,0,__PYX_ERR(0, 504, __pyx_L1_error))
  __pyx_v_func_ptr = ((void *)__pyx_v_function);

  /* "discretize/_extensions/tree_ext.pyx":505
 *         #Wrapping function so it can be called in c++
 *         cdef void * func_ptr = <void *> function
 *         self.wrapper.set(func_ptr, _evaluate_func)             # <<<<<<<<<<<<<<
 *         #Then tell c++ to build the tree
 *         self.tree.refine_function(self.wrapper, diag_balance)
 */
  __Pyx_TraceLine(505,0,__PYX_ERR(0, 505, __pyx_L1_error))
  __pyx_v_self->wrapper->set(__pyx_v_func_ptr, __pyx_f_10discretize_11_extensions_8tree_ext__evaluate_func);

  /* "discretize/_extensions/tree_ext.pyx":507
 *         self.wrapper.set(func_ptr, _evaluate_func)
 *         #Then tell c++ to build the tree
 *         self.tree.refine_function(self.wrapper, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
  __Pyx_TraceLine(507,0,__PYX_ERR(0, 507, __pyx_L1_error))
  __pyx_v_self->tree->refine_function(__pyx_v_self->wrapper, __pyx_v_diag_balance);

  /* "discretize/_extensions/tree_ext.pyx":508
 *         #Then tell c++ to build the tree
 *         self.tree.refine_function(self.wrapper, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(508,0,__PYX_ERR(0, 508, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 508, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":509
 *         self.tree.refine_function(self.wrapper, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(509,0,__PYX_ERR(0, 509, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 509, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":508
 *         #Then tell c++ to build the tree
 *         self.tree.refine_function(self.wrapper, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":448
 *         self.__ubc_indArr = None
 * 
 *     def refine(self, function, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` with user-defined function.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_function);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":512
 * 
 *     @cython.cdivision(True)
 *     def refine_ball(self, points, radii, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` using radial distance (ball) and refinement level for a cluster of points.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9refine_ball(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_8refine_ball[] = "_TreeMesh.refine_ball(self, points, radii, levels, finalize=True, diagonal_balance=None)\nRefine :class:`~discretize.TreeMesh` using radial distance (ball) and refinement level for a cluster of points.\n\n        For each point in the array `points`, this method refines the tree mesh\n        based on the radial distance (ball) and refinement level supplied. The method\n        accomplishes this by determining which cells intersect ball(s) and refining them\n        to the prescribed level(s) of refinement.\n\n        Parameters\n        ----------\n        points : (N, dim) array_like\n            The centers of the refinement balls\n        radii : float or (N) array_like of float\n            A 1D array defining the radius for each ball\n        levels : int or (N) array_like of int\n            A 1D array defining the maximum refinement level for each ball\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the tree mesh such that all cells that\n        intersect the spherical balls are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the center and radius of the two spheres, as well as the level\n        we want to refine them to, and refine the mesh.\n\n        >>> centers = [[0.1, 0.3], [0.6, 0.8]]\n        >>> radii = [0.2, 0.3]\n        >>> levels = [4, 5]\n        >>> tree_mesh.refine_ball(centers, radii, levels)\n\n        Now lets look at the mesh, and overlay the balls on it to ensure it refined\n        where we wanted"" it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> circ = patches.Circle(centers[0], radii[0], facecolor='none', edgecolor='r', linewidth=3)\n        >>> ax.add_patch(circ)\n        >>> circ = patches.Circle(centers[1], radii[1], facecolor='none', edgecolor='k', linewidth=3)\n        >>> ax.add_patch(circ)\n        >>> plt.show()\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9refine_ball(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_points = 0;
  PyObject *__pyx_v_radii = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_ball (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_points,&__pyx_n_s_radii,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_points)) != 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_radii)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_ball", 0, 3, 5, 1); __PYX_ERR(0, 512, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_ball", 0, 3, 5, 2); __PYX_ERR(0, 512, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_ball") < 0)) __PYX_ERR(0, 512, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_points = values[0];
    __pyx_v_radii = values[1];
    __pyx_v_levels = values[2];
    __pyx_v_finalize = values[3];
    __pyx_v_diagonal_balance = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_ball", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 512, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_ball", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8refine_ball(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_points, __pyx_v_radii, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_8refine_ball(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_points, PyObject *__pyx_v_radii, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_cs = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_rs = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int_t __pyx_v_i;
  int __pyx_v_l;
  int __pyx_v_max_level;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_UCS4 __pyx_t_8;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_11 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_12;
  bool __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  int_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_ball", 0);
  __Pyx_TraceCall("refine_ball", __pyx_f[0], 512, 0, __PYX_ERR(0, 512, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_points);
  __Pyx_INCREF(__pyx_v_radii);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":564
 *         >>> plt.show()
 *         """
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                             requirements='C')
 *         if points.shape[1] != self.dim:
 */
  __Pyx_TraceLine(564,0,__PYX_ERR(0, 564, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_points) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_points);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 564, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_points, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":566
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,
 *                             requirements='C')
 *         if points.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 */
  __Pyx_TraceLine(566,0,__PYX_ERR(0, 566, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":567
 *                             requirements='C')
 *         if points.shape[1] != self.dim:
 *             raise ValueError(f"points array must be (N, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :] cs = points
 *         radii = np.require(np.atleast_1d(radii), dtype=np.float64,
 */
    __Pyx_TraceLine(567,0,__PYX_ERR(0, 567, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_points_array_must_be_N);
    __pyx_t_7 += 25;
    __Pyx_GIVEREF(__pyx_kp_u_points_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_points_array_must_be_N);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_7 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__11);
    __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 567, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":566
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,
 *                             requirements='C')
 *         if points.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":568
 *         if points.shape[1] != self.dim:
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points             # <<<<<<<<<<<<<<
 *         radii = np.require(np.atleast_1d(radii), dtype=np.float64,
 *                                        requirements='C')
 */
  __Pyx_TraceLine(568,0,__PYX_ERR(0, 568, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_points, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 568, __pyx_L1_error)
  __pyx_v_cs = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":569
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 *         radii = np.require(np.atleast_1d(radii), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                                        requirements='C')
 *         if radii.shape[0] == 1:
 */
  __Pyx_TraceLine(569,0,__PYX_ERR(0, 569, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_radii) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_radii);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 569, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_radii, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":571
 *         radii = np.require(np.atleast_1d(radii), dtype=np.float64,
 *                                        requirements='C')
 *         if radii.shape[0] == 1:             # <<<<<<<<<<<<<<
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)
 *         cdef double[:] rs = radii
 */
  __Pyx_TraceLine(571,0,__PYX_ERR(0, 571, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_radii, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":572
 *                                        requirements='C')
 *         if radii.shape[0] == 1:
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef double[:] rs = radii
 *         if points.shape[0] != rs.shape[0]:
 */
    __Pyx_TraceLine(572,0,__PYX_ERR(0, 572, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_full); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_radii, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_radii, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":571
 *         radii = np.require(np.atleast_1d(radii), dtype=np.float64,
 *                                        requirements='C')
 *         if radii.shape[0] == 1:             # <<<<<<<<<<<<<<
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)
 *         cdef double[:] rs = radii
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":573
 *         if radii.shape[0] == 1:
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)
 *         cdef double[:] rs = radii             # <<<<<<<<<<<<<<
 *         if points.shape[0] != rs.shape[0]:
 *             raise ValueError("radii length must match the points array's first dimension")
 */
  __Pyx_TraceLine(573,0,__PYX_ERR(0, 573, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_radii, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 573, __pyx_L1_error)
  __pyx_v_rs = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":574
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)
 *         cdef double[:] rs = radii
 *         if points.shape[0] != rs.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("radii length must match the points array's first dimension")
 * 
 */
  __Pyx_TraceLine(574,0,__PYX_ERR(0, 574, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_rs.shape[0])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 574, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":575
 *         cdef double[:] rs = radii
 *         if points.shape[0] != rs.shape[0]:
 *             raise ValueError("radii length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
    __Pyx_TraceLine(575,0,__PYX_ERR(0, 575, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 575, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":574
 *            radii = np.full(points.shape[0], radii[0], dtype=np.float64)
 *         cdef double[:] rs = radii
 *         if points.shape[0] != rs.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("radii length must match the points array's first dimension")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":577
 *             raise ValueError("radii length must match the points array's first dimension")
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         if levels.shape[0] == 1:
 */
  __Pyx_TraceLine(577,0,__PYX_ERR(0, 577, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 577, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":579
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 */
  __Pyx_TraceLine(579,0,__PYX_ERR(0, 579, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":580
 *                                     requirements='C')
 *         if levels.shape[0] == 1:
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         cdef int[:] ls = levels
 *         if points.shape[0] != ls.shape[0]:
 */
    __Pyx_TraceLine(580,0,__PYX_ERR(0, 580, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_full); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":579
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":581
 *         if levels.shape[0] == 1:
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 *         if points.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")
 */
  __Pyx_TraceLine(581,0,__PYX_ERR(0, 581, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 581, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_11;
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":582
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 *         if points.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 */
  __Pyx_TraceLine(582,0,__PYX_ERR(0, 582, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_ls.shape[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":583
 *         cdef int[:] ls = levels
 *         if points.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
    __Pyx_TraceLine(583,0,__PYX_ERR(0, 583, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 583, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 583, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":582
 *             levels = np.full(points.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 *         if points.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":585
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(585,0,__PYX_ERR(0, 585, __pyx_L1_error))
  __pyx_t_6 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_12 = (__pyx_t_6 != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":586
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(586,0,__PYX_ERR(0, 586, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":585
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":587
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t i
 */
  __Pyx_TraceLine(587,0,__PYX_ERR(0, 587, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_13 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 587, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":591
 *         cdef int_t i
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 */
  __Pyx_TraceLine(591,0,__PYX_ERR(0, 591, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_max_level = __pyx_t_14;

  /* "discretize/_extensions/tree_ext.pyx":592
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(ls.shape[0]):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(592,0,__PYX_ERR(0, 592, __pyx_L1_error))
  __pyx_t_7 = (__pyx_v_ls.shape[0]);
  __pyx_t_15 = __pyx_t_7;
  for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
    __pyx_v_i = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":593
 *         cdef int max_level = self.max_level
 *         for i in range(ls.shape[0]):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(593,0,__PYX_ERR(0, 593, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_14 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_ls.shape[0])) __pyx_t_14 = 0;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 593, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_17 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":594
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 */
    __Pyx_TraceLine(594,0,__PYX_ERR(0, 594, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":595
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(595,0,__PYX_ERR(0, 595, __pyx_L1_error))
      __pyx_t_14 = abs(__pyx_v_l); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 595, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_14 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":594
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":596
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(596,0,__PYX_ERR(0, 596, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_18 = 0;
    __pyx_t_14 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_cs.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_cs.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_18 < 0) {
      __pyx_t_18 += __pyx_v_cs.shape[1];
      if (unlikely(__pyx_t_18 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_18 >= __pyx_v_cs.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 596, __pyx_L1_error)
    }
    __pyx_t_19 = __pyx_v_i;
    __pyx_t_14 = -1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_rs.shape[0];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_rs.shape[0])) __pyx_t_14 = 0;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 596, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_ball((&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_cs.data + __pyx_t_17 * __pyx_v_cs.strides[0]) ) + __pyx_t_18 * __pyx_v_cs.strides[1]) )))), (*((double *) ( /* dim=0 */ (__pyx_v_rs.data + __pyx_t_19 * __pyx_v_rs.strides[0]) ))), __pyx_v_l, __pyx_v_diag_balance);
  }

  /* "discretize/_extensions/tree_ext.pyx":597
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(597,0,__PYX_ERR(0, 597, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 597, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":598
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(598,0,__PYX_ERR(0, 598, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(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_5 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":597
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_ball(&cs[i, 0], rs[i], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":512
 * 
 *     @cython.cdivision(True)
 *     def refine_ball(self, points, radii, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine :class:`~discretize.TreeMesh` using radial distance (ball) and refinement level for a cluster of points.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_ball", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_cs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_rs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_points);
  __Pyx_XDECREF(__pyx_v_radii);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":601
 * 
 *     @cython.cdivision(True)
 *     def refine_box(self, x0s, x1s, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` within the axis aligned boxes to the desired level.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11refine_box(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_10refine_box[] = "_TreeMesh.refine_box(self, x0s, x1s, levels, finalize=True, diagonal_balance=None)\nRefine the :class:`~discretize.TreeMesh` within the axis aligned boxes to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given axis aligned\n        box(es) to the prescribed level(s).\n\n        Parameters\n        ----------\n        x0s : (N, dim) array_like\n            The minimum location of the boxes\n        x1s : (N, dim) array_like\n            The maximum location of the boxes\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : None or bool, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the boxes are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the origins and furthest corners of the two rectangles, as\n        well as the level we want to refine them to, and refine the mesh.\n\n        >>> x0s = [[0.1, 0.1], [0.8, 0.8]]\n        >>> x1s = [[0.3, 0.2], [0.9, 1.0]]\n        >>> levels = [4, 5]\n        >>> tree_mesh.refine_box(x0s, x1s, levels)\n\n        Now lets look at the mesh, and overlay the boxes on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> rect = patches.Rectangle([0.1, 0.1], 0.2, 0.1, facecolor='none', edgecolor='r', linewidth=3)\n        >>> ax.add_patch(rect)\n        >>> rect = patches.Rectangle([0.8, 0.8], 0.1, 0.2, ""facecolor='none', edgecolor='k', linewidth=3)\n        >>> ax.add_patch(rect)\n        >>> plt.show()\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11refine_box(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_x0s = 0;
  PyObject *__pyx_v_x1s = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_box (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x0s,&__pyx_n_s_x1s,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x0s)) != 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_x1s)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_box", 0, 3, 5, 1); __PYX_ERR(0, 601, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_box", 0, 3, 5, 2); __PYX_ERR(0, 601, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_box") < 0)) __PYX_ERR(0, 601, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_x0s = values[0];
    __pyx_v_x1s = values[1];
    __pyx_v_levels = values[2];
    __pyx_v_finalize = values[3];
    __pyx_v_diagonal_balance = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_box", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 601, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_box", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10refine_box(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_x0s, __pyx_v_x1s, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10refine_box(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_x0s, PyObject *__pyx_v_x1s, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_x0 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_x1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int __pyx_v_l;
  int __pyx_v_max_level;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_UCS4 __pyx_t_8;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  bool __pyx_t_12;
  int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_box", 0);
  __Pyx_TraceCall("refine_box", __pyx_f[0], 601, 0, __PYX_ERR(0, 601, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_x0s);
  __Pyx_INCREF(__pyx_v_x1s);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":651
 *         >>> plt.show()
 *         """
 *         x0s = np.require(np.atleast_2d(x0s), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                             requirements='C')
 *         if x0s.shape[1] != self.dim:
 */
  __Pyx_TraceLine(651,0,__PYX_ERR(0, 651, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_x0s) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_x0s);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 651, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_x0s, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":653
 *         x0s = np.require(np.atleast_2d(x0s), dtype=np.float64,
 *                             requirements='C')
 *         if x0s.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x0s array must be (N, {self.dim})")
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,
 */
  __Pyx_TraceLine(653,0,__PYX_ERR(0, 653, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_x0s, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":654
 *                             requirements='C')
 *         if x0s.shape[1] != self.dim:
 *             raise ValueError(f"x0s array must be (N, {self.dim})")             # <<<<<<<<<<<<<<
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,
 *                             requirements='C')
 */
    __Pyx_TraceLine(654,0,__PYX_ERR(0, 654, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_x0s_array_must_be_N);
    __pyx_t_7 += 22;
    __Pyx_GIVEREF(__pyx_kp_u_x0s_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_x0s_array_must_be_N);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_7 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__11);
    __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 654, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":653
 *         x0s = np.require(np.atleast_2d(x0s), dtype=np.float64,
 *                             requirements='C')
 *         if x0s.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x0s array must be (N, {self.dim})")
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":655
 *         if x0s.shape[1] != self.dim:
 *             raise ValueError(f"x0s array must be (N, {self.dim})")
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                             requirements='C')
 *         if x1s.shape[1] != self.dim:
 */
  __Pyx_TraceLine(655,0,__PYX_ERR(0, 655, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_x1s) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_x1s);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 655, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_x1s, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":657
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,
 *                             requirements='C')
 *         if x1s.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:
 */
  __Pyx_TraceLine(657,0,__PYX_ERR(0, 657, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_x1s, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":658
 *                             requirements='C')
 *         if x1s.shape[1] != self.dim:
 *             raise ValueError(f"x1s array must be (N, {self.dim})")             # <<<<<<<<<<<<<<
 *         if x1s.shape[0] != x0s.shape[0]:
 *             raise ValueError(f"x0s and x1s must have the same length")
 */
    __Pyx_TraceLine(658,0,__PYX_ERR(0, 658, __pyx_L1_error))
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_x1s_array_must_be_N);
    __pyx_t_7 += 22;
    __Pyx_GIVEREF(__pyx_kp_u_x1s_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_x1s_array_must_be_N);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_7 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u__11);
    __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 658, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":657
 *         x1s = np.require(np.atleast_2d(x1s), dtype=np.float64,
 *                             requirements='C')
 *         if x1s.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":659
 *         if x1s.shape[1] != self.dim:
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x0s and x1s must have the same length")
 *         cdef double[:, :] x0 = x0s
 */
  __Pyx_TraceLine(659,0,__PYX_ERR(0, 659, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_x1s, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_x0s, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":660
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:
 *             raise ValueError(f"x0s and x1s must have the same length")             # <<<<<<<<<<<<<<
 *         cdef double[:, :] x0 = x0s
 *         cdef double[:, :] x1 = x1s
 */
    __Pyx_TraceLine(660,0,__PYX_ERR(0, 660, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 660, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 660, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":659
 *         if x1s.shape[1] != self.dim:
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"x0s and x1s must have the same length")
 *         cdef double[:, :] x0 = x0s
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":661
 *         if x1s.shape[0] != x0s.shape[0]:
 *             raise ValueError(f"x0s and x1s must have the same length")
 *         cdef double[:, :] x0 = x0s             # <<<<<<<<<<<<<<
 *         cdef double[:, :] x1 = x1s
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
  __Pyx_TraceLine(661,0,__PYX_ERR(0, 661, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_x0s, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 661, __pyx_L1_error)
  __pyx_v_x0 = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":662
 *             raise ValueError(f"x0s and x1s must have the same length")
 *         cdef double[:, :] x0 = x0s
 *         cdef double[:, :] x1 = x1s             # <<<<<<<<<<<<<<
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 */
  __Pyx_TraceLine(662,0,__PYX_ERR(0, 662, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_x1s, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 662, __pyx_L1_error)
  __pyx_v_x1 = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":663
 *         cdef double[:, :] x0 = x0s
 *         cdef double[:, :] x1 = x1s
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         if levels.shape[0] == 1:
 */
  __Pyx_TraceLine(663,0,__PYX_ERR(0, 663, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_require); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 663, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 663, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":665
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 */
  __Pyx_TraceLine(665,0,__PYX_ERR(0, 665, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 665, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":666
 *                                     requirements='C')
 *         if levels.shape[0] == 1:
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         cdef int[:] ls = levels
 *         if x0.shape[0] != ls.shape[0]:
 */
    __Pyx_TraceLine(666,0,__PYX_ERR(0, 666, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_full); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_x0.shape[0])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":665
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":667
 *         if levels.shape[0] == 1:
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 *         if x0.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")
 */
  __Pyx_TraceLine(667,0,__PYX_ERR(0, 667, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 667, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":668
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 *         if x0.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 */
  __Pyx_TraceLine(668,0,__PYX_ERR(0, 668, __pyx_L1_error))
  __pyx_t_6 = (((__pyx_v_x0.shape[0]) != (__pyx_v_ls.shape[0])) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":669
 *         cdef int[:] ls = levels
 *         if x0.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
    __Pyx_TraceLine(669,0,__PYX_ERR(0, 669, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 669, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 669, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":668
 *             levels = np.full(x0.shape[0], levels[0], dtype=np.int32)
 *         cdef int[:] ls = levels
 *         if x0.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":671
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(671,0,__PYX_ERR(0, 671, __pyx_L1_error))
  __pyx_t_6 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_11 = (__pyx_t_6 != 0);
  if (__pyx_t_11) {

    /* "discretize/_extensions/tree_ext.pyx":672
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(672,0,__PYX_ERR(0, 672, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":671
 *             raise ValueError("level length must match the points array's first dimension")
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":673
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int l
 */
  __Pyx_TraceLine(673,0,__PYX_ERR(0, 673, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_12 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 673, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":676
 * 
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 */
  __Pyx_TraceLine(676,0,__PYX_ERR(0, 676, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 676, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_max_level = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":677
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(ls.shape[0]):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(677,0,__PYX_ERR(0, 677, __pyx_L1_error))
  __pyx_t_7 = (__pyx_v_ls.shape[0]);
  __pyx_t_14 = __pyx_t_7;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":678
 *         cdef int max_level = self.max_level
 *         for i in range(ls.shape[0]):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(678,0,__PYX_ERR(0, 678, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_13 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_ls.shape[0])) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 678, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_16 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":679
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 */
    __Pyx_TraceLine(679,0,__PYX_ERR(0, 679, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_11) {

      /* "discretize/_extensions/tree_ext.pyx":680
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(680,0,__PYX_ERR(0, 680, __pyx_L1_error))
      __pyx_t_13 = abs(__pyx_v_l); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(0, 680, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_13 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":679
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":681
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(681,0,__PYX_ERR(0, 681, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_x0.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_x0.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_x0.shape[1];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_x0.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 681, __pyx_L1_error)
    }
    __pyx_t_18 = __pyx_v_i;
    __pyx_t_19 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_18 < 0) {
      __pyx_t_18 += __pyx_v_x1.shape[0];
      if (unlikely(__pyx_t_18 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_18 >= __pyx_v_x1.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_x1.shape[1];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_x1.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 681, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_box((&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_x0.data + __pyx_t_16 * __pyx_v_x0.strides[0]) ) + __pyx_t_17 * __pyx_v_x0.strides[1]) )))), (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_x1.data + __pyx_t_18 * __pyx_v_x1.strides[0]) ) + __pyx_t_19 * __pyx_v_x1.strides[1]) )))), __pyx_v_l, __pyx_v_diag_balance);
  }

  /* "discretize/_extensions/tree_ext.pyx":682
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(682,0,__PYX_ERR(0, 682, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 682, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "discretize/_extensions/tree_ext.pyx":683
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(683,0,__PYX_ERR(0, 683, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":682
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_box(&x0[i, 0], &x1[i, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":601
 * 
 *     @cython.cdivision(True)
 *     def refine_box(self, x0s, x1s, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` within the axis aligned boxes to the desired level.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_box", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_x0, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_x1, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_x0s);
  __Pyx_XDECREF(__pyx_v_x1s);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":686
 * 
 *     @cython.cdivision(True)
 *     def refine_line(self, path, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the line segment to the desired level.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13refine_line(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_12refine_line[] = "_TreeMesh.refine_line(self, path, levels, finalize=True, diagonal_balance=None)\nRefine the :class:`~discretize.TreeMesh` along the line segment to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given line segment(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        path : (N+1, dim) array_like\n            The nodes of the line segment(s).\n            i.e. `[[x0, y0, z0], [x1, y1, z1], [x2, y2, z2]]` would be two segments.\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> segments = np.array([[0.1, 0.3], [0.3, 0.9], [0.8, 0.9]])\n        >>> levels = 5\n        >>> tree_mesh.refine_line(segments, levels)\n\n        Now lets look at the mesh, and overlay the line on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> ax.plot(*segments.T, color='C1')\n        >>> plt.show()\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13refine_line(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_path = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_line (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_path,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_path)) != 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_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_line", 0, 2, 4, 1); __PYX_ERR(0, 686, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_line") < 0)) __PYX_ERR(0, 686, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_path = values[0];
    __pyx_v_levels = values[1];
    __pyx_v_finalize = values[2];
    __pyx_v_diagonal_balance = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_line", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 686, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12refine_line(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_path, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12refine_line(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_path, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_line_nodes = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_n_segments;
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int __pyx_v_l;
  int __pyx_v_max_level;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_UCS4 __pyx_t_8;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  bool __pyx_t_12;
  int __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_line", 0);
  __Pyx_TraceCall("refine_line", __pyx_f[0], 686, 0, __PYX_ERR(0, 686, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_path);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":732
 * 
 *         """
 *         path = np.require(np.atleast_2d(path), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                             requirements='C')
 *         if path.shape[1] != self.dim:
 */
  __Pyx_TraceLine(732,0,__PYX_ERR(0, 732, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_path) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_path);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 732, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_path, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":734
 *         path = np.require(np.atleast_2d(path), dtype=np.float64,
 *                             requirements='C')
 *         if path.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"line_nodes array must be (N, {self.dim})")
 *         cdef double[:, :] line_nodes = path
 */
  __Pyx_TraceLine(734,0,__PYX_ERR(0, 734, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_path, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 734, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":735
 *                             requirements='C')
 *         if path.shape[1] != self.dim:
 *             raise ValueError(f"line_nodes array must be (N, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :] line_nodes = path
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
    __Pyx_TraceLine(735,0,__PYX_ERR(0, 735, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_line_nodes_array_must_be_N);
    __pyx_t_7 += 29;
    __Pyx_GIVEREF(__pyx_kp_u_line_nodes_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_line_nodes_array_must_be_N);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_7 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__11);
    __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 735, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":734
 *         path = np.require(np.atleast_2d(path), dtype=np.float64,
 *                             requirements='C')
 *         if path.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"line_nodes array must be (N, {self.dim})")
 *         cdef double[:, :] line_nodes = path
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":736
 *         if path.shape[1] != self.dim:
 *             raise ValueError(f"line_nodes array must be (N, {self.dim})")
 *         cdef double[:, :] line_nodes = path             # <<<<<<<<<<<<<<
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 */
  __Pyx_TraceLine(736,0,__PYX_ERR(0, 736, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_path, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 736, __pyx_L1_error)
  __pyx_v_line_nodes = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":737
 *             raise ValueError(f"line_nodes array must be (N, {self.dim})")
 *         cdef double[:, :] line_nodes = path
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         cdef int n_segments = line_nodes.shape[0] - 1;
 */
  __Pyx_TraceLine(737,0,__PYX_ERR(0, 737, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 737, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":739
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         cdef int n_segments = line_nodes.shape[0] - 1;             # <<<<<<<<<<<<<<
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 */
  __Pyx_TraceLine(739,0,__PYX_ERR(0, 739, __pyx_L1_error))
  __pyx_v_n_segments = ((__pyx_v_line_nodes.shape[0]) - 1);

  /* "discretize/_extensions/tree_ext.pyx":740
 *                                     requirements='C')
 *         cdef int n_segments = line_nodes.shape[0] - 1;
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 *         if n_segments != levels.shape[0]:
 */
  __Pyx_TraceLine(740,0,__PYX_ERR(0, 740, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 740, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":741
 *         cdef int n_segments = line_nodes.shape[0] - 1;
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         if n_segments != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of line segments {n_segments} and levels {levels.shape[0]}")
 */
    __Pyx_TraceLine(741,0,__PYX_ERR(0, 741, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_full); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_segments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":740
 *                                     requirements='C')
 *         cdef int n_segments = line_nodes.shape[0] - 1;
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 *         if n_segments != levels.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":742
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 *         if n_segments != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of line segments {n_segments} and levels {levels.shape[0]}")
 * 
 */
  __Pyx_TraceLine(742,0,__PYX_ERR(0, 742, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_n_segments); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":743
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 *         if n_segments != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of line segments {n_segments} and levels {levels.shape[0]}")             # <<<<<<<<<<<<<<
 * 
 *         cdef int[:] ls = levels
 */
    __Pyx_TraceLine(743,0,__PYX_ERR(0, 743, __pyx_L1_error))
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_inconsistent_number_of_line_segm);
    __pyx_t_7 += 37;
    __Pyx_GIVEREF(__pyx_kp_u_inconsistent_number_of_line_segm);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_inconsistent_number_of_line_segm);
    __pyx_t_1 = __Pyx_PyUnicode_From_int(__pyx_v_n_segments, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u_and_levels);
    __pyx_t_7 += 12;
    __Pyx_GIVEREF(__pyx_kp_u_and_levels);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_and_levels);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 743, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":742
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_segments, levels[0], dtype=np.int32)
 *         if n_segments != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of line segments {n_segments} and levels {levels.shape[0]}")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":745
 *             raise ValueError(f"inconsistent number of line segments {n_segments} and levels {levels.shape[0]}")
 * 
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
  __Pyx_TraceLine(745,0,__PYX_ERR(0, 745, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 745, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":747
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(747,0,__PYX_ERR(0, 747, __pyx_L1_error))
  __pyx_t_6 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_11 = (__pyx_t_6 != 0);
  if (__pyx_t_11) {

    /* "discretize/_extensions/tree_ext.pyx":748
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(748,0,__PYX_ERR(0, 748, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":747
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":749
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int l
 */
  __Pyx_TraceLine(749,0,__PYX_ERR(0, 749, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_12 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 749, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":752
 * 
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(n_segments):
 *             l = ls[i]
 */
  __Pyx_TraceLine(752,0,__PYX_ERR(0, 752, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_max_level = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":753
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(n_segments):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(753,0,__PYX_ERR(0, 753, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_segments); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
    __pyx_t_14 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_14 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 753, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_14)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 753, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 753, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 753, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 753, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_14(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 753, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":754
 *         cdef int max_level = self.max_level
 *         for i in range(n_segments):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(754,0,__PYX_ERR(0, 754, __pyx_L1_error))
    __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 754, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_15;
    __pyx_t_13 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_ls.shape[0])) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 754, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_16 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":755
 *         for i in range(n_segments):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 */
    __Pyx_TraceLine(755,0,__PYX_ERR(0, 755, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_11) {

      /* "discretize/_extensions/tree_ext.pyx":756
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(756,0,__PYX_ERR(0, 756, __pyx_L1_error))
      __pyx_t_13 = abs(__pyx_v_l); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(0, 756, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_13 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":755
 *         for i in range(n_segments):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":757
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(757,0,__PYX_ERR(0, 757, __pyx_L1_error))
    __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 757, __pyx_L1_error)
    __pyx_t_16 = __pyx_t_15;
    __pyx_t_17 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_line_nodes.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_line_nodes.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_line_nodes.shape[1];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_line_nodes.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 757, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 757, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_18 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_18 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 757, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_19 = __pyx_t_18;
    __pyx_t_20 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_line_nodes.shape[0];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_line_nodes.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_20 < 0) {
      __pyx_t_20 += __pyx_v_line_nodes.shape[1];
      if (unlikely(__pyx_t_20 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_20 >= __pyx_v_line_nodes.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 757, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_line((&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_line_nodes.data + __pyx_t_16 * __pyx_v_line_nodes.strides[0]) ) + __pyx_t_17 * __pyx_v_line_nodes.strides[1]) )))), (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_line_nodes.data + __pyx_t_19 * __pyx_v_line_nodes.strides[0]) ) + __pyx_t_20 * __pyx_v_line_nodes.strides[1]) )))), __pyx_v_l, __pyx_v_diag_balance);

    /* "discretize/_extensions/tree_ext.pyx":753
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(n_segments):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
    __Pyx_TraceLine(753,0,__PYX_ERR(0, 753, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":758
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(758,0,__PYX_ERR(0, 758, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 758, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "discretize/_extensions/tree_ext.pyx":759
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(759,0,__PYX_ERR(0, 759, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":758
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_line(&line_nodes[i, 0], &line_nodes[i+1, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":686
 * 
 *     @cython.cdivision(True)
 *     def refine_line(self, path, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the line segment to the desired level.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_line_nodes, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_path);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":762
 * 
 *     @cython.cdivision(True)
 *     def refine_triangle(self, triangle, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the triangle to the desired level.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15refine_triangle(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_14refine_triangle[] = "_TreeMesh.refine_triangle(self, triangle, levels, finalize=True, diagonal_balance=None)\nRefine the :class:`~discretize.TreeMesh` along the triangle to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given triangle(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        triangle : (N, 3, dim) array_like\n            The nodes of the triangle(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> triangle = [[0.14, 0.31], [0.32, 0.96], [0.23, 0.87]]\n        >>> levels = 5\n        >>> tree_mesh.refine_triangle(triangle, levels)\n\n        Now lets look at the mesh, and overlay the line on it to ensure it refined\n        where we wanted it to.\n\n        >>> ax = tree_mesh.plot_grid()\n        >>> tri = patches.Polygon(triangle, fill=False)\n        >>> ax.add_patch(tri)\n        >>> plt.show()\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15refine_triangle(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_triangle = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_triangle (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangle,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_triangle)) != 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_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_triangle", 0, 2, 4, 1); __PYX_ERR(0, 762, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_triangle") < 0)) __PYX_ERR(0, 762, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_triangle = values[0];
    __pyx_v_levels = values[1];
    __pyx_v_finalize = values[2];
    __pyx_v_diagonal_balance = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_triangle", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 762, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_triangle", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14refine_triangle(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_triangle, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14refine_triangle(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_triangle, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_tris = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_n_triangles;
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int __pyx_v_l;
  int __pyx_v_max_level;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  Py_UCS4 __pyx_t_9;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  __Pyx_memviewslice __pyx_t_12 = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_triangle", 0);
  __Pyx_TraceCall("refine_triangle", __pyx_f[0], 762, 0, __PYX_ERR(0, 762, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_triangle);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":808
 * 
 *         """
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")             # <<<<<<<<<<<<<<
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 */
  __Pyx_TraceLine(808,0,__PYX_ERR(0, 808, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_triangle) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_triangle);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 808, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_triangle, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":809
 *         """
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:             # <<<<<<<<<<<<<<
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 */
  __Pyx_TraceLine(809,0,__PYX_ERR(0, 809, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_ndim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 809, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":810
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]             # <<<<<<<<<<<<<<
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 */
    __Pyx_TraceLine(810,0,__PYX_ERR(0, 810, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_triangle, __pyx_tuple__15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 810, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_triangle, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":809
 *         """
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:             # <<<<<<<<<<<<<<
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":811
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle
 */
  __Pyx_TraceLine(811,0,__PYX_ERR(0, 811, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_6 = __pyx_t_7;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_1, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __pyx_t_7;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":812
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :, :] tris = triangle
 * 
 */
    __Pyx_TraceLine(812,0,__PYX_ERR(0, 812, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_triangle_array_must_be_N_3);
    __pyx_t_8 += 30;
    __Pyx_GIVEREF(__pyx_kp_u_triangle_array_must_be_N_3);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_triangle_array_must_be_N_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_8 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__11);
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 812, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 812, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":811
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":813
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle             # <<<<<<<<<<<<<<
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
  __Pyx_TraceLine(813,0,__PYX_ERR(0, 813, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(__pyx_v_triangle, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 813, __pyx_L1_error)
  __pyx_v_tris = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":815
 *         cdef double[:, :, :] tris = triangle
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 */
  __Pyx_TraceLine(815,0,__PYX_ERR(0, 815, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 815, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":817
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];             # <<<<<<<<<<<<<<
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 */
  __Pyx_TraceLine(817,0,__PYX_ERR(0, 817, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 817, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 817, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 817, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_n_triangles = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":818
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 */
  __Pyx_TraceLine(818,0,__PYX_ERR(0, 818, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 818, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 818, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 818, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 818, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":819
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 */
    __Pyx_TraceLine(819,0,__PYX_ERR(0, 819, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_full); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 819, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":818
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":820
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 */
  __Pyx_TraceLine(820,0,__PYX_ERR(0, 820, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 820, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 820, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":821
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")             # <<<<<<<<<<<<<<
 * 
 *         cdef int[:] ls = levels
 */
    __Pyx_TraceLine(821,0,__PYX_ERR(0, 821, __pyx_L1_error))
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_8 += 33;
    __Pyx_GIVEREF(__pyx_kp_u_inconsistent_number_of_triangles);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_5 = __Pyx_PyUnicode_From_int(__pyx_v_n_triangles, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_and_levels);
    __pyx_t_8 += 12;
    __Pyx_GIVEREF(__pyx_kp_u_and_levels);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_and_levels);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 821, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 821, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":820
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":823
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
  __Pyx_TraceLine(823,0,__PYX_ERR(0, 823, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_12.memview)) __PYX_ERR(0, 823, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_12;
  __pyx_t_12.memview = NULL;
  __pyx_t_12.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":825
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(825,0,__PYX_ERR(0, 825, __pyx_L1_error))
  __pyx_t_6 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":826
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(826,0,__PYX_ERR(0, 826, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":825
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":827
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int l
 */
  __Pyx_TraceLine(827,0,__PYX_ERR(0, 827, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_13 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 827, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":830
 * 
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(n_triangles):
 *             l = ls[i]
 */
  __Pyx_TraceLine(830,0,__PYX_ERR(0, 830, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 830, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 830, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_max_level = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":831
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(831,0,__PYX_ERR(0, 831, __pyx_L1_error))
  __pyx_t_11 = __pyx_v_n_triangles;
  __pyx_t_14 = __pyx_t_11;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":832
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(832,0,__PYX_ERR(0, 832, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_ls.shape[0])) __pyx_t_17 = 0;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 832, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_16 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":833
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 */
    __Pyx_TraceLine(833,0,__PYX_ERR(0, 833, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":834
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(834,0,__PYX_ERR(0, 834, __pyx_L1_error))
      __pyx_t_17 = abs(__pyx_v_l); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 834, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_17 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":833
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":835
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(835,0,__PYX_ERR(0, 835, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_18 = 0;
    __pyx_t_19 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_18 < 0) {
      __pyx_t_18 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_18 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_18 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 835, __pyx_L1_error)
    }
    __pyx_t_20 = __pyx_v_i;
    __pyx_t_21 = 1;
    __pyx_t_22 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_20 < 0) {
      __pyx_t_20 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_20 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_20 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_21 < 0) {
      __pyx_t_21 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_21 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_21 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_22 < 0) {
      __pyx_t_22 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_22 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_22 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 835, __pyx_L1_error)
    }
    __pyx_t_23 = __pyx_v_i;
    __pyx_t_24 = 2;
    __pyx_t_25 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_23 < 0) {
      __pyx_t_23 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_23 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_23 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_24 < 0) {
      __pyx_t_24 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_24 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_24 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_25 < 0) {
      __pyx_t_25 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_25 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_25 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 835, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_triangle((&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_16 * __pyx_v_tris.strides[0]) ) + __pyx_t_18 * __pyx_v_tris.strides[1]) ) + __pyx_t_19 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_20 * __pyx_v_tris.strides[0]) ) + __pyx_t_21 * __pyx_v_tris.strides[1]) ) + __pyx_t_22 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_23 * __pyx_v_tris.strides[0]) ) + __pyx_t_24 * __pyx_v_tris.strides[1]) ) + __pyx_t_25 * __pyx_v_tris.strides[2]) )))), __pyx_v_l, __pyx_v_diag_balance);
  }

  /* "discretize/_extensions/tree_ext.pyx":836
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(836,0,__PYX_ERR(0, 836, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 836, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":837
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(837,0,__PYX_ERR(0, 837, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":836
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_triangle(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":762
 * 
 *     @cython.cdivision(True)
 *     def refine_triangle(self, triangle, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the triangle to the desired level.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_triangle", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_tris, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_triangle);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":840
 * 
 *     @cython.cdivision(True)
 *     def refine_vertical_trianglular_prism(self, triangle, h, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the trianglular prism to the desired level.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17refine_vertical_trianglular_prism(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_16refine_vertical_trianglular_prism[] = "_TreeMesh.refine_vertical_trianglular_prism(self, triangle, h, levels, finalize=True, diagonal_balance=None)\nRefine the :class:`~discretize.TreeMesh` along the trianglular prism to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given trianglular prism(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        triangle : (N, 3, dim) array_like\n            The nodes of the bottom triangle(s).\n        h : (N) array_like\n            The height of the prism(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        See Also\n        --------\n        refine_surface\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> mesh = discretize.TreeMesh([32, 32, 32])\n        >>> mesh.max_level\n        5\n\n        Next we define the bottom points of the prism, its heights, and the level we\n        want to refine to, then refine the mesh.\n\n        >>> triangle = [[0.14, 0.31, 0.21], [0.32, 0.96, 0.34], [0.87, 0.23, 0.12]]\n        >>> height = 0.35\n        >>> levels = 5\n        >>> tree_mesh.refine_vertical_trianglular_prism(triangle, height, levels)\n\n        Now lets look at the mesh.\n\n        >>> v = tree_mesh.cell_levels_by_index(np.arange(tree_mesh.n_cells))\n        >>> fig, axs = plt.subplots(1, 3, figsize=(12,4))\n        >>> tree_mesh.plot_slice(v, ax=axs[0], normal='x', gri""d=True, clim=[2, 5])\n        >>> tree_mesh.plot_slice(v, ax=axs[1], normal='y', grid=True, clim=[2, 5])\n        >>> tree_mesh.plot_slice(v, ax=axs[2], normal='z', grid=True, clim=[2, 5])\n        >>> plt.show()\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17refine_vertical_trianglular_prism(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_triangle = 0;
  PyObject *__pyx_v_h = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_vertical_trianglular_prism (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_triangle,&__pyx_n_s_h,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_triangle)) != 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_h)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_vertical_trianglular_prism", 0, 3, 5, 1); __PYX_ERR(0, 840, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_vertical_trianglular_prism", 0, 3, 5, 2); __PYX_ERR(0, 840, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_vertical_trianglular_prism") < 0)) __PYX_ERR(0, 840, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_triangle = values[0];
    __pyx_v_h = values[1];
    __pyx_v_levels = values[2];
    __pyx_v_finalize = values[3];
    __pyx_v_diagonal_balance = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_vertical_trianglular_prism", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 840, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_vertical_trianglular_prism", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_16refine_vertical_trianglular_prism(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_triangle, __pyx_v_h, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_16refine_vertical_trianglular_prism(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_triangle, PyObject *__pyx_v_h, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_tris = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_n_triangles;
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_hs = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int __pyx_v_l;
  int __pyx_v_max_level;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  Py_UCS4 __pyx_t_9;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  __Pyx_memviewslice __pyx_t_12 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_13 = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_t_14;
  int __pyx_t_15;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_vertical_trianglular_prism", 0);
  __Pyx_TraceCall("refine_vertical_trianglular_prism", __pyx_f[0], 840, 0, __PYX_ERR(0, 840, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_triangle);
  __Pyx_INCREF(__pyx_v_h);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":894
 * 
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 */
  __Pyx_TraceLine(894,0,__PYX_ERR(0, 894, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":895
 *         """
 *         if self.dim == 2:
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")             # <<<<<<<<<<<<<<
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:
 */
    __Pyx_TraceLine(895,0,__PYX_ERR(0, 895, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 895, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 895, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":894
 * 
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":896
 *         if self.dim == 2:
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")             # <<<<<<<<<<<<<<
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 */
  __Pyx_TraceLine(896,0,__PYX_ERR(0, 896, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_triangle) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_triangle);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 896, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 896, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_triangle, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":897
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:             # <<<<<<<<<<<<<<
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 */
  __Pyx_TraceLine(897,0,__PYX_ERR(0, 897, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_ndim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 897, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 897, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 897, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":898
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]             # <<<<<<<<<<<<<<
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 */
    __Pyx_TraceLine(898,0,__PYX_ERR(0, 898, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_triangle, __pyx_tuple__15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 898, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_triangle, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":897
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:             # <<<<<<<<<<<<<<
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":899
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle
 */
  __Pyx_TraceLine(899,0,__PYX_ERR(0, 899, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_2, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_3 = __pyx_t_7;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_NeObjC(__pyx_t_2, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __pyx_t_7;
  __pyx_L6_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":900
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :, :] tris = triangle
 * 
 */
    __Pyx_TraceLine(900,0,__PYX_ERR(0, 900, __pyx_L1_error))
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_triangle_array_must_be_N_3);
    __pyx_t_8 += 30;
    __Pyx_GIVEREF(__pyx_kp_u_triangle_array_must_be_N_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_triangle_array_must_be_N_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_t_2, __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_8 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u__11);
    __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_5, 3, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 900, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 900, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":899
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":901
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 *         cdef double[:, :, :] tris = triangle             # <<<<<<<<<<<<<<
 * 
 *         h = np.require(np.atleast_1d(h), dtype=np.float64, requirements="C")
 */
  __Pyx_TraceLine(901,0,__PYX_ERR(0, 901, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(__pyx_v_triangle, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 901, __pyx_L1_error)
  __pyx_v_tris = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":903
 *         cdef double[:, :, :] tris = triangle
 * 
 *         h = np.require(np.atleast_1d(h), dtype=np.float64, requirements="C")             # <<<<<<<<<<<<<<
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 */
  __Pyx_TraceLine(903,0,__PYX_ERR(0, 903, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_require); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_h) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_h);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 903, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":904
 * 
 *         h = np.require(np.atleast_1d(h), dtype=np.float64, requirements="C")
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 */
  __Pyx_TraceLine(904,0,__PYX_ERR(0, 904, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 904, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":906
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];             # <<<<<<<<<<<<<<
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 */
  __Pyx_TraceLine(906,0,__PYX_ERR(0, 906, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_triangle, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_n_triangles = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":907
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if h.shape[0] == 1:
 */
  __Pyx_TraceLine(907,0,__PYX_ERR(0, 907, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 907, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 907, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 907, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 907, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":908
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         if h.shape[0] == 1:
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 */
    __Pyx_TraceLine(908,0,__PYX_ERR(0, 908, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_full); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":907
 *                                     requirements='C')
 *         cdef int n_triangles = triangle.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if h.shape[0] == 1:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":909
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if h.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 *         if n_triangles != levels.shape[0]:
 */
  __Pyx_TraceLine(909,0,__PYX_ERR(0, 909, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_h, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 909, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":910
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if h.shape[0] == 1:
 *             h = np.full(n_triangles, h[0], dtype=np.float64)             # <<<<<<<<<<<<<<
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 */
    __Pyx_TraceLine(910,0,__PYX_ERR(0, 910, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_full); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_h, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
    __pyx_t_1 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":909
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if h.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 *         if n_triangles != levels.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":911
 *         if h.shape[0] == 1:
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 *         if n_triangles != h.shape[0]:
 */
  __Pyx_TraceLine(911,0,__PYX_ERR(0, 911, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 911, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 911, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 911, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 911, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 911, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":912
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")             # <<<<<<<<<<<<<<
 *         if n_triangles != h.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 */
    __Pyx_TraceLine(912,0,__PYX_ERR(0, 912, __pyx_L1_error))
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_8 += 33;
    __Pyx_GIVEREF(__pyx_kp_u_inconsistent_number_of_triangles);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_2 = __Pyx_PyUnicode_From_int(__pyx_v_n_triangles, 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_kp_u_and_levels);
    __pyx_t_8 += 12;
    __Pyx_GIVEREF(__pyx_kp_u_and_levels);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_and_levels);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_5, 4, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 912, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 912, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":911
 *         if h.shape[0] == 1:
 *             h = np.full(n_triangles, h[0], dtype=np.float64)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 *         if n_triangles != h.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":913
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 *         if n_triangles != h.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):
 */
  __Pyx_TraceLine(913,0,__PYX_ERR(0, 913, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 913, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_h, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 913, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 913, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":914
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 *         if n_triangles != h.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")             # <<<<<<<<<<<<<<
 *         if np.any(h < 0):
 *             raise ValueError("All heights must be positive.")
 */
    __Pyx_TraceLine(914,0,__PYX_ERR(0, 914, __pyx_L1_error))
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_8 += 33;
    __Pyx_GIVEREF(__pyx_kp_u_inconsistent_number_of_triangles);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_n_triangles, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_INCREF(__pyx_kp_u_and_heights);
    __pyx_t_8 += 13;
    __Pyx_GIVEREF(__pyx_kp_u_and_heights);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_and_heights);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_h, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 914, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":913
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 *         if n_triangles != h.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":915
 *         if n_triangles != h.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):             # <<<<<<<<<<<<<<
 *             raise ValueError("All heights must be positive.")
 * 
 */
  __Pyx_TraceLine(915,0,__PYX_ERR(0, 915, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 915, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_any); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 915, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_h, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 915, __pyx_L1_error)
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 915, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 915, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":916
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):
 *             raise ValueError("All heights must be positive.")             # <<<<<<<<<<<<<<
 * 
 *         cdef int[:] ls = levels
 */
    __Pyx_TraceLine(916,0,__PYX_ERR(0, 916, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 916, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 916, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":915
 *         if n_triangles != h.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):             # <<<<<<<<<<<<<<
 *             raise ValueError("All heights must be positive.")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":918
 *             raise ValueError("All heights must be positive.")
 * 
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 *         cdef double[:] hs = h
 * 
 */
  __Pyx_TraceLine(918,0,__PYX_ERR(0, 918, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_12.memview)) __PYX_ERR(0, 918, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_12;
  __pyx_t_12.memview = NULL;
  __pyx_t_12.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":919
 * 
 *         cdef int[:] ls = levels
 *         cdef double[:] hs = h             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
  __Pyx_TraceLine(919,0,__PYX_ERR(0, 919, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_h, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 919, __pyx_L1_error)
  __pyx_v_hs = __pyx_t_13;
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":921
 *         cdef double[:] hs = h
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(921,0,__PYX_ERR(0, 921, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_7 = (__pyx_t_3 != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":922
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(922,0,__PYX_ERR(0, 922, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":921
 *         cdef double[:] hs = h
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":923
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int l
 */
  __Pyx_TraceLine(923,0,__PYX_ERR(0, 923, __pyx_L1_error))
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_14 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 923, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_14;

  /* "discretize/_extensions/tree_ext.pyx":926
 * 
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(n_triangles):
 *             l = ls[i]
 */
  __Pyx_TraceLine(926,0,__PYX_ERR(0, 926, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_max_level = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":927
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(927,0,__PYX_ERR(0, 927, __pyx_L1_error))
  __pyx_t_11 = __pyx_v_n_triangles;
  __pyx_t_15 = __pyx_t_11;
  for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
    __pyx_v_i = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":928
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(928,0,__PYX_ERR(0, 928, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_18 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_ls.shape[0])) __pyx_t_18 = 0;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 928, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_17 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":929
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 */
    __Pyx_TraceLine(929,0,__PYX_ERR(0, 929, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":930
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(930,0,__PYX_ERR(0, 930, __pyx_L1_error))
      __pyx_t_18 = abs(__pyx_v_l); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 930, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_18 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":929
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":931
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(931,0,__PYX_ERR(0, 931, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_19 = 0;
    __pyx_t_20 = 0;
    __pyx_t_18 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_tris.shape[0])) __pyx_t_18 = 0;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_18 = 1;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_tris.shape[1])) __pyx_t_18 = 1;
    if (__pyx_t_20 < 0) {
      __pyx_t_20 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_20 < 0)) __pyx_t_18 = 2;
    } else if (unlikely(__pyx_t_20 >= __pyx_v_tris.shape[2])) __pyx_t_18 = 2;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 931, __pyx_L1_error)
    }
    __pyx_t_21 = __pyx_v_i;
    __pyx_t_22 = 1;
    __pyx_t_23 = 0;
    __pyx_t_18 = -1;
    if (__pyx_t_21 < 0) {
      __pyx_t_21 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_21 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_21 >= __pyx_v_tris.shape[0])) __pyx_t_18 = 0;
    if (__pyx_t_22 < 0) {
      __pyx_t_22 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_22 < 0)) __pyx_t_18 = 1;
    } else if (unlikely(__pyx_t_22 >= __pyx_v_tris.shape[1])) __pyx_t_18 = 1;
    if (__pyx_t_23 < 0) {
      __pyx_t_23 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_23 < 0)) __pyx_t_18 = 2;
    } else if (unlikely(__pyx_t_23 >= __pyx_v_tris.shape[2])) __pyx_t_18 = 2;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 931, __pyx_L1_error)
    }
    __pyx_t_24 = __pyx_v_i;
    __pyx_t_25 = 2;
    __pyx_t_26 = 0;
    __pyx_t_18 = -1;
    if (__pyx_t_24 < 0) {
      __pyx_t_24 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_24 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_24 >= __pyx_v_tris.shape[0])) __pyx_t_18 = 0;
    if (__pyx_t_25 < 0) {
      __pyx_t_25 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_25 < 0)) __pyx_t_18 = 1;
    } else if (unlikely(__pyx_t_25 >= __pyx_v_tris.shape[1])) __pyx_t_18 = 1;
    if (__pyx_t_26 < 0) {
      __pyx_t_26 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_26 < 0)) __pyx_t_18 = 2;
    } else if (unlikely(__pyx_t_26 >= __pyx_v_tris.shape[2])) __pyx_t_18 = 2;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 931, __pyx_L1_error)
    }
    __pyx_t_27 = __pyx_v_i;
    __pyx_t_18 = -1;
    if (__pyx_t_27 < 0) {
      __pyx_t_27 += __pyx_v_hs.shape[0];
      if (unlikely(__pyx_t_27 < 0)) __pyx_t_18 = 0;
    } else if (unlikely(__pyx_t_27 >= __pyx_v_hs.shape[0])) __pyx_t_18 = 0;
    if (unlikely(__pyx_t_18 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_18);
      __PYX_ERR(0, 931, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_vert_triang_prism((&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_17 * __pyx_v_tris.strides[0]) ) + __pyx_t_19 * __pyx_v_tris.strides[1]) ) + __pyx_t_20 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_21 * __pyx_v_tris.strides[0]) ) + __pyx_t_22 * __pyx_v_tris.strides[1]) ) + __pyx_t_23 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_24 * __pyx_v_tris.strides[0]) ) + __pyx_t_25 * __pyx_v_tris.strides[1]) ) + __pyx_t_26 * __pyx_v_tris.strides[2]) )))), (*((double *) ( /* dim=0 */ (__pyx_v_hs.data + __pyx_t_27 * __pyx_v_hs.strides[0]) ))), __pyx_v_l, __pyx_v_diag_balance);
  }

  /* "discretize/_extensions/tree_ext.pyx":932
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(932,0,__PYX_ERR(0, 932, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 932, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":933
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(933,0,__PYX_ERR(0, 933, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":932
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_vert_triang_prism(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], hs[i], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":840
 * 
 *     @cython.cdivision(True)
 *     def refine_vertical_trianglular_prism(self, triangle, h, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the trianglular prism to the desired level.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_vertical_trianglular_prism", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_tris, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_hs, 1);
  __Pyx_XDECREF(__pyx_v_triangle);
  __Pyx_XDECREF(__pyx_v_h);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":936
 * 
 *     @cython.cdivision(True)
 *     def refine_tetrahedron(self, tetra, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the tetrahedron to the desired level.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_19refine_tetrahedron(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_18refine_tetrahedron[] = "_TreeMesh.refine_tetrahedron(self, tetra, levels, finalize=True, diagonal_balance=None)\nRefine the :class:`~discretize.TreeMesh` along the tetrahedron to the desired level.\n\n        Refines the TreeMesh by determining if a cell intersects the given triangle(s)\n        to the prescribed level(s).\n\n        Parameters\n        ----------\n        tetra : (N, dim+1, dim) array_like\n            The nodes of the tetrahedron(s).\n        levels : int or (N) array_like of int\n            The level to refine intersecting cells to.\n        finalize : bool, optional\n            Whether to finalize after refining\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        We create a simple mesh and refine the TreeMesh such that all cells that\n        intersect the line segment path are at the given levels.\n\n        >>> import discretize\n        >>> import matplotlib.pyplot as plt\n        >>> import matplotlib.patches as patches\n        >>> tree_mesh = discretize.TreeMesh([32, 32, 32])\n        >>> tree_mesh.max_level\n        5\n\n        Next we define the points along the line and the level we want to refine to,\n        and refine the mesh.\n\n        >>> tetra = [\n        ...     [0.32, 0.21, 0.15],\n        ...     [0.82, 0.19, 0.34],\n        ...     [0.14, 0.82, 0.29],\n        ...     [0.32, 0.27, 0.83],\n        ... ]\n        >>> levels = 5\n        >>> tree_mesh.refine_tetrahedron(tetra, levels)\n\n        Now lets look at the mesh, checking how the refine function proceeded.\n\n        >>> levels = tree_mesh.cell_levels_by_index(np.arange(tree_mesh.n_cells))\n        >>> ax = plt.gca()\n        >>> tree_mesh.plot_slice(levels, normal='z', slice_loc=0.2, grid=True, ax=ax)\n        >>> plt.show()\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_19refine_tetrahedron(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tetra = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("refine_tetrahedron (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tetra,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tetra)) != 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_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("refine_tetrahedron", 0, 2, 4, 1); __PYX_ERR(0, 936, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "refine_tetrahedron") < 0)) __PYX_ERR(0, 936, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tetra = values[0];
    __pyx_v_levels = values[1];
    __pyx_v_finalize = values[2];
    __pyx_v_diagonal_balance = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("refine_tetrahedron", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 936, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_tetrahedron", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_18refine_tetrahedron(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_tetra, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_18refine_tetrahedron(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_tetra, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_tris = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_n_triangles;
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_v_diag_balance;
  int __pyx_v_l;
  int __pyx_v_max_level;
  int __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  Py_UCS4 __pyx_t_9;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  __Pyx_memviewslice __pyx_t_12 = { 0, 0, { 0 }, { 0 }, { 0 } };
  bool __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  Py_ssize_t __pyx_t_23;
  Py_ssize_t __pyx_t_24;
  Py_ssize_t __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refine_tetrahedron", 0);
  __Pyx_TraceCall("refine_tetrahedron", __pyx_f[0], 936, 0, __PYX_ERR(0, 936, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_tetra);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":986
 * 
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 */
  __Pyx_TraceLine(986,0,__PYX_ERR(0, 986, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 986, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 986, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 986, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":987
 *         """
 *         if self.dim == 2:
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)             # <<<<<<<<<<<<<<
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 *         if tetra.ndim == 2:
 */
    __Pyx_TraceLine(987,0,__PYX_ERR(0, 987, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_refine_triangle); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 987, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 987, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_tetra);
    __Pyx_GIVEREF(__pyx_v_tetra);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tetra);
    __Pyx_INCREF(__pyx_v_levels);
    __Pyx_GIVEREF(__pyx_v_levels);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_levels);
    __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_finalize, __pyx_v_finalize) < 0) __PYX_ERR(0, 987, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_diagonal_balance, __pyx_v_diagonal_balance) < 0) __PYX_ERR(0, 987, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 987, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":986
 * 
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":988
 *         if self.dim == 2:
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")             # <<<<<<<<<<<<<<
 *         if tetra.ndim == 2:
 *             tetra = tetra[None, ...]
 */
  __Pyx_TraceLine(988,0,__PYX_ERR(0, 988, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_require); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_v_tetra) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tetra);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 988, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_tetra, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":989
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 *         if tetra.ndim == 2:             # <<<<<<<<<<<<<<
 *             tetra = tetra[None, ...]
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:
 */
  __Pyx_TraceLine(989,0,__PYX_ERR(0, 989, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_tetra, __pyx_n_s_ndim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 989, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":990
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 *         if tetra.ndim == 2:
 *             tetra = tetra[None, ...]             # <<<<<<<<<<<<<<
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:
 *             raise ValueError(f"tetra array must be (N, {self.dim+1}, {self.dim})")
 */
    __Pyx_TraceLine(990,0,__PYX_ERR(0, 990, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_tetra, __pyx_tuple__15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 990, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF_SET(__pyx_v_tetra, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":989
 *             return self.refine_triangle(tetra, levels, finalize=finalize, diagonal_balance=diagonal_balance)
 *         tetra = np.require(np.atleast_2d(tetra), dtype=np.float64, requirements="C")
 *         if tetra.ndim == 2:             # <<<<<<<<<<<<<<
 *             tetra = tetra[None, ...]
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":991
 *         if tetra.ndim == 2:
 *             tetra = tetra[None, ...]
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"tetra array must be (N, {self.dim+1}, {self.dim})")
 *         cdef double[:, :, :] tris = tetra
 */
  __Pyx_TraceLine(991,0,__PYX_ERR(0, 991, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tetra, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_3 = __pyx_t_7;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tetra, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __pyx_t_7;
  __pyx_L6_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":992
 *             tetra = tetra[None, ...]
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:
 *             raise ValueError(f"tetra array must be (N, {self.dim+1}, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :, :] tris = tetra
 * 
 */
    __Pyx_TraceLine(992,0,__PYX_ERR(0, 992, __pyx_L1_error))
    __pyx_t_2 = PyTuple_New(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_tetra_array_must_be_N);
    __pyx_t_8 += 24;
    __Pyx_GIVEREF(__pyx_kp_u_tetra_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_tetra_array_must_be_N);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_INCREF(__pyx_kp_u__18);
    __pyx_t_8 += 2;
    __Pyx_GIVEREF(__pyx_kp_u__18);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u__18);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_8 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_kp_u__11);
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 5, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 992, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":991
 *         if tetra.ndim == 2:
 *             tetra = tetra[None, ...]
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"tetra array must be (N, {self.dim+1}, {self.dim})")
 *         cdef double[:, :, :] tris = tetra
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":993
 *         if tetra.shape[-1] != self.dim or tetra.shape[-2] != self.dim+1:
 *             raise ValueError(f"tetra array must be (N, {self.dim+1}, {self.dim})")
 *         cdef double[:, :, :] tris = tetra             # <<<<<<<<<<<<<<
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
  __Pyx_TraceLine(993,0,__PYX_ERR(0, 993, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(__pyx_v_tetra, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 993, __pyx_L1_error)
  __pyx_v_tris = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":995
 *         cdef double[:, :, :] tris = tetra
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         cdef int n_triangles = tetra.shape[0];
 */
  __Pyx_TraceLine(995,0,__PYX_ERR(0, 995, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_require); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 995, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":997
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         cdef int n_triangles = tetra.shape[0];             # <<<<<<<<<<<<<<
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 */
  __Pyx_TraceLine(997,0,__PYX_ERR(0, 997, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tetra, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 997, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 997, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 997, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_n_triangles = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":998
 *                                     requirements='C')
 *         cdef int n_triangles = tetra.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 */
  __Pyx_TraceLine(998,0,__PYX_ERR(0, 998, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":999
 *         cdef int n_triangles = tetra.shape[0];
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)             # <<<<<<<<<<<<<<
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 */
    __Pyx_TraceLine(999,0,__PYX_ERR(0, 999, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_full); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_levels, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":998
 *                                     requirements='C')
 *         cdef int n_triangles = tetra.shape[0];
 *         if levels.shape[0] == 1:             # <<<<<<<<<<<<<<
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1000
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 */
  __Pyx_TraceLine(1000,0,__PYX_ERR(0, 1000, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_n_triangles); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":1001
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")             # <<<<<<<<<<<<<<
 * 
 *         cdef int[:] ls = levels
 */
    __Pyx_TraceLine(1001,0,__PYX_ERR(0, 1001, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = 0;
    __pyx_t_9 = 127;
    __Pyx_INCREF(__pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_8 += 33;
    __Pyx_GIVEREF(__pyx_kp_u_inconsistent_number_of_triangles);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_inconsistent_number_of_triangles);
    __pyx_t_5 = __Pyx_PyUnicode_From_int(__pyx_v_n_triangles, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_INCREF(__pyx_kp_u_and_levels);
    __pyx_t_8 += 12;
    __Pyx_GIVEREF(__pyx_kp_u_and_levels);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_and_levels);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_levels, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
    __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 4, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 1001, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":1000
 *         if levels.shape[0] == 1:
 *             levels = np.full(n_triangles, levels[0], dtype=np.int32)
 *         if n_triangles != levels.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1003
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and levels {levels.shape[0]}")
 * 
 *         cdef int[:] ls = levels             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
  __Pyx_TraceLine(1003,0,__PYX_ERR(0, 1003, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_12.memview)) __PYX_ERR(0, 1003, __pyx_L1_error)
  __pyx_v_ls = __pyx_t_12;
  __pyx_t_12.memview = NULL;
  __pyx_t_12.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":1005
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(1005,0,__PYX_ERR(0, 1005, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_7 = (__pyx_t_3 != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":1006
 * 
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 * 
 */
    __Pyx_TraceLine(1006,0,__PYX_ERR(0, 1006, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1005
 *         cdef int[:] ls = levels
 * 
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1007
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 * 
 *         cdef int l
 */
  __Pyx_TraceLine(1007,0,__PYX_ERR(0, 1007, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_13 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1007, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":1010
 * 
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         for i in range(n_triangles):
 *             l = ls[i]
 */
  __Pyx_TraceLine(1010,0,__PYX_ERR(0, 1010, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1010, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1010, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_max_level = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":1011
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(1011,0,__PYX_ERR(0, 1011, __pyx_L1_error))
  __pyx_t_11 = __pyx_v_n_triangles;
  __pyx_t_14 = __pyx_t_11;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":1012
 *         cdef int max_level = self.max_level
 *         for i in range(n_triangles):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(1012,0,__PYX_ERR(0, 1012, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_ls.shape[0])) __pyx_t_17 = 0;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 1012, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_16 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":1013
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 */
    __Pyx_TraceLine(1013,0,__PYX_ERR(0, 1013, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":1014
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(1014,0,__PYX_ERR(0, 1014, __pyx_L1_error))
      __pyx_t_17 = abs(__pyx_v_l); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 1014, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_17 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":1013
 *         for i in range(n_triangles):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":1015
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(1015,0,__PYX_ERR(0, 1015, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_18 = 0;
    __pyx_t_19 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_18 < 0) {
      __pyx_t_18 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_18 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_18 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 1015, __pyx_L1_error)
    }
    __pyx_t_20 = __pyx_v_i;
    __pyx_t_21 = 1;
    __pyx_t_22 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_20 < 0) {
      __pyx_t_20 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_20 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_20 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_21 < 0) {
      __pyx_t_21 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_21 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_21 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_22 < 0) {
      __pyx_t_22 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_22 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_22 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 1015, __pyx_L1_error)
    }
    __pyx_t_23 = __pyx_v_i;
    __pyx_t_24 = 2;
    __pyx_t_25 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_23 < 0) {
      __pyx_t_23 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_23 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_23 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_24 < 0) {
      __pyx_t_24 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_24 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_24 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_25 < 0) {
      __pyx_t_25 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_25 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_25 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 1015, __pyx_L1_error)
    }
    __pyx_t_26 = __pyx_v_i;
    __pyx_t_27 = 3;
    __pyx_t_28 = 0;
    __pyx_t_17 = -1;
    if (__pyx_t_26 < 0) {
      __pyx_t_26 += __pyx_v_tris.shape[0];
      if (unlikely(__pyx_t_26 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_26 >= __pyx_v_tris.shape[0])) __pyx_t_17 = 0;
    if (__pyx_t_27 < 0) {
      __pyx_t_27 += __pyx_v_tris.shape[1];
      if (unlikely(__pyx_t_27 < 0)) __pyx_t_17 = 1;
    } else if (unlikely(__pyx_t_27 >= __pyx_v_tris.shape[1])) __pyx_t_17 = 1;
    if (__pyx_t_28 < 0) {
      __pyx_t_28 += __pyx_v_tris.shape[2];
      if (unlikely(__pyx_t_28 < 0)) __pyx_t_17 = 2;
    } else if (unlikely(__pyx_t_28 >= __pyx_v_tris.shape[2])) __pyx_t_17 = 2;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      __PYX_ERR(0, 1015, __pyx_L1_error)
    }
    __pyx_v_self->tree->refine_tetra((&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_16 * __pyx_v_tris.strides[0]) ) + __pyx_t_18 * __pyx_v_tris.strides[1]) ) + __pyx_t_19 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_20 * __pyx_v_tris.strides[0]) ) + __pyx_t_21 * __pyx_v_tris.strides[1]) ) + __pyx_t_22 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_23 * __pyx_v_tris.strides[0]) ) + __pyx_t_24 * __pyx_v_tris.strides[1]) ) + __pyx_t_25 * __pyx_v_tris.strides[2]) )))), (&(*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_tris.data + __pyx_t_26 * __pyx_v_tris.strides[0]) ) + __pyx_t_27 * __pyx_v_tris.strides[1]) ) + __pyx_t_28 * __pyx_v_tris.strides[2]) )))), __pyx_v_l, __pyx_v_diag_balance);
  }

  /* "discretize/_extensions/tree_ext.pyx":1016
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(1016,0,__PYX_ERR(0, 1016, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1016, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":1017
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
    __Pyx_TraceLine(1017,0,__PYX_ERR(0, 1017, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1016
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.refine_tetra(&tris[i, 0, 0], &tris[i, 1, 0], &tris[i, 2, 0], &tris[i, 3, 0], l, diag_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":936
 * 
 *     @cython.cdivision(True)
 *     def refine_tetrahedron(self, tetra, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Refine the :class:`~discretize.TreeMesh` along the tetrahedron to the desired level.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.refine_tetrahedron", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_tris, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_tetra);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1020
 * 
 *     @cython.cdivision(True)
 *     def insert_cells(self, points, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Insert cells into the :class:`~discretize.TreeMesh` that contain given points.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21insert_cells(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_20insert_cells[] = "_TreeMesh.insert_cells(self, points, levels, finalize=True, diagonal_balance=None)\nInsert cells into the :class:`~discretize.TreeMesh` that contain given points.\n\n        Insert cell(s) into the :class:`~discretize.TreeMesh` that contain the given point(s) at the\n        assigned level(s).\n\n        Parameters\n        ----------\n        points : (N, dim) array_like\n        levels : (N) array_like of int\n        finalize : bool, optional\n            Whether to finalize after inserting point(s)\n        diagonal_balance : bool or None, optional\n            Whether to balance cells diagonally in the refinement, `None` implies using\n            the same setting used to instantiate the TreeMesh`.\n\n        Examples\n        --------\n        >>> from discretize import TreeMesh\n        >>> mesh = TreeMesh([32,32])\n        >>> mesh.insert_cells([0.5, 0.5], mesh.max_level)\n        >>> mesh\n        QuadTreeMesh: 3.91%% filled\n        Level : Number of cells               Mesh Extent               Cell Widths\n        -----------------------           min     ,     max            min   ,   max\n          2   :       12             ---------------------------   --------------------\n          3   :       13          x:      0.0     ,     1.0         0.03125  ,    0.25\n          4   :       11          y:      0.0     ,     1.0         0.03125  ,    0.25\n          5   :        4\n        -----------------------\n        Total :       40\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21insert_cells(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_points = 0;
  PyObject *__pyx_v_levels = 0;
  PyObject *__pyx_v_finalize = 0;
  PyObject *__pyx_v_diagonal_balance = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("insert_cells (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_points,&__pyx_n_s_levels,&__pyx_n_s_finalize,&__pyx_n_s_diagonal_balance,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_points)) != 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_levels)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("insert_cells", 0, 2, 4, 1); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_finalize);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_diagonal_balance);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert_cells") < 0)) __PYX_ERR(0, 1020, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_points = values[0];
    __pyx_v_levels = values[1];
    __pyx_v_finalize = values[2];
    __pyx_v_diagonal_balance = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("insert_cells", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1020, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.insert_cells", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20insert_cells(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_points, __pyx_v_levels, __pyx_v_finalize, __pyx_v_diagonal_balance);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20insert_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_points, PyObject *__pyx_v_levels, PyObject *__pyx_v_finalize, PyObject *__pyx_v_diagonal_balance) {
  __Pyx_memviewslice __pyx_v_cs = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_ls = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_l;
  int __pyx_v_max_level;
  CYTHON_UNUSED bool __pyx_v_diag_balance;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_UCS4 __pyx_t_8;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_11;
  int __pyx_t_12;
  bool __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("insert_cells", 0);
  __Pyx_TraceCall("insert_cells", __pyx_f[0], 1020, 0, __PYX_ERR(0, 1020, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_points);
  __Pyx_INCREF(__pyx_v_diagonal_balance);

  /* "discretize/_extensions/tree_ext.pyx":1052
 *         Total :       40
 *         """
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,             # <<<<<<<<<<<<<<
 *                             requirements='C')
 *         if points.shape[1] != self.dim:
 */
  __Pyx_TraceLine(1052,0,__PYX_ERR(0, 1052, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_points) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_points);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 1052, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_points, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1054
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,
 *                             requirements='C')
 *         if points.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 */
  __Pyx_TraceLine(1054,0,__PYX_ERR(0, 1054, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":1055
 *                             requirements='C')
 *         if points.shape[1] != self.dim:
 *             raise ValueError(f"points array must be (N, {self.dim})")             # <<<<<<<<<<<<<<
 *         cdef double[:, :] cs = points
 *         cdef int[:] ls = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
    __Pyx_TraceLine(1055,0,__PYX_ERR(0, 1055, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_8 = 127;
    __Pyx_INCREF(__pyx_kp_u_points_array_must_be_N);
    __pyx_t_7 += 25;
    __Pyx_GIVEREF(__pyx_kp_u_points_array_must_be_N);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_points_array_must_be_N);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8;
    __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_kp_u__11);
    __pyx_t_7 += 1;
    __Pyx_GIVEREF(__pyx_kp_u__11);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u__11);
    __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1055, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 1055, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":1054
 *         points = np.require(np.atleast_2d(points), dtype=np.float64,
 *                             requirements='C')
 *         if points.shape[1] != self.dim:             # <<<<<<<<<<<<<<
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1056
 *         if points.shape[1] != self.dim:
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points             # <<<<<<<<<<<<<<
 *         cdef int[:] ls = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 */
  __Pyx_TraceLine(1056,0,__PYX_ERR(0, 1056, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_points, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __pyx_v_cs = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":1057
 *             raise ValueError(f"points array must be (N, {self.dim})")
 *         cdef double[:, :] cs = points
 *         cdef int[:] ls = np.require(np.atleast_1d(levels), dtype=np.int32,             # <<<<<<<<<<<<<<
 *                                     requirements='C')
 *         if points.shape[0] != ls.shape[0]:
 */
  __Pyx_TraceLine(1057,0,__PYX_ERR(0, 1057, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 1057, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ls = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":1059
 *         cdef int[:] ls = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if points.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 *         cdef int l
 */
  __Pyx_TraceLine(1059,0,__PYX_ERR(0, 1059, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_points, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_ls.shape[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_6)) {

    /* "discretize/_extensions/tree_ext.pyx":1060
 *                                     requirements='C')
 *         if points.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 *         cdef int l
 *         cdef int max_level = self.max_level
 */
    __Pyx_TraceLine(1060,0,__PYX_ERR(0, 1060, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1060, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1060, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":1059
 *         cdef int[:] ls = np.require(np.atleast_1d(levels), dtype=np.int32,
 *                                     requirements='C')
 *         if points.shape[0] != ls.shape[0]:             # <<<<<<<<<<<<<<
 *             raise ValueError("level length must match the points array's first dimension")
 *         cdef int l
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1062
 *             raise ValueError("level length must match the points array's first dimension")
 *         cdef int l
 *         cdef int max_level = self.max_level             # <<<<<<<<<<<<<<
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 */
  __Pyx_TraceLine(1062,0,__PYX_ERR(0, 1062, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1062, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_max_level = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":1063
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  __Pyx_TraceLine(1063,0,__PYX_ERR(0, 1063, __pyx_L1_error))
  __pyx_t_6 = (__pyx_v_diagonal_balance == Py_None);
  __pyx_t_12 = (__pyx_t_6 != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":1064
 *         cdef int max_level = self.max_level
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance             # <<<<<<<<<<<<<<
 *         cdef bool diag_balance = diagonal_balance
 *         for i in range(ls.shape[0]):
 */
    __Pyx_TraceLine(1064,0,__PYX_ERR(0, 1064, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->_diagonal_balance); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1064, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_diagonal_balance, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1063
 *         cdef int l
 *         cdef int max_level = self.max_level
 *         if diagonal_balance is None:             # <<<<<<<<<<<<<<
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1065
 *         if diagonal_balance is None:
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance             # <<<<<<<<<<<<<<
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 */
  __Pyx_TraceLine(1065,0,__PYX_ERR(0, 1065, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_13 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1065, __pyx_L1_error)
  __pyx_v_diag_balance = __pyx_t_13;

  /* "discretize/_extensions/tree_ext.pyx":1066
 *             diagonal_balance = self._diagonal_balance
 *         cdef bool diag_balance = diagonal_balance
 *         for i in range(ls.shape[0]):             # <<<<<<<<<<<<<<
 *             l = ls[i]
 *             if l < 0:
 */
  __Pyx_TraceLine(1066,0,__PYX_ERR(0, 1066, __pyx_L1_error))
  __pyx_t_7 = (__pyx_v_ls.shape[0]);
  __pyx_t_14 = __pyx_t_7;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":1067
 *         cdef bool diag_balance = diagonal_balance
 *         for i in range(ls.shape[0]):
 *             l = ls[i]             # <<<<<<<<<<<<<<
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 */
    __Pyx_TraceLine(1067,0,__PYX_ERR(0, 1067, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_11 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_ls.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_ls.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1067, __pyx_L1_error)
    }
    __pyx_v_l = (*((int *) ( /* dim=0 */ (__pyx_v_ls.data + __pyx_t_16 * __pyx_v_ls.strides[0]) )));

    /* "discretize/_extensions/tree_ext.pyx":1068
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 */
    __Pyx_TraceLine(1068,0,__PYX_ERR(0, 1068, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_l < 0) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":1069
 *             l = ls[i]
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))             # <<<<<<<<<<<<<<
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 *         if finalize:
 */
      __Pyx_TraceLine(1069,0,__PYX_ERR(0, 1069, __pyx_L1_error))
      __pyx_t_11 = abs(__pyx_v_l); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1069, __pyx_L1_error)
      __pyx_v_l = ((__pyx_v_max_level + 1) - (__pyx_t_11 % (__pyx_v_max_level + 1)));

      /* "discretize/_extensions/tree_ext.pyx":1068
 *         for i in range(ls.shape[0]):
 *             l = ls[i]
 *             if l < 0:             # <<<<<<<<<<<<<<
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":1070
 *             if l < 0:
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)             # <<<<<<<<<<<<<<
 *         if finalize:
 *             self.finalize()
 */
    __Pyx_TraceLine(1070,0,__PYX_ERR(0, 1070, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_cs.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_cs.shape[0])) __pyx_t_11 = 0;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_cs.shape[1];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_11 = 1;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_cs.shape[1])) __pyx_t_11 = 1;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1070, __pyx_L1_error)
    }
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_diagonal_balance); if (unlikely((__pyx_t_13 == ((bool)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1070, __pyx_L1_error)
    __pyx_v_self->tree->insert_cell((&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_cs.data + __pyx_t_16 * __pyx_v_cs.strides[0]) ) + __pyx_t_17 * __pyx_v_cs.strides[1]) )))), __pyx_v_l, __pyx_t_13);
  }

  /* "discretize/_extensions/tree_ext.pyx":1071
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  __Pyx_TraceLine(1071,0,__PYX_ERR(0, 1071, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_finalize); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1071, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":1072
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 *         if finalize:
 *             self.finalize()             # <<<<<<<<<<<<<<
 * 
 *     def finalize(self):
 */
    __Pyx_TraceLine(1072,0,__PYX_ERR(0, 1072, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_finalize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1072, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1072, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1071
 *                 l = (max_level + 1) - (abs(l) % (max_level + 1))
 *             self.tree.insert_cell(&cs[i, 0], l, diagonal_balance)
 *         if finalize:             # <<<<<<<<<<<<<<
 *             self.finalize()
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1020
 * 
 *     @cython.cdivision(True)
 *     def insert_cells(self, points, levels, finalize=True, diagonal_balance=None):             # <<<<<<<<<<<<<<
 *         """Insert cells into the :class:`~discretize.TreeMesh` that contain given points.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.insert_cells", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_cs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_ls, 1);
  __Pyx_XDECREF(__pyx_v_points);
  __Pyx_XDECREF(__pyx_v_diagonal_balance);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1074
 *             self.finalize()
 * 
 *     def finalize(self):             # <<<<<<<<<<<<<<
 *         """Finalize the :class:`~discretize.TreeMesh`.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23finalize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_22finalize[] = "_TreeMesh.finalize(self)\nFinalize the :class:`~discretize.TreeMesh`.\n\n        Called once a tree mesh has been finalized; i.e. no further mesh\n        refinement will be carried out. The tree mesh must be finalized\n        before it can be used to call most of its properties or construct\n        operators. When finalized, mesh refinement is no longer enabled.\n\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23finalize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("finalize (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22finalize(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22finalize(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("finalize", 0);
  __Pyx_TraceCall("finalize", __pyx_f[0], 1074, 0, __PYX_ERR(0, 1074, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1083
 * 
 *         """
 *         if not self._finalized:             # <<<<<<<<<<<<<<
 *             self.tree.finalize_lists()
 *             self.tree.number()
 */
  __Pyx_TraceLine(1083,0,__PYX_ERR(0, 1083, __pyx_L1_error))
  __pyx_t_1 = ((!(__pyx_v_self->_finalized != 0)) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":1084
 *         """
 *         if not self._finalized:
 *             self.tree.finalize_lists()             # <<<<<<<<<<<<<<
 *             self.tree.number()
 *             self._finalized=True
 */
    __Pyx_TraceLine(1084,0,__PYX_ERR(0, 1084, __pyx_L1_error))
    __pyx_v_self->tree->finalize_lists();

    /* "discretize/_extensions/tree_ext.pyx":1085
 *         if not self._finalized:
 *             self.tree.finalize_lists()
 *             self.tree.number()             # <<<<<<<<<<<<<<
 *             self._finalized=True
 * 
 */
    __Pyx_TraceLine(1085,0,__PYX_ERR(0, 1085, __pyx_L1_error))
    __pyx_v_self->tree->number();

    /* "discretize/_extensions/tree_ext.pyx":1086
 *             self.tree.finalize_lists()
 *             self.tree.number()
 *             self._finalized=True             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
    __Pyx_TraceLine(1086,0,__PYX_ERR(0, 1086, __pyx_L1_error))
    __pyx_v_self->_finalized = 1;

    /* "discretize/_extensions/tree_ext.pyx":1083
 * 
 *         """
 *         if not self._finalized:             # <<<<<<<<<<<<<<
 *             self.tree.finalize_lists()
 *             self.tree.number()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1074
 *             self.finalize()
 * 
 *     def finalize(self):             # <<<<<<<<<<<<<<
 *         """Finalize the :class:`~discretize.TreeMesh`.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.finalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1089
 * 
 *     @property
 *     def finalized(self):             # <<<<<<<<<<<<<<
 *         """Whether tree mesh is finalized.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1089, 0, __PYX_ERR(0, 1089, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1103
 *             Returns *True* if finalized, *False* otherwise
 *         """
 *         return self._finalized             # <<<<<<<<<<<<<<
 * 
 *     def number(self):
 */
  __Pyx_TraceLine(1103,0,__PYX_ERR(0, 1103, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_finalized); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1089
 * 
 *     @property
 *     def finalized(self):             # <<<<<<<<<<<<<<
 *         """Whether tree mesh is finalized.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.finalized.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1105
 *         return self._finalized
 * 
 *     def number(self):             # <<<<<<<<<<<<<<
 *         """Number the cells, nodes, faces, and edges of the TreeMesh."""
 *         self.tree.number()
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_25number(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_24number[] = "_TreeMesh.number(self)\nNumber the cells, nodes, faces, and edges of the TreeMesh.";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_25number(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("number (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_24number(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_24number(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("number", 0);
  __Pyx_TraceCall("number", __pyx_f[0], 1105, 0, __PYX_ERR(0, 1105, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1107
 *     def number(self):
 *         """Number the cells, nodes, faces, and edges of the TreeMesh."""
 *         self.tree.number()             # <<<<<<<<<<<<<<
 * 
 *     def _set_origin(self, origin):
 */
  __Pyx_TraceLine(1107,0,__PYX_ERR(0, 1107, __pyx_L1_error))
  __pyx_v_self->tree->number();

  /* "discretize/_extensions/tree_ext.pyx":1105
 *         return self._finalized
 * 
 *     def number(self):             # <<<<<<<<<<<<<<
 *         """Number the cells, nodes, faces, and edges of the TreeMesh."""
 *         self.tree.number()
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.number", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1109
 *         self.tree.number()
 * 
 *     def _set_origin(self, origin):             # <<<<<<<<<<<<<<
 *         if not isinstance(origin, (list, tuple, np.ndarray)):
 *             raise ValueError('origin must be a list, tuple or numpy array')
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27_set_origin(PyObject *__pyx_v_self, PyObject *__pyx_v_origin); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_26_set_origin[] = "_TreeMesh._set_origin(self, origin)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27_set_origin(PyObject *__pyx_v_self, PyObject *__pyx_v_origin) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_set_origin (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_26_set_origin(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_origin));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_26_set_origin(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_origin) {
  int_t __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_shift = { 0, 0, { 0 }, { 0 }, { 0 } };
  Node *__pyx_v_node;
  Edge *__pyx_v_edge;
  Face *__pyx_v_face;
  Py_ssize_t __pyx_v_i;
  std::pair<int_t,Node *>  __pyx_v_itN;
  std::pair<int_t,Edge *>  __pyx_v_itE;
  std::pair<int_t,Face *>  __pyx_v_itF;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  std::map<int_t,Node *> ::iterator __pyx_t_17;
  node_map_t *__pyx_t_18;
  std::pair<int_t,Node *>  __pyx_t_19;
  Node *__pyx_t_20;
  int_t __pyx_t_21;
  int_t __pyx_t_22;
  std::map<int_t,Edge *> ::iterator __pyx_t_23;
  edge_map_t *__pyx_t_24;
  std::pair<int_t,Edge *>  __pyx_t_25;
  Edge *__pyx_t_26;
  std::map<int_t,Face *> ::iterator __pyx_t_27;
  face_map_t *__pyx_t_28;
  std::pair<int_t,Face *>  __pyx_t_29;
  Face *__pyx_t_30;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_set_origin", 0);
  __Pyx_TraceCall("_set_origin", __pyx_f[0], 1109, 0, __PYX_ERR(0, 1109, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1110
 * 
 *     def _set_origin(self, origin):
 *         if not isinstance(origin, (list, tuple, np.ndarray)):             # <<<<<<<<<<<<<<
 *             raise ValueError('origin must be a list, tuple or numpy array')
 *         self._origin = np.asarray(origin, dtype=np.float64)
 */
  __Pyx_TraceLine(1110,0,__PYX_ERR(0, 1110, __pyx_L1_error))
  __pyx_t_2 = PyList_Check(__pyx_v_origin); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = PyTuple_Check(__pyx_v_origin); 
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_origin, __pyx_ptype_5numpy_ndarray); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  __pyx_t_3 = ((!(__pyx_t_1 != 0)) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":1111
 *     def _set_origin(self, origin):
 *         if not isinstance(origin, (list, tuple, np.ndarray)):
 *             raise ValueError('origin must be a list, tuple or numpy array')             # <<<<<<<<<<<<<<
 *         self._origin = np.asarray(origin, dtype=np.float64)
 *         cdef int_t dim = self._origin.shape[0]
 */
    __Pyx_TraceLine(1111,0,__PYX_ERR(0, 1111, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1111, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 1111, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":1110
 * 
 *     def _set_origin(self, origin):
 *         if not isinstance(origin, (list, tuple, np.ndarray)):             # <<<<<<<<<<<<<<
 *             raise ValueError('origin must be a list, tuple or numpy array')
 *         self._origin = np.asarray(origin, dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1112
 *         if not isinstance(origin, (list, tuple, np.ndarray)):
 *             raise ValueError('origin must be a list, tuple or numpy array')
 *         self._origin = np.asarray(origin, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int_t dim = self._origin.shape[0]
 *         cdef double[:] shift
 */
  __Pyx_TraceLine(1112,0,__PYX_ERR(0, 1112, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_asarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_origin);
  __Pyx_GIVEREF(__pyx_v_origin);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_origin);
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1112, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __PYX_XDEC_MEMVIEW(&__pyx_v_self->_origin, 0);
  __pyx_v_self->_origin = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":1113
 *             raise ValueError('origin must be a list, tuple or numpy array')
 *         self._origin = np.asarray(origin, dtype=np.float64)
 *         cdef int_t dim = self._origin.shape[0]             # <<<<<<<<<<<<<<
 *         cdef double[:] shift
 *         #cdef c_Cell *cell
 */
  __Pyx_TraceLine(1113,0,__PYX_ERR(0, 1113, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1113, __pyx_L1_error)}
  __pyx_v_dim = (__pyx_v_self->_origin.shape[0]);

  /* "discretize/_extensions/tree_ext.pyx":1119
 *         cdef Edge *edge
 *         cdef Face *face
 *         if self.tree.n_dim > 0: # Will only happen if __init__ has been called             # <<<<<<<<<<<<<<
 *             shift = np.empty(dim, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(1119,0,__PYX_ERR(0, 1119, __pyx_L1_error))
  __pyx_t_3 = ((__pyx_v_self->tree->n_dim > 0) != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":1120
 *         cdef Face *face
 *         if self.tree.n_dim > 0: # Will only happen if __init__ has been called
 *             shift = np.empty(dim, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             shift[0] = self._origin[0] - self._xs[0]
 */
    __Pyx_TraceLine(1120,0,__PYX_ERR(0, 1120, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_dim); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1120, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_shift = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1122
 *             shift = np.empty(dim, dtype=np.float64)
 * 
 *             shift[0] = self._origin[0] - self._xs[0]             # <<<<<<<<<<<<<<
 *             shift[1] = self._origin[1] - self._ys[0]
 *             if dim == 3:
 */
    __Pyx_TraceLine(1122,0,__PYX_ERR(0, 1122, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1122, __pyx_L1_error)}
    __pyx_t_10 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_self->_origin.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_origin.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1122, __pyx_L1_error)
    }
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1122, __pyx_L1_error)}
    __pyx_t_12 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_self->_xs.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_self->_xs.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1122, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_shift.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1122, __pyx_L1_error)
    }
    *((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_13 * __pyx_v_shift.strides[0]) )) = ((*((double *) ( /* dim=0 */ (__pyx_v_self->_origin.data + __pyx_t_10 * __pyx_v_self->_origin.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_12 * __pyx_v_self->_xs.strides[0]) ))));

    /* "discretize/_extensions/tree_ext.pyx":1123
 * 
 *             shift[0] = self._origin[0] - self._xs[0]
 *             shift[1] = self._origin[1] - self._ys[0]             # <<<<<<<<<<<<<<
 *             if dim == 3:
 *                 shift[2] = self._origin[2] - self._zs[0]
 */
    __Pyx_TraceLine(1123,0,__PYX_ERR(0, 1123, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1123, __pyx_L1_error)}
    __pyx_t_12 = 1;
    __pyx_t_11 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_self->_origin.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_self->_origin.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1123, __pyx_L1_error)
    }
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1123, __pyx_L1_error)}
    __pyx_t_10 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_self->_ys.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_ys.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1123, __pyx_L1_error)
    }
    __pyx_t_13 = 1;
    __pyx_t_11 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_shift.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1123, __pyx_L1_error)
    }
    *((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_13 * __pyx_v_shift.strides[0]) )) = ((*((double *) ( /* dim=0 */ (__pyx_v_self->_origin.data + __pyx_t_12 * __pyx_v_self->_origin.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_10 * __pyx_v_self->_ys.strides[0]) ))));

    /* "discretize/_extensions/tree_ext.pyx":1124
 *             shift[0] = self._origin[0] - self._xs[0]
 *             shift[1] = self._origin[1] - self._ys[0]
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 shift[2] = self._origin[2] - self._zs[0]
 * 
 */
    __Pyx_TraceLine(1124,0,__PYX_ERR(0, 1124, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":1125
 *             shift[1] = self._origin[1] - self._ys[0]
 *             if dim == 3:
 *                 shift[2] = self._origin[2] - self._zs[0]             # <<<<<<<<<<<<<<
 * 
 *             for i in range(self._xs.shape[0]):
 */
      __Pyx_TraceLine(1125,0,__PYX_ERR(0, 1125, __pyx_L1_error))
      if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1125, __pyx_L1_error)}
      __pyx_t_10 = 2;
      __pyx_t_11 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_self->_origin.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_origin.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1125, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1125, __pyx_L1_error)}
      __pyx_t_12 = 0;
      __pyx_t_11 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_self->_zs.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_self->_zs.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1125, __pyx_L1_error)
      }
      __pyx_t_13 = 2;
      __pyx_t_11 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_v_shift.shape[0];
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1125, __pyx_L1_error)
      }
      *((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_13 * __pyx_v_shift.strides[0]) )) = ((*((double *) ( /* dim=0 */ (__pyx_v_self->_origin.data + __pyx_t_10 * __pyx_v_self->_origin.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_12 * __pyx_v_self->_zs.strides[0]) ))));

      /* "discretize/_extensions/tree_ext.pyx":1124
 *             shift[0] = self._origin[0] - self._xs[0]
 *             shift[1] = self._origin[1] - self._ys[0]
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 shift[2] = self._origin[2] - self._zs[0]
 * 
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":1127
 *                 shift[2] = self._origin[2] - self._zs[0]
 * 
 *             for i in range(self._xs.shape[0]):             # <<<<<<<<<<<<<<
 *                 self._xs[i] += shift[0]
 *             for i in range(self._ys.shape[0]):
 */
    __Pyx_TraceLine(1127,0,__PYX_ERR(0, 1127, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1127, __pyx_L1_error)}
    __pyx_t_14 = (__pyx_v_self->_xs.shape[0]);
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_i = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":1128
 * 
 *             for i in range(self._xs.shape[0]):
 *                 self._xs[i] += shift[0]             # <<<<<<<<<<<<<<
 *             for i in range(self._ys.shape[0]):
 *                 self._ys[i] += shift[1]
 */
      __Pyx_TraceLine(1128,0,__PYX_ERR(0, 1128, __pyx_L1_error))
      __pyx_t_12 = 0;
      __pyx_t_11 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_shift.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1128, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1128, __pyx_L1_error)}
      __pyx_t_10 = __pyx_v_i;
      __pyx_t_11 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_self->_xs.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_xs.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1128, __pyx_L1_error)
      }
      *((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_10 * __pyx_v_self->_xs.strides[0]) )) += (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) )));
    }

    /* "discretize/_extensions/tree_ext.pyx":1129
 *             for i in range(self._xs.shape[0]):
 *                 self._xs[i] += shift[0]
 *             for i in range(self._ys.shape[0]):             # <<<<<<<<<<<<<<
 *                 self._ys[i] += shift[1]
 *             if dim == 3:
 */
    __Pyx_TraceLine(1129,0,__PYX_ERR(0, 1129, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1129, __pyx_L1_error)}
    __pyx_t_14 = (__pyx_v_self->_ys.shape[0]);
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_i = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":1130
 *                 self._xs[i] += shift[0]
 *             for i in range(self._ys.shape[0]):
 *                 self._ys[i] += shift[1]             # <<<<<<<<<<<<<<
 *             if dim == 3:
 *                 for i in range(self._zs.shape[0]):
 */
      __Pyx_TraceLine(1130,0,__PYX_ERR(0, 1130, __pyx_L1_error))
      __pyx_t_12 = 1;
      __pyx_t_11 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_shift.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1130, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1130, __pyx_L1_error)}
      __pyx_t_10 = __pyx_v_i;
      __pyx_t_11 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_self->_ys.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_ys.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 1130, __pyx_L1_error)
      }
      *((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_10 * __pyx_v_self->_ys.strides[0]) )) += (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) )));
    }

    /* "discretize/_extensions/tree_ext.pyx":1131
 *             for i in range(self._ys.shape[0]):
 *                 self._ys[i] += shift[1]
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 for i in range(self._zs.shape[0]):
 *                     self._zs[i] += shift[2]
 */
    __Pyx_TraceLine(1131,0,__PYX_ERR(0, 1131, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":1132
 *                 self._ys[i] += shift[1]
 *             if dim == 3:
 *                 for i in range(self._zs.shape[0]):             # <<<<<<<<<<<<<<
 *                     self._zs[i] += shift[2]
 * 
 */
      __Pyx_TraceLine(1132,0,__PYX_ERR(0, 1132, __pyx_L1_error))
      if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1132, __pyx_L1_error)}
      __pyx_t_14 = (__pyx_v_self->_zs.shape[0]);
      __pyx_t_15 = __pyx_t_14;
      for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
        __pyx_v_i = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":1133
 *             if dim == 3:
 *                 for i in range(self._zs.shape[0]):
 *                     self._zs[i] += shift[2]             # <<<<<<<<<<<<<<
 * 
 *             #update the locations of all of the items
 */
        __Pyx_TraceLine(1133,0,__PYX_ERR(0, 1133, __pyx_L1_error))
        __pyx_t_12 = 2;
        __pyx_t_11 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_shift.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 1133, __pyx_L1_error)
        }
        if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1133, __pyx_L1_error)}
        __pyx_t_10 = __pyx_v_i;
        __pyx_t_11 = -1;
        if (__pyx_t_10 < 0) {
          __pyx_t_10 += __pyx_v_self->_zs.shape[0];
          if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_10 >= __pyx_v_self->_zs.shape[0])) __pyx_t_11 = 0;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 1133, __pyx_L1_error)
        }
        *((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_10 * __pyx_v_self->_zs.strides[0]) )) += (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) )));
      }

      /* "discretize/_extensions/tree_ext.pyx":1131
 *             for i in range(self._ys.shape[0]):
 *                 self._ys[i] += shift[1]
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 for i in range(self._zs.shape[0]):
 *                     self._zs[i] += shift[2]
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":1136
 * 
 *             #update the locations of all of the items
 *             self.tree.shift_cell_centers(&shift[0])             # <<<<<<<<<<<<<<
 * 
 *             for itN in self.tree.nodes:
 */
    __Pyx_TraceLine(1136,0,__PYX_ERR(0, 1136, __pyx_L1_error))
    __pyx_t_12 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_shift.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 1136, __pyx_L1_error)
    }
    __pyx_v_self->tree->shift_cell_centers((&(*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) )))));

    /* "discretize/_extensions/tree_ext.pyx":1138
 *             self.tree.shift_cell_centers(&shift[0])
 * 
 *             for itN in self.tree.nodes:             # <<<<<<<<<<<<<<
 *                 node = itN.second
 *                 for i in range(dim):
 */
    __Pyx_TraceLine(1138,0,__PYX_ERR(0, 1138, __pyx_L1_error))
    __pyx_t_18 = &__pyx_v_self->tree->nodes;
    __pyx_t_17 = __pyx_t_18->begin();
    for (;;) {
      if (!(__pyx_t_17 != __pyx_t_18->end())) break;
      __pyx_t_19 = *__pyx_t_17;
      ++__pyx_t_17;
      __pyx_v_itN = __pyx_t_19;

      /* "discretize/_extensions/tree_ext.pyx":1139
 * 
 *             for itN in self.tree.nodes:
 *                 node = itN.second             # <<<<<<<<<<<<<<
 *                 for i in range(dim):
 *                     node.location[i] += shift[i]
 */
      __Pyx_TraceLine(1139,0,__PYX_ERR(0, 1139, __pyx_L1_error))
      __pyx_t_20 = __pyx_v_itN.second;
      __pyx_v_node = __pyx_t_20;

      /* "discretize/_extensions/tree_ext.pyx":1140
 *             for itN in self.tree.nodes:
 *                 node = itN.second
 *                 for i in range(dim):             # <<<<<<<<<<<<<<
 *                     node.location[i] += shift[i]
 * 
 */
      __Pyx_TraceLine(1140,0,__PYX_ERR(0, 1140, __pyx_L1_error))
      __pyx_t_21 = __pyx_v_dim;
      __pyx_t_22 = __pyx_t_21;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
        __pyx_v_i = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":1141
 *                 node = itN.second
 *                 for i in range(dim):
 *                     node.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *             for itE in self.tree.edges_x:
 */
        __Pyx_TraceLine(1141,0,__PYX_ERR(0, 1141, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_i;
        __pyx_t_12 = __pyx_v_i;
        __pyx_t_11 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_shift.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 1141, __pyx_L1_error)
        }
        (__pyx_v_node->location[__pyx_t_15]) = ((__pyx_v_node->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
      }

      /* "discretize/_extensions/tree_ext.pyx":1138
 *             self.tree.shift_cell_centers(&shift[0])
 * 
 *             for itN in self.tree.nodes:             # <<<<<<<<<<<<<<
 *                 node = itN.second
 *                 for i in range(dim):
 */
      __Pyx_TraceLine(1138,0,__PYX_ERR(0, 1138, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1143
 *                     node.location[i] += shift[i]
 * 
 *             for itE in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = itE.second
 *                 for i in range(dim):
 */
    __Pyx_TraceLine(1143,0,__PYX_ERR(0, 1143, __pyx_L1_error))
    __pyx_t_24 = &__pyx_v_self->tree->edges_x;
    __pyx_t_23 = __pyx_t_24->begin();
    for (;;) {
      if (!(__pyx_t_23 != __pyx_t_24->end())) break;
      __pyx_t_25 = *__pyx_t_23;
      ++__pyx_t_23;
      __pyx_v_itE = __pyx_t_25;

      /* "discretize/_extensions/tree_ext.pyx":1144
 * 
 *             for itE in self.tree.edges_x:
 *                 edge = itE.second             # <<<<<<<<<<<<<<
 *                 for i in range(dim):
 *                     edge.location[i] += shift[i]
 */
      __Pyx_TraceLine(1144,0,__PYX_ERR(0, 1144, __pyx_L1_error))
      __pyx_t_26 = __pyx_v_itE.second;
      __pyx_v_edge = __pyx_t_26;

      /* "discretize/_extensions/tree_ext.pyx":1145
 *             for itE in self.tree.edges_x:
 *                 edge = itE.second
 *                 for i in range(dim):             # <<<<<<<<<<<<<<
 *                     edge.location[i] += shift[i]
 * 
 */
      __Pyx_TraceLine(1145,0,__PYX_ERR(0, 1145, __pyx_L1_error))
      __pyx_t_21 = __pyx_v_dim;
      __pyx_t_22 = __pyx_t_21;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
        __pyx_v_i = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":1146
 *                 edge = itE.second
 *                 for i in range(dim):
 *                     edge.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *             for itE in self.tree.edges_y:
 */
        __Pyx_TraceLine(1146,0,__PYX_ERR(0, 1146, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_i;
        __pyx_t_12 = __pyx_v_i;
        __pyx_t_11 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_shift.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 1146, __pyx_L1_error)
        }
        (__pyx_v_edge->location[__pyx_t_15]) = ((__pyx_v_edge->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
      }

      /* "discretize/_extensions/tree_ext.pyx":1143
 *                     node.location[i] += shift[i]
 * 
 *             for itE in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = itE.second
 *                 for i in range(dim):
 */
      __Pyx_TraceLine(1143,0,__PYX_ERR(0, 1143, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1148
 *                     edge.location[i] += shift[i]
 * 
 *             for itE in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = itE.second
 *                 for i in range(dim):
 */
    __Pyx_TraceLine(1148,0,__PYX_ERR(0, 1148, __pyx_L1_error))
    __pyx_t_24 = &__pyx_v_self->tree->edges_y;
    __pyx_t_23 = __pyx_t_24->begin();
    for (;;) {
      if (!(__pyx_t_23 != __pyx_t_24->end())) break;
      __pyx_t_25 = *__pyx_t_23;
      ++__pyx_t_23;
      __pyx_v_itE = __pyx_t_25;

      /* "discretize/_extensions/tree_ext.pyx":1149
 * 
 *             for itE in self.tree.edges_y:
 *                 edge = itE.second             # <<<<<<<<<<<<<<
 *                 for i in range(dim):
 *                     edge.location[i] += shift[i]
 */
      __Pyx_TraceLine(1149,0,__PYX_ERR(0, 1149, __pyx_L1_error))
      __pyx_t_26 = __pyx_v_itE.second;
      __pyx_v_edge = __pyx_t_26;

      /* "discretize/_extensions/tree_ext.pyx":1150
 *             for itE in self.tree.edges_y:
 *                 edge = itE.second
 *                 for i in range(dim):             # <<<<<<<<<<<<<<
 *                     edge.location[i] += shift[i]
 * 
 */
      __Pyx_TraceLine(1150,0,__PYX_ERR(0, 1150, __pyx_L1_error))
      __pyx_t_21 = __pyx_v_dim;
      __pyx_t_22 = __pyx_t_21;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
        __pyx_v_i = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":1151
 *                 edge = itE.second
 *                 for i in range(dim):
 *                     edge.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *             if dim == 3:
 */
        __Pyx_TraceLine(1151,0,__PYX_ERR(0, 1151, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_i;
        __pyx_t_12 = __pyx_v_i;
        __pyx_t_11 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_shift.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
        if (unlikely(__pyx_t_11 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_11);
          __PYX_ERR(0, 1151, __pyx_L1_error)
        }
        (__pyx_v_edge->location[__pyx_t_15]) = ((__pyx_v_edge->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
      }

      /* "discretize/_extensions/tree_ext.pyx":1148
 *                     edge.location[i] += shift[i]
 * 
 *             for itE in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = itE.second
 *                 for i in range(dim):
 */
      __Pyx_TraceLine(1148,0,__PYX_ERR(0, 1148, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1153
 *                     edge.location[i] += shift[i]
 * 
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 for itE in self.tree.edges_z:
 *                     edge = itE.second
 */
    __Pyx_TraceLine(1153,0,__PYX_ERR(0, 1153, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":1154
 * 
 *             if dim == 3:
 *                 for itE in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                     edge = itE.second
 *                     for i in range(dim):
 */
      __Pyx_TraceLine(1154,0,__PYX_ERR(0, 1154, __pyx_L1_error))
      __pyx_t_24 = &__pyx_v_self->tree->edges_z;
      __pyx_t_23 = __pyx_t_24->begin();
      for (;;) {
        if (!(__pyx_t_23 != __pyx_t_24->end())) break;
        __pyx_t_25 = *__pyx_t_23;
        ++__pyx_t_23;
        __pyx_v_itE = __pyx_t_25;

        /* "discretize/_extensions/tree_ext.pyx":1155
 *             if dim == 3:
 *                 for itE in self.tree.edges_z:
 *                     edge = itE.second             # <<<<<<<<<<<<<<
 *                     for i in range(dim):
 *                         edge.location[i] += shift[i]
 */
        __Pyx_TraceLine(1155,0,__PYX_ERR(0, 1155, __pyx_L1_error))
        __pyx_t_26 = __pyx_v_itE.second;
        __pyx_v_edge = __pyx_t_26;

        /* "discretize/_extensions/tree_ext.pyx":1156
 *                 for itE in self.tree.edges_z:
 *                     edge = itE.second
 *                     for i in range(dim):             # <<<<<<<<<<<<<<
 *                         edge.location[i] += shift[i]
 * 
 */
        __Pyx_TraceLine(1156,0,__PYX_ERR(0, 1156, __pyx_L1_error))
        __pyx_t_21 = __pyx_v_dim;
        __pyx_t_22 = __pyx_t_21;
        for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
          __pyx_v_i = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":1157
 *                     edge = itE.second
 *                     for i in range(dim):
 *                         edge.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *                 for itF in self.tree.faces_x:
 */
          __Pyx_TraceLine(1157,0,__PYX_ERR(0, 1157, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_i;
          __pyx_t_12 = __pyx_v_i;
          __pyx_t_11 = -1;
          if (__pyx_t_12 < 0) {
            __pyx_t_12 += __pyx_v_shift.shape[0];
            if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 1157, __pyx_L1_error)
          }
          (__pyx_v_edge->location[__pyx_t_15]) = ((__pyx_v_edge->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
        }

        /* "discretize/_extensions/tree_ext.pyx":1154
 * 
 *             if dim == 3:
 *                 for itE in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                     edge = itE.second
 *                     for i in range(dim):
 */
        __Pyx_TraceLine(1154,0,__PYX_ERR(0, 1154, __pyx_L1_error))
      }

      /* "discretize/_extensions/tree_ext.pyx":1159
 *                         edge.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
      __Pyx_TraceLine(1159,0,__PYX_ERR(0, 1159, __pyx_L1_error))
      __pyx_t_28 = &__pyx_v_self->tree->faces_x;
      __pyx_t_27 = __pyx_t_28->begin();
      for (;;) {
        if (!(__pyx_t_27 != __pyx_t_28->end())) break;
        __pyx_t_29 = *__pyx_t_27;
        ++__pyx_t_27;
        __pyx_v_itF = __pyx_t_29;

        /* "discretize/_extensions/tree_ext.pyx":1160
 * 
 *                 for itF in self.tree.faces_x:
 *                     face = itF.second             # <<<<<<<<<<<<<<
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]
 */
        __Pyx_TraceLine(1160,0,__PYX_ERR(0, 1160, __pyx_L1_error))
        __pyx_t_30 = __pyx_v_itF.second;
        __pyx_v_face = __pyx_t_30;

        /* "discretize/_extensions/tree_ext.pyx":1161
 *                 for itF in self.tree.faces_x:
 *                     face = itF.second
 *                     for i in range(dim):             # <<<<<<<<<<<<<<
 *                         face.location[i] += shift[i]
 * 
 */
        __Pyx_TraceLine(1161,0,__PYX_ERR(0, 1161, __pyx_L1_error))
        __pyx_t_21 = __pyx_v_dim;
        __pyx_t_22 = __pyx_t_21;
        for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
          __pyx_v_i = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":1162
 *                     face = itF.second
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *                 for itF in self.tree.faces_y:
 */
          __Pyx_TraceLine(1162,0,__PYX_ERR(0, 1162, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_i;
          __pyx_t_12 = __pyx_v_i;
          __pyx_t_11 = -1;
          if (__pyx_t_12 < 0) {
            __pyx_t_12 += __pyx_v_shift.shape[0];
            if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 1162, __pyx_L1_error)
          }
          (__pyx_v_face->location[__pyx_t_15]) = ((__pyx_v_face->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
        }

        /* "discretize/_extensions/tree_ext.pyx":1159
 *                         edge.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
        __Pyx_TraceLine(1159,0,__PYX_ERR(0, 1159, __pyx_L1_error))
      }

      /* "discretize/_extensions/tree_ext.pyx":1164
 *                         face.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
      __Pyx_TraceLine(1164,0,__PYX_ERR(0, 1164, __pyx_L1_error))
      __pyx_t_28 = &__pyx_v_self->tree->faces_y;
      __pyx_t_27 = __pyx_t_28->begin();
      for (;;) {
        if (!(__pyx_t_27 != __pyx_t_28->end())) break;
        __pyx_t_29 = *__pyx_t_27;
        ++__pyx_t_27;
        __pyx_v_itF = __pyx_t_29;

        /* "discretize/_extensions/tree_ext.pyx":1165
 * 
 *                 for itF in self.tree.faces_y:
 *                     face = itF.second             # <<<<<<<<<<<<<<
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]
 */
        __Pyx_TraceLine(1165,0,__PYX_ERR(0, 1165, __pyx_L1_error))
        __pyx_t_30 = __pyx_v_itF.second;
        __pyx_v_face = __pyx_t_30;

        /* "discretize/_extensions/tree_ext.pyx":1166
 *                 for itF in self.tree.faces_y:
 *                     face = itF.second
 *                     for i in range(dim):             # <<<<<<<<<<<<<<
 *                         face.location[i] += shift[i]
 * 
 */
        __Pyx_TraceLine(1166,0,__PYX_ERR(0, 1166, __pyx_L1_error))
        __pyx_t_21 = __pyx_v_dim;
        __pyx_t_22 = __pyx_t_21;
        for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
          __pyx_v_i = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":1167
 *                     face = itF.second
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]             # <<<<<<<<<<<<<<
 * 
 *                 for itF in self.tree.faces_z:
 */
          __Pyx_TraceLine(1167,0,__PYX_ERR(0, 1167, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_i;
          __pyx_t_12 = __pyx_v_i;
          __pyx_t_11 = -1;
          if (__pyx_t_12 < 0) {
            __pyx_t_12 += __pyx_v_shift.shape[0];
            if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 1167, __pyx_L1_error)
          }
          (__pyx_v_face->location[__pyx_t_15]) = ((__pyx_v_face->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
        }

        /* "discretize/_extensions/tree_ext.pyx":1164
 *                         face.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
        __Pyx_TraceLine(1164,0,__PYX_ERR(0, 1164, __pyx_L1_error))
      }

      /* "discretize/_extensions/tree_ext.pyx":1169
 *                         face.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
      __Pyx_TraceLine(1169,0,__PYX_ERR(0, 1169, __pyx_L1_error))
      __pyx_t_28 = &__pyx_v_self->tree->faces_z;
      __pyx_t_27 = __pyx_t_28->begin();
      for (;;) {
        if (!(__pyx_t_27 != __pyx_t_28->end())) break;
        __pyx_t_29 = *__pyx_t_27;
        ++__pyx_t_27;
        __pyx_v_itF = __pyx_t_29;

        /* "discretize/_extensions/tree_ext.pyx":1170
 * 
 *                 for itF in self.tree.faces_z:
 *                     face = itF.second             # <<<<<<<<<<<<<<
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]
 */
        __Pyx_TraceLine(1170,0,__PYX_ERR(0, 1170, __pyx_L1_error))
        __pyx_t_30 = __pyx_v_itF.second;
        __pyx_v_face = __pyx_t_30;

        /* "discretize/_extensions/tree_ext.pyx":1171
 *                 for itF in self.tree.faces_z:
 *                     face = itF.second
 *                     for i in range(dim):             # <<<<<<<<<<<<<<
 *                         face.location[i] += shift[i]
 *             #clear out all cached grids
 */
        __Pyx_TraceLine(1171,0,__PYX_ERR(0, 1171, __pyx_L1_error))
        __pyx_t_21 = __pyx_v_dim;
        __pyx_t_22 = __pyx_t_21;
        for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_22; __pyx_t_14+=1) {
          __pyx_v_i = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":1172
 *                     face = itF.second
 *                     for i in range(dim):
 *                         face.location[i] += shift[i]             # <<<<<<<<<<<<<<
 *             #clear out all cached grids
 *             self._cell_centers = None
 */
          __Pyx_TraceLine(1172,0,__PYX_ERR(0, 1172, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_i;
          __pyx_t_12 = __pyx_v_i;
          __pyx_t_11 = -1;
          if (__pyx_t_12 < 0) {
            __pyx_t_12 += __pyx_v_shift.shape[0];
            if (unlikely(__pyx_t_12 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_12 >= __pyx_v_shift.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 1172, __pyx_L1_error)
          }
          (__pyx_v_face->location[__pyx_t_15]) = ((__pyx_v_face->location[__pyx_t_15]) + (*((double *) ( /* dim=0 */ (__pyx_v_shift.data + __pyx_t_12 * __pyx_v_shift.strides[0]) ))));
        }

        /* "discretize/_extensions/tree_ext.pyx":1169
 *                         face.location[i] += shift[i]
 * 
 *                 for itF in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                     face = itF.second
 *                     for i in range(dim):
 */
        __Pyx_TraceLine(1169,0,__PYX_ERR(0, 1169, __pyx_L1_error))
      }

      /* "discretize/_extensions/tree_ext.pyx":1153
 *                     edge.location[i] += shift[i]
 * 
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 for itE in self.tree.edges_z:
 *                     edge = itE.second
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":1174
 *                         face.location[i] += shift[i]
 *             #clear out all cached grids
 *             self._cell_centers = None             # <<<<<<<<<<<<<<
 *             self._nodes = None
 *             self._hanging_nodes = None
 */
    __Pyx_TraceLine(1174,0,__PYX_ERR(0, 1174, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_cell_centers);
    __Pyx_DECREF(__pyx_v_self->_cell_centers);
    __pyx_v_self->_cell_centers = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1175
 *             #clear out all cached grids
 *             self._cell_centers = None
 *             self._nodes = None             # <<<<<<<<<<<<<<
 *             self._hanging_nodes = None
 *             self._edges_x = None
 */
    __Pyx_TraceLine(1175,0,__PYX_ERR(0, 1175, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_nodes);
    __Pyx_DECREF(__pyx_v_self->_nodes);
    __pyx_v_self->_nodes = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1176
 *             self._cell_centers = None
 *             self._nodes = None
 *             self._hanging_nodes = None             # <<<<<<<<<<<<<<
 *             self._edges_x = None
 *             self._hanging_edges_x = None
 */
    __Pyx_TraceLine(1176,0,__PYX_ERR(0, 1176, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_nodes);
    __Pyx_DECREF(__pyx_v_self->_hanging_nodes);
    __pyx_v_self->_hanging_nodes = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1177
 *             self._nodes = None
 *             self._hanging_nodes = None
 *             self._edges_x = None             # <<<<<<<<<<<<<<
 *             self._hanging_edges_x = None
 *             self._edges_y = None
 */
    __Pyx_TraceLine(1177,0,__PYX_ERR(0, 1177, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_edges_x);
    __Pyx_DECREF(__pyx_v_self->_edges_x);
    __pyx_v_self->_edges_x = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1178
 *             self._hanging_nodes = None
 *             self._edges_x = None
 *             self._hanging_edges_x = None             # <<<<<<<<<<<<<<
 *             self._edges_y = None
 *             self._hanging_edges_y = None
 */
    __Pyx_TraceLine(1178,0,__PYX_ERR(0, 1178, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_x);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_x);
    __pyx_v_self->_hanging_edges_x = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1179
 *             self._edges_x = None
 *             self._hanging_edges_x = None
 *             self._edges_y = None             # <<<<<<<<<<<<<<
 *             self._hanging_edges_y = None
 *             self._edges_z = None
 */
    __Pyx_TraceLine(1179,0,__PYX_ERR(0, 1179, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_edges_y);
    __Pyx_DECREF(__pyx_v_self->_edges_y);
    __pyx_v_self->_edges_y = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1180
 *             self._hanging_edges_x = None
 *             self._edges_y = None
 *             self._hanging_edges_y = None             # <<<<<<<<<<<<<<
 *             self._edges_z = None
 *             self._hanging_edges_z = None
 */
    __Pyx_TraceLine(1180,0,__PYX_ERR(0, 1180, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_y);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_y);
    __pyx_v_self->_hanging_edges_y = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1181
 *             self._edges_y = None
 *             self._hanging_edges_y = None
 *             self._edges_z = None             # <<<<<<<<<<<<<<
 *             self._hanging_edges_z = None
 *             self._faces_x = None
 */
    __Pyx_TraceLine(1181,0,__PYX_ERR(0, 1181, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_edges_z);
    __Pyx_DECREF(__pyx_v_self->_edges_z);
    __pyx_v_self->_edges_z = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1182
 *             self._hanging_edges_y = None
 *             self._edges_z = None
 *             self._hanging_edges_z = None             # <<<<<<<<<<<<<<
 *             self._faces_x = None
 *             self._hanging_faces_x = None
 */
    __Pyx_TraceLine(1182,0,__PYX_ERR(0, 1182, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_z);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_z);
    __pyx_v_self->_hanging_edges_z = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1183
 *             self._edges_z = None
 *             self._hanging_edges_z = None
 *             self._faces_x = None             # <<<<<<<<<<<<<<
 *             self._hanging_faces_x = None
 *             self._faces_y = None
 */
    __Pyx_TraceLine(1183,0,__PYX_ERR(0, 1183, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_faces_x);
    __Pyx_DECREF(__pyx_v_self->_faces_x);
    __pyx_v_self->_faces_x = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1184
 *             self._hanging_edges_z = None
 *             self._faces_x = None
 *             self._hanging_faces_x = None             # <<<<<<<<<<<<<<
 *             self._faces_y = None
 *             self._hanging_faces_y = None
 */
    __Pyx_TraceLine(1184,0,__PYX_ERR(0, 1184, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_x);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_x);
    __pyx_v_self->_hanging_faces_x = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1185
 *             self._faces_x = None
 *             self._hanging_faces_x = None
 *             self._faces_y = None             # <<<<<<<<<<<<<<
 *             self._hanging_faces_y = None
 *             self._faces_z = None
 */
    __Pyx_TraceLine(1185,0,__PYX_ERR(0, 1185, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_faces_y);
    __Pyx_DECREF(__pyx_v_self->_faces_y);
    __pyx_v_self->_faces_y = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1186
 *             self._hanging_faces_x = None
 *             self._faces_y = None
 *             self._hanging_faces_y = None             # <<<<<<<<<<<<<<
 *             self._faces_z = None
 *             self._hanging_faces_z = None
 */
    __Pyx_TraceLine(1186,0,__PYX_ERR(0, 1186, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_y);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_y);
    __pyx_v_self->_hanging_faces_y = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1187
 *             self._faces_y = None
 *             self._hanging_faces_y = None
 *             self._faces_z = None             # <<<<<<<<<<<<<<
 *             self._hanging_faces_z = None
 * 
 */
    __Pyx_TraceLine(1187,0,__PYX_ERR(0, 1187, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_faces_z);
    __Pyx_DECREF(__pyx_v_self->_faces_z);
    __pyx_v_self->_faces_z = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1188
 *             self._hanging_faces_y = None
 *             self._faces_z = None
 *             self._hanging_faces_z = None             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
    __Pyx_TraceLine(1188,0,__PYX_ERR(0, 1188, __pyx_L1_error))
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_z);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_z);
    __pyx_v_self->_hanging_faces_z = Py_None;

    /* "discretize/_extensions/tree_ext.pyx":1119
 *         cdef Edge *edge
 *         cdef Face *face
 *         if self.tree.n_dim > 0: # Will only happen if __init__ has been called             # <<<<<<<<<<<<<<
 *             shift = np.empty(dim, dtype=np.float64)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1109
 *         self.tree.number()
 * 
 *     def _set_origin(self, origin):             # <<<<<<<<<<<<<<
 *         if not isinstance(origin, (list, tuple, np.ndarray)):
 *             raise ValueError('origin must be a list, tuple or numpy array')
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._set_origin", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shift, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1191
 * 
 *     @property
 *     def fill(self):             # <<<<<<<<<<<<<<
 *         """How 'filled' the tree mesh is compared to the underlying tensor mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int_t __pyx_v_nxc;
  int_t __pyx_v_nyc;
  int_t __pyx_v_nzc;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  double __pyx_t_3;
  int_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1191, 0, __PYX_ERR(0, 1191, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1206
 *         #Tensor mesh cells:
 *         cdef int_t nxc, nyc, nzc;
 *         nxc = (self._xs.shape[0]-1)//2             # <<<<<<<<<<<<<<
 *         nyc = (self._ys.shape[0]-1)//2
 *         nzc = (self._zs.shape[0]-1)//2 if self._dim==3 else 1
 */
  __Pyx_TraceLine(1206,0,__PYX_ERR(0, 1206, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1206, __pyx_L1_error)}
  __pyx_v_nxc = __Pyx_div_Py_ssize_t(((__pyx_v_self->_xs.shape[0]) - 1), 2);

  /* "discretize/_extensions/tree_ext.pyx":1207
 *         cdef int_t nxc, nyc, nzc;
 *         nxc = (self._xs.shape[0]-1)//2
 *         nyc = (self._ys.shape[0]-1)//2             # <<<<<<<<<<<<<<
 *         nzc = (self._zs.shape[0]-1)//2 if self._dim==3 else 1
 *         return float(self.n_cells)/(nxc * nyc * nzc)
 */
  __Pyx_TraceLine(1207,0,__PYX_ERR(0, 1207, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1207, __pyx_L1_error)}
  __pyx_v_nyc = __Pyx_div_Py_ssize_t(((__pyx_v_self->_ys.shape[0]) - 1), 2);

  /* "discretize/_extensions/tree_ext.pyx":1208
 *         nxc = (self._xs.shape[0]-1)//2
 *         nyc = (self._ys.shape[0]-1)//2
 *         nzc = (self._zs.shape[0]-1)//2 if self._dim==3 else 1             # <<<<<<<<<<<<<<
 *         return float(self.n_cells)/(nxc * nyc * nzc)
 * 
 */
  __Pyx_TraceLine(1208,0,__PYX_ERR(0, 1208, __pyx_L1_error))
  if (((__pyx_v_self->_dim == 3) != 0)) {
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1208, __pyx_L1_error)}
    __pyx_t_1 = __Pyx_div_Py_ssize_t(((__pyx_v_self->_zs.shape[0]) - 1), 2);
  } else {
    __pyx_t_1 = 1;
  }
  __pyx_v_nzc = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":1209
 *         nyc = (self._ys.shape[0]-1)//2
 *         nzc = (self._zs.shape[0]-1)//2 if self._dim==3 else 1
 *         return float(self.n_cells)/(nxc * nyc * nzc)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1209,0,__PYX_ERR(0, 1209, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_AsDouble(__pyx_t_2); if (unlikely(__pyx_t_3 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((__pyx_v_nxc * __pyx_v_nyc) * __pyx_v_nzc);
  if (unlikely(__pyx_t_4 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 1209, __pyx_L1_error)
  }
  __pyx_t_2 = PyFloat_FromDouble((__pyx_t_3 / ((double)__pyx_t_4))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1191
 * 
 *     @property
 *     def fill(self):             # <<<<<<<<<<<<<<
 *         """How 'filled' the tree mesh is compared to the underlying tensor mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.fill.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1212
 * 
 *     @property
 *     def max_used_level(self):             # <<<<<<<<<<<<<<
 *         """Maximum refinement level used.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int __pyx_v_level;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  std::vector<Cell *> ::iterator __pyx_t_1;
  std::vector<Cell *>  *__pyx_t_2;
  Cell *__pyx_t_3;
  int_t __pyx_t_4;
  int __pyx_t_5;
  int_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1212, 0, __PYX_ERR(0, 1212, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1224
 *             Maximum level used when refining the mesh
 *         """
 *         cdef int level = 0             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             level = max(level, cell.level)
 */
  __Pyx_TraceLine(1224,0,__PYX_ERR(0, 1224, __pyx_L1_error))
  __pyx_v_level = 0;

  /* "discretize/_extensions/tree_ext.pyx":1225
 *         """
 *         cdef int level = 0
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             level = max(level, cell.level)
 *         return level
 */
  __Pyx_TraceLine(1225,0,__PYX_ERR(0, 1225, __pyx_L1_error))
  __pyx_t_2 = &__pyx_v_self->tree->cells;
  __pyx_t_1 = __pyx_t_2->begin();
  for (;;) {
    if (!(__pyx_t_1 != __pyx_t_2->end())) break;
    __pyx_t_3 = *__pyx_t_1;
    ++__pyx_t_1;
    __pyx_v_cell = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1226
 *         cdef int level = 0
 *         for cell in self.tree.cells:
 *             level = max(level, cell.level)             # <<<<<<<<<<<<<<
 *         return level
 * 
 */
    __Pyx_TraceLine(1226,0,__PYX_ERR(0, 1226, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_cell->level;
    __pyx_t_5 = __pyx_v_level;
    if (((__pyx_t_4 > __pyx_t_5) != 0)) {
      __pyx_t_6 = __pyx_t_4;
    } else {
      __pyx_t_6 = __pyx_t_5;
    }
    __pyx_v_level = __pyx_t_6;

    /* "discretize/_extensions/tree_ext.pyx":1225
 *         """
 *         cdef int level = 0
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             level = max(level, cell.level)
 *         return level
 */
    __Pyx_TraceLine(1225,0,__PYX_ERR(0, 1225, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":1227
 *         for cell in self.tree.cells:
 *             level = max(level, cell.level)
 *         return level             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1227,0,__PYX_ERR(0, 1227, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_level); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1212
 * 
 *     @property
 *     def max_used_level(self):             # <<<<<<<<<<<<<<
 *         """Maximum refinement level used.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.max_used_level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1230
 * 
 *     @property
 *     def max_level(self):             # <<<<<<<<<<<<<<
 *         r"""Maximum allowable refinement level for the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1230, 0, __PYX_ERR(0, 1230, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1248
 * 
 *         """
 *         return self.tree.max_level             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1248,0,__PYX_ERR(0, 1248, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int_t(__pyx_v_self->tree->max_level); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1230
 * 
 *     @property
 *     def max_level(self):             # <<<<<<<<<<<<<<
 *         r"""Maximum allowable refinement level for the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.max_level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1251
 * 
 *     @property
 *     def n_cells(self):             # <<<<<<<<<<<<<<
 *         """Total number of cells in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1251, 0, __PYX_ERR(0, 1251, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1263
 *         Property also accessible as using the shorthand **nC**
 *         """
 *         return self.tree.cells.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1263,0,__PYX_ERR(0, 1263, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->cells.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1263, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1251
 * 
 *     @property
 *     def n_cells(self):             # <<<<<<<<<<<<<<
 *         """Total number of cells in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_cells.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1266
 * 
 *     @property
 *     def n_nodes(self):             # <<<<<<<<<<<<<<
 *         """Total number of nodes in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1266, 0, __PYX_ERR(0, 1266, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1278
 *         Property also accessible as using the shorthand **nN**
 *         """
 *         return self.n_total_nodes - self.n_hanging_nodes             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1278,0,__PYX_ERR(0, 1278, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_nodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1266
 * 
 *     @property
 *     def n_nodes(self):             # <<<<<<<<<<<<<<
 *         """Total number of nodes in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1281
 * 
 *     @property
 *     def n_total_nodes(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging nodes.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1281, 0, __PYX_ERR(0, 1281, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1289
 *             Number of hanging and non-hanging nodes
 *         """
 *         return self.tree.nodes.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1289,0,__PYX_ERR(0, 1289, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->nodes.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1281
 * 
 *     @property
 *     def n_total_nodes(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging nodes.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1292
 * 
 *     @property
 *     def n_hanging_nodes(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging nodes.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1292, 0, __PYX_ERR(0, 1292, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1300
 *             Number of hanging nodes
 *         """
 *         return self.tree.hanging_nodes.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1300,0,__PYX_ERR(0, 1300, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_nodes.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1292
 * 
 *     @property
 *     def n_hanging_nodes(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging nodes.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1303
 * 
 *     @property
 *     def n_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1303, 0, __PYX_ERR(0, 1303, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1315
 *         Property also accessible as using the shorthand **nE**
 *         """
 *         return self.n_edges_x + self.n_edges_y + self.n_edges_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1315,0,__PYX_ERR(0, 1315, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1303
 * 
 *     @property
 *     def n_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1318
 * 
 *     @property
 *     def n_hanging_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging edges in all dimensions.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1318, 0, __PYX_ERR(0, 1318, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1326
 *             Number of hanging edges in all dimensions
 *         """
 *         return self.n_hanging_edges_x + self.n_hanging_edges_y + self.n_hanging_edges_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1326,0,__PYX_ERR(0, 1326, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1326, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1318
 * 
 *     @property
 *     def n_hanging_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging edges in all dimensions.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1329
 * 
 *     @property
 *     def n_total_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging and non-hanging edges in all dimensions.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1329, 0, __PYX_ERR(0, 1329, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1337
 *             Number of hanging and non-hanging edges in all dimensions
 *         """
 *         return self.n_edges + self.n_hanging_edges             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1337,0,__PYX_ERR(0, 1337, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1329
 * 
 *     @property
 *     def n_total_edges(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging and non-hanging edges in all dimensions.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1340
 * 
 *     @property
 *     def n_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of x-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1340, 0, __PYX_ERR(0, 1340, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1355
 *         Property also accessible as using the shorthand **nEx**
 *         """
 *         return self.n_total_edges_x - self.n_hanging_edges_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1355,0,__PYX_ERR(0, 1355, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1340
 * 
 *     @property
 *     def n_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of x-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_edges_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1358
 * 
 *     @property
 *     def n_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of y-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1358, 0, __PYX_ERR(0, 1358, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1373
 *         Property also accessible as using the shorthand **nEy**
 *         """
 *         return self.n_total_edges_y - self.n_hanging_edges_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1373,0,__PYX_ERR(0, 1373, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1373, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1373, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1358
 * 
 *     @property
 *     def n_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of y-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_edges_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1376
 * 
 *     @property
 *     def n_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of z-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1376, 0, __PYX_ERR(0, 1376, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1391
 *         Property also accessible as using the shorthand **nEz**
 *         """
 *         return self.n_total_edges_z - self.n_hanging_edges_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1391,0,__PYX_ERR(0, 1391, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1376
 * 
 *     @property
 *     def n_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of z-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_edges_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1394
 * 
 *     @property
 *     def n_total_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging x-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1394, 0, __PYX_ERR(0, 1394, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1402
 *             Number of hanging and non-hanging x-edges in the mesh
 *         """
 *         return self.tree.edges_x.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1402,0,__PYX_ERR(0, 1402, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->edges_x.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1394
 * 
 *     @property
 *     def n_total_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging x-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_edges_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1405
 * 
 *     @property
 *     def n_total_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging y-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1405, 0, __PYX_ERR(0, 1405, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1413
 *             Number of hanging and non-hanging y-edges in the mesh
 *         """
 *         return self.tree.edges_y.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1413,0,__PYX_ERR(0, 1413, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->edges_y.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1413, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1405
 * 
 *     @property
 *     def n_total_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging y-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_edges_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1416
 * 
 *     @property
 *     def n_total_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging z-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1416, 0, __PYX_ERR(0, 1416, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1424
 *             Number of hanging and non-hanging z-edges in the mesh
 *         """
 *         return self.tree.edges_z.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1424,0,__PYX_ERR(0, 1424, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->edges_z.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1416
 * 
 *     @property
 *     def n_total_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging z-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_edges_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1427
 * 
 *     @property
 *     def n_hanging_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging x-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1427, 0, __PYX_ERR(0, 1427, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1435
 *             Number of hanging x-edges in the mesh
 *         """
 *         return self.tree.hanging_edges_x.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1435,0,__PYX_ERR(0, 1435, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_edges_x.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1427
 * 
 *     @property
 *     def n_hanging_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging x-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_edges_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1438
 * 
 *     @property
 *     def n_hanging_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging y-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1438, 0, __PYX_ERR(0, 1438, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1446
 *             Number of hanging y-edges in the mesh
 *         """
 *         return self.tree.hanging_edges_y.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1446,0,__PYX_ERR(0, 1446, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_edges_y.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1446, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1438
 * 
 *     @property
 *     def n_hanging_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging y-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_edges_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1449
 * 
 *     @property
 *     def n_hanging_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging z-edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1449, 0, __PYX_ERR(0, 1449, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1457
 *             Number of hanging z-edges in the mesh
 *         """
 *         return self.tree.hanging_edges_z.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1457,0,__PYX_ERR(0, 1457, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_edges_z.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1449
 * 
 *     @property
 *     def n_hanging_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging z-edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_edges_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1460
 * 
 *     @property
 *     def n_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1460, 0, __PYX_ERR(0, 1460, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1472
 *         Property also accessible as using the shorthand **nF**
 *         """
 *         return self.n_faces_x + self.n_faces_y + self.n_faces_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1472,0,__PYX_ERR(0, 1472, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1460
 * 
 *     @property
 *     def n_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_faces.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1475
 * 
 *     @property
 *     def n_hanging_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1475, 0, __PYX_ERR(0, 1475, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1483
 *             Total number of non-hanging faces in the mesh
 *         """
 *         return self.n_hanging_faces_x + self.n_hanging_faces_y + self.n_hanging_faces_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1483,0,__PYX_ERR(0, 1483, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1475
 * 
 *     @property
 *     def n_hanging_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_faces.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1486
 * 
 *     @property
 *     def n_total_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging and non-hanging faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1486, 0, __PYX_ERR(0, 1486, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1494
 *             Total number of non-hanging faces in the mesh
 *         """
 *         return self.n_faces + self.n_hanging_faces             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1494,0,__PYX_ERR(0, 1494, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1486
 * 
 *     @property
 *     def n_total_faces(self):             # <<<<<<<<<<<<<<
 *         """Total number of hanging and non-hanging faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_faces.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1497
 * 
 *     @property
 *     def n_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of x-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1497, 0, __PYX_ERR(0, 1497, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1512
 *         Property also accessible as using the shorthand **nFx**
 *         """
 *         return self.n_total_faces_x - self.n_hanging_faces_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1512,0,__PYX_ERR(0, 1512, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1497
 * 
 *     @property
 *     def n_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of x-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_faces_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1515
 * 
 *     @property
 *     def n_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of y-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1515, 0, __PYX_ERR(0, 1515, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1530
 *         Property also accessible as using the shorthand **nFy**
 *         """
 *         return self.n_total_faces_y - self.n_hanging_faces_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1530,0,__PYX_ERR(0, 1530, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1515
 * 
 *     @property
 *     def n_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of y-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_faces_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1533
 * 
 *     @property
 *     def n_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of z-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1533, 0, __PYX_ERR(0, 1533, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1548
 *         Property also accessible as using the shorthand **nFz**
 *         """
 *         return self.n_total_faces_z - self.n_hanging_faces_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1548,0,__PYX_ERR(0, 1548, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1533
 * 
 *     @property
 *     def n_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of z-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_faces_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1551
 * 
 *     @property
 *     def n_total_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging x-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1551, 0, __PYX_ERR(0, 1551, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1559
 *             Number of hanging and non-hanging x-faces in the mesh
 *         """
 *         if(self._dim == 2): return self.n_total_edges_y             # <<<<<<<<<<<<<<
 *         return self.tree.faces_x.size()
 * 
 */
  __Pyx_TraceLine(1559,0,__PYX_ERR(0, 1559, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1559, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1560
 *         """
 *         if(self._dim == 2): return self.n_total_edges_y
 *         return self.tree.faces_x.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1560,0,__PYX_ERR(0, 1560, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->faces_x.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1551
 * 
 *     @property
 *     def n_total_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging x-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_faces_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1563
 * 
 *     @property
 *     def n_total_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging y-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1563, 0, __PYX_ERR(0, 1563, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1571
 *             Number of hanging and non-hanging y-faces in the mesh
 *         """
 *         if(self._dim == 2): return self.n_total_edges_x             # <<<<<<<<<<<<<<
 *         return self.tree.faces_y.size()
 * 
 */
  __Pyx_TraceLine(1571,0,__PYX_ERR(0, 1571, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1571, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1572
 *         """
 *         if(self._dim == 2): return self.n_total_edges_x
 *         return self.tree.faces_y.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1572,0,__PYX_ERR(0, 1572, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->faces_y.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1563
 * 
 *     @property
 *     def n_total_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging y-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_faces_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1575
 * 
 *     @property
 *     def n_total_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging z-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1575, 0, __PYX_ERR(0, 1575, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1583
 *             Number of hanging and non-hanging z-faces in the mesh
 *         """
 *         if(self._dim == 2): return 0             # <<<<<<<<<<<<<<
 *         return self.tree.faces_z.size()
 * 
 */
  __Pyx_TraceLine(1583,0,__PYX_ERR(0, 1583, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1584
 *         """
 *         if(self._dim == 2): return 0
 *         return self.tree.faces_z.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1584,0,__PYX_ERR(0, 1584, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->faces_z.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1575
 * 
 *     @property
 *     def n_total_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging and non-hanging z-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_total_faces_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1587
 * 
 *     @property
 *     def n_hanging_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging x-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1587, 0, __PYX_ERR(0, 1587, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1595
 *             Number of hanging x-faces in the mesh
 *         """
 *         if(self._dim == 2): return self.n_hanging_edges_y             # <<<<<<<<<<<<<<
 *         return self.tree.hanging_faces_x.size()
 * 
 */
  __Pyx_TraceLine(1595,0,__PYX_ERR(0, 1595, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1596
 *         """
 *         if(self._dim == 2): return self.n_hanging_edges_y
 *         return self.tree.hanging_faces_x.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1596,0,__PYX_ERR(0, 1596, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_faces_x.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1596, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1587
 * 
 *     @property
 *     def n_hanging_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging x-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_faces_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1599
 * 
 *     @property
 *     def n_hanging_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging y-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1599, 0, __PYX_ERR(0, 1599, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1607
 *             Number of hanging y-faces in the mesh
 *         """
 *         if(self._dim == 2): return self.n_hanging_edges_x             # <<<<<<<<<<<<<<
 *         return self.tree.hanging_faces_y.size()
 * 
 */
  __Pyx_TraceLine(1607,0,__PYX_ERR(0, 1607, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1607, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1608
 *         """
 *         if(self._dim == 2): return self.n_hanging_edges_x
 *         return self.tree.hanging_faces_y.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1608,0,__PYX_ERR(0, 1608, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_faces_y.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1599
 * 
 *     @property
 *     def n_hanging_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging y-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_faces_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1611
 * 
 *     @property
 *     def n_hanging_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging z-faces in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1611, 0, __PYX_ERR(0, 1611, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1619
 *             Number of hanging z-faces in the mesh
 *         """
 *         if(self._dim == 2): return 0             # <<<<<<<<<<<<<<
 *         return self.tree.hanging_faces_z.size()
 * 
 */
  __Pyx_TraceLine(1619,0,__PYX_ERR(0, 1619, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1620
 *         """
 *         if(self._dim == 2): return 0
 *         return self.tree.hanging_faces_z.size()             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1620,0,__PYX_ERR(0, 1620, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->tree->hanging_faces_z.size()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1611
 * 
 *     @property
 *     def n_hanging_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Number of hanging z-faces in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.n_hanging_faces_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1623
 * 
 *     @property
 *     def cell_centers(self):             # <<<<<<<<<<<<<<
 *         """Gridded cell center locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridCC = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1623, 0, __PYX_ERR(0, 1623, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1637
 *         cdef np.float64_t[:, :] gridCC
 *         cdef np.int64_t ii, ind, dim
 *         if self._cell_centers is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1637,0,__PYX_ERR(0, 1637, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_cell_centers == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1638
 *         cdef np.int64_t ii, ind, dim
 *         if self._cell_centers is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 *             gridCC = self._cell_centers
 */
    __Pyx_TraceLine(1638,0,__PYX_ERR(0, 1638, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1639
 *         if self._cell_centers is None:
 *             dim = self._dim
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridCC = self._cell_centers
 *             for cell in self.tree.cells:
 */
    __Pyx_TraceLine(1639,0,__PYX_ERR(0, 1639, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_cell_centers);
    __Pyx_DECREF(__pyx_v_self->_cell_centers);
    __pyx_v_self->_cell_centers = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1640
 *             dim = self._dim
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 *             gridCC = self._cell_centers             # <<<<<<<<<<<<<<
 *             for cell in self.tree.cells:
 *                 ind = cell.index
 */
    __Pyx_TraceLine(1640,0,__PYX_ERR(0, 1640, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_cell_centers, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1640, __pyx_L1_error)
    __pyx_v_gridCC = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1641
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 *             gridCC = self._cell_centers
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 ind = cell.index
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(1641,0,__PYX_ERR(0, 1641, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->cells;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_cell = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1642
 *             gridCC = self._cell_centers
 *             for cell in self.tree.cells:
 *                 ind = cell.index             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridCC[ind, ii] = cell.location[ii]
 */
      __Pyx_TraceLine(1642,0,__PYX_ERR(0, 1642, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_cell->index;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1643
 *             for cell in self.tree.cells:
 *                 ind = cell.index
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridCC[ind, ii] = cell.location[ii]
 *         return self._cell_centers
 */
      __Pyx_TraceLine(1643,0,__PYX_ERR(0, 1643, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_dim;
      __pyx_t_15 = __pyx_t_14;
      for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
        __pyx_v_ii = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":1644
 *                 ind = cell.index
 *                 for ii in range(dim):
 *                     gridCC[ind, ii] = cell.location[ii]             # <<<<<<<<<<<<<<
 *         return self._cell_centers
 * 
 */
        __Pyx_TraceLine(1644,0,__PYX_ERR(0, 1644, __pyx_L1_error))
        __pyx_t_17 = __pyx_v_ind;
        __pyx_t_18 = __pyx_v_ii;
        __pyx_t_19 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridCC.shape[0];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridCC.shape[0])) __pyx_t_19 = 0;
        if (__pyx_t_18 < 0) {
          __pyx_t_18 += __pyx_v_gridCC.shape[1];
          if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
        } else if (unlikely(__pyx_t_18 >= __pyx_v_gridCC.shape[1])) __pyx_t_19 = 1;
        if (unlikely(__pyx_t_19 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_19);
          __PYX_ERR(0, 1644, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridCC.data + __pyx_t_17 * __pyx_v_gridCC.strides[0]) ) + __pyx_t_18 * __pyx_v_gridCC.strides[1]) )) = (__pyx_v_cell->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":1641
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 *             gridCC = self._cell_centers
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 ind = cell.index
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(1641,0,__PYX_ERR(0, 1641, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1637
 *         cdef np.float64_t[:, :] gridCC
 *         cdef np.int64_t ii, ind, dim
 *         if self._cell_centers is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._cell_centers = np.empty((self.n_cells, self._dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1645
 *                 for ii in range(dim):
 *                     gridCC[ind, ii] = cell.location[ii]
 *         return self._cell_centers             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1645,0,__PYX_ERR(0, 1645, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_cell_centers);
  __pyx_r = __pyx_v_self->_cell_centers;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1623
 * 
 *     @property
 *     def cell_centers(self):             # <<<<<<<<<<<<<<
 *         """Gridded cell center locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.cell_centers.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridCC, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1648
 * 
 *     @property
 *     def nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded non-hanging nodes locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridN = { 0, 0, { 0 }, { 0 }, { 0 } };
  Node *__pyx_v_node;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Node *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Node *> ::iterator __pyx_t_10;
  node_map_t *__pyx_t_11;
  std::pair<int_t,Node *>  __pyx_t_12;
  Node *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1648, 0, __PYX_ERR(0, 1648, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1663
 *         cdef Node *node
 *         cdef np.int64_t ii, ind, dim
 *         if self._nodes is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 */
  __Pyx_TraceLine(1663,0,__PYX_ERR(0, 1663, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_nodes == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1664
 *         cdef np.int64_t ii, ind, dim
 *         if self._nodes is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 *             gridN = self._nodes
 */
    __Pyx_TraceLine(1664,0,__PYX_ERR(0, 1664, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1665
 *         if self._nodes is None:
 *             dim = self._dim
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridN = self._nodes
 *             for it in self.tree.nodes:
 */
    __Pyx_TraceLine(1665,0,__PYX_ERR(0, 1665, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_nodes);
    __Pyx_DECREF(__pyx_v_self->_nodes);
    __pyx_v_self->_nodes = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1666
 *             dim = self._dim
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 *             gridN = self._nodes             # <<<<<<<<<<<<<<
 *             for it in self.tree.nodes:
 *                 node = it.second
 */
    __Pyx_TraceLine(1666,0,__PYX_ERR(0, 1666, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_nodes, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1666, __pyx_L1_error)
    __pyx_v_gridN = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1667
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 *             gridN = self._nodes
 *             for it in self.tree.nodes:             # <<<<<<<<<<<<<<
 *                 node = it.second
 *                 if not node.hanging:
 */
    __Pyx_TraceLine(1667,0,__PYX_ERR(0, 1667, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->nodes;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1668
 *             gridN = self._nodes
 *             for it in self.tree.nodes:
 *                 node = it.second             # <<<<<<<<<<<<<<
 *                 if not node.hanging:
 *                     ind = node.index
 */
      __Pyx_TraceLine(1668,0,__PYX_ERR(0, 1668, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_node = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1669
 *             for it in self.tree.nodes:
 *                 node = it.second
 *                 if not node.hanging:             # <<<<<<<<<<<<<<
 *                     ind = node.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(1669,0,__PYX_ERR(0, 1669, __pyx_L1_error))
      __pyx_t_2 = ((!(__pyx_v_node->hanging != 0)) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":1670
 *                 node = it.second
 *                 if not node.hanging:
 *                     ind = node.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridN[ind, ii] = node.location[ii]
 */
        __Pyx_TraceLine(1670,0,__PYX_ERR(0, 1670, __pyx_L1_error))
        __pyx_t_3 = __pyx_v_node->index;
        __pyx_v_ind = __pyx_t_3;

        /* "discretize/_extensions/tree_ext.pyx":1671
 *                 if not node.hanging:
 *                     ind = node.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridN[ind, ii] = node.location[ii]
 *         return self._nodes
 */
        __Pyx_TraceLine(1671,0,__PYX_ERR(0, 1671, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":1672
 *                     ind = node.index
 *                     for ii in range(dim):
 *                         gridN[ind, ii] = node.location[ii]             # <<<<<<<<<<<<<<
 *         return self._nodes
 * 
 */
          __Pyx_TraceLine(1672,0,__PYX_ERR(0, 1672, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridN.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridN.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridN.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridN.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 1672, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridN.data + __pyx_t_17 * __pyx_v_gridN.strides[0]) ) + __pyx_t_18 * __pyx_v_gridN.strides[1]) )) = (__pyx_v_node->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":1669
 *             for it in self.tree.nodes:
 *                 node = it.second
 *                 if not node.hanging:             # <<<<<<<<<<<<<<
 *                     ind = node.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":1667
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 *             gridN = self._nodes
 *             for it in self.tree.nodes:             # <<<<<<<<<<<<<<
 *                 node = it.second
 *                 if not node.hanging:
 */
      __Pyx_TraceLine(1667,0,__PYX_ERR(0, 1667, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1663
 *         cdef Node *node
 *         cdef np.int64_t ii, ind, dim
 *         if self._nodes is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._nodes = np.empty((self.n_nodes, dim) ,dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1673
 *                     for ii in range(dim):
 *                         gridN[ind, ii] = node.location[ii]
 *         return self._nodes             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1673,0,__PYX_ERR(0, 1673, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_nodes);
  __pyx_r = __pyx_v_self->_nodes;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1648
 * 
 *     @property
 *     def nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded non-hanging nodes locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridN, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1676
 * 
 *     @property
 *     def hanging_nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded hanging node locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  Node *__pyx_v_node;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_v_gridhN = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  std::vector<Node *> ::iterator __pyx_t_9;
  std::vector<Node *>  *__pyx_t_10;
  Node *__pyx_t_11;
  __pyx_t_5numpy_int64_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1676, 0, __PYX_ERR(0, 1676, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1691
 *         cdef Node *node
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_nodes is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1691,0,__PYX_ERR(0, 1691, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_nodes == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1692
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_nodes is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 *             gridhN = self._hanging_nodes
 */
    __Pyx_TraceLine(1692,0,__PYX_ERR(0, 1692, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1693
 *         if self._hanging_nodes is None:
 *             dim = self._dim
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhN = self._hanging_nodes
 *             for node in self.tree.hanging_nodes:
 */
    __Pyx_TraceLine(1693,0,__PYX_ERR(0, 1693, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_nodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_nodes);
    __Pyx_DECREF(__pyx_v_self->_hanging_nodes);
    __pyx_v_self->_hanging_nodes = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1694
 *             dim = self._dim
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 *             gridhN = self._hanging_nodes             # <<<<<<<<<<<<<<
 *             for node in self.tree.hanging_nodes:
 *                 ind = node.index-self.n_nodes
 */
    __Pyx_TraceLine(1694,0,__PYX_ERR(0, 1694, __pyx_L1_error))
    __pyx_t_8 = __pyx_v_self->_hanging_nodes;
    __Pyx_INCREF(__pyx_t_8);
    __pyx_v_gridhN = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1695
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 *             gridhN = self._hanging_nodes
 *             for node in self.tree.hanging_nodes:             # <<<<<<<<<<<<<<
 *                 ind = node.index-self.n_nodes
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(1695,0,__PYX_ERR(0, 1695, __pyx_L1_error))
    __pyx_t_10 = &__pyx_v_self->tree->hanging_nodes;
    __pyx_t_9 = __pyx_t_10->begin();
    for (;;) {
      if (!(__pyx_t_9 != __pyx_t_10->end())) break;
      __pyx_t_11 = *__pyx_t_9;
      ++__pyx_t_9;
      __pyx_v_node = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":1696
 *             gridhN = self._hanging_nodes
 *             for node in self.tree.hanging_nodes:
 *                 ind = node.index-self.n_nodes             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhN[ind, ii] = node.location[ii]
 */
      __Pyx_TraceLine(1696,0,__PYX_ERR(0, 1696, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_node->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1696, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_12 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1696, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1697
 *             for node in self.tree.hanging_nodes:
 *                 ind = node.index-self.n_nodes
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhN[ind, ii] = node.location[ii]
 *         return self._hanging_nodes
 */
      __Pyx_TraceLine(1697,0,__PYX_ERR(0, 1697, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_dim;
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_ii = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":1698
 *                 ind = node.index-self.n_nodes
 *                 for ii in range(dim):
 *                     gridhN[ind, ii] = node.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_nodes
 * 
 */
        __Pyx_TraceLine(1698,0,__PYX_ERR(0, 1698, __pyx_L1_error))
        __pyx_t_6 = PyFloat_FromDouble((__pyx_v_node->location[__pyx_v_ii])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyInt_From_npy_int64(__pyx_v_ind); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_npy_int64(__pyx_v_ii); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_gridhN, __pyx_t_5, __pyx_t_6) < 0)) __PYX_ERR(0, 1698, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }

      /* "discretize/_extensions/tree_ext.pyx":1695
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 *             gridhN = self._hanging_nodes
 *             for node in self.tree.hanging_nodes:             # <<<<<<<<<<<<<<
 *                 ind = node.index-self.n_nodes
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(1695,0,__PYX_ERR(0, 1695, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1691
 *         cdef Node *node
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_nodes is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_nodes = np.empty((self.n_hanging_nodes, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1699
 *                 for ii in range(dim):
 *                     gridhN[ind, ii] = node.location[ii]
 *         return self._hanging_nodes             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1699,0,__PYX_ERR(0, 1699, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_nodes);
  __pyx_r = __pyx_v_self->_hanging_nodes;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1676
 * 
 *     @property
 *     def hanging_nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded hanging node locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gridhN);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1702
 * 
 *     @property
 *     def boundary_nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary node locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_boundary = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1702, 0, __PYX_ERR(0, 1702, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1714
 *             Gridded boundary node locations
 *         """
 *         nodes = self.nodes             # <<<<<<<<<<<<<<
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 */
  __Pyx_TraceLine(1714,0,__PYX_ERR(0, 1714, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1714, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1715
 *         """
 *         nodes = self.nodes
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary = (
 */
  __Pyx_TraceLine(1715,0,__PYX_ERR(0, 1715, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1715, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1715, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1715, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1715, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1715, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1715, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1716
 *         nodes = self.nodes
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_boundary = (
 *             (nodes[:, 0] == x0)
 */
  __Pyx_TraceLine(1716,0,__PYX_ERR(0, 1716, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1716, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1716, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1716, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1716, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1716, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1716, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1718
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary = (
 *             (nodes[:, 0] == x0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)
 */
  __Pyx_TraceLine(1718,0,__PYX_ERR(0, 1718, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1718, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1719
 *         is_boundary = (
 *             (nodes[:, 0] == x0)
 *             | (nodes[:, 0] == xF)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 1] == y0)
 *             | (nodes[:, 1] == yF)
 */
  __Pyx_TraceLine(1719,0,__PYX_ERR(0, 1719, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1719, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1720
 *             (nodes[:, 0] == x0)
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 1] == yF)
 *         )
 */
  __Pyx_TraceLine(1720,0,__PYX_ERR(0, 1720, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1721
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)
 *             | (nodes[:, 1] == yF)             # <<<<<<<<<<<<<<
 *         )
 *         if self.dim > 2:
 */
  __Pyx_TraceLine(1721,0,__PYX_ERR(0, 1721, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__22); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1721, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1721, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1721, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_boundary = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1723
 *             | (nodes[:, 1] == yF)
 *         )
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_boundary |= (
 */
  __Pyx_TraceLine(1723,0,__PYX_ERR(0, 1723, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1723, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":1724
 *         )
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             is_boundary |= (
 *                 (nodes[:, 2] == z0)
 */
    __Pyx_TraceLine(1724,0,__PYX_ERR(0, 1724, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1724, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 1724, __pyx_L1_error)
    }
    __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1724, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 1724, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_z0 = __pyx_t_1;
    __pyx_t_1 = 0;
    __pyx_v_zF = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1726
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_boundary |= (
 *                 (nodes[:, 2] == z0)             # <<<<<<<<<<<<<<
 *                 | (nodes[:, 2] == zF)
 *             )
 */
    __Pyx_TraceLine(1726,0,__PYX_ERR(0, 1726, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1726, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1726, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1727
 *             is_boundary |= (
 *                 (nodes[:, 2] == z0)
 *                 | (nodes[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             )
 *         return nodes[is_boundary]
 */
    __Pyx_TraceLine(1727,0,__PYX_ERR(0, 1727, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Or(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1725
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_boundary |= (             # <<<<<<<<<<<<<<
 *                 (nodes[:, 2] == z0)
 *                 | (nodes[:, 2] == zF)
 */
    __Pyx_TraceLine(1725,0,__PYX_ERR(0, 1725, __pyx_L1_error))
    __pyx_t_5 = PyNumber_InPlaceOr(__pyx_v_is_boundary, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1725, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_boundary, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1723
 *             | (nodes[:, 1] == yF)
 *         )
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_boundary |= (
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1729
 *                 | (nodes[:, 2] == zF)
 *             )
 *         return nodes[is_boundary]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1729,0,__PYX_ERR(0, 1729, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_v_is_boundary); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1729, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1702
 * 
 *     @property
 *     def boundary_nodes(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary node locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.boundary_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_boundary);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1732
 * 
 *     @property
 *     def h_gridded(self):             # <<<<<<<<<<<<<<
 *         """Gridded cell dimensions.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridCH = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  int __pyx_v_epc;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  PY_LONG_LONG __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  double __pyx_t_18;
  __pyx_t_5numpy_int64_t __pyx_t_19;
  __pyx_t_5numpy_int64_t __pyx_t_20;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1732, 0, __PYX_ERR(0, 1732, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1745
 *             Gridded cell dimensions
 *         """
 *         if self._h_gridded is not None:             # <<<<<<<<<<<<<<
 *             return self._h_gridded
 *         cdef np.float64_t[:, :] gridCH
 */
  __Pyx_TraceLine(1745,0,__PYX_ERR(0, 1745, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_h_gridded != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1746
 *         """
 *         if self._h_gridded is not None:
 *             return self._h_gridded             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:, :] gridCH
 *         cdef np.int64_t ii, ind, dim
 */
    __Pyx_TraceLine(1746,0,__PYX_ERR(0, 1746, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_h_gridded);
    __pyx_r = __pyx_v_self->_h_gridded;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":1745
 *             Gridded cell dimensions
 *         """
 *         if self._h_gridded is not None:             # <<<<<<<<<<<<<<
 *             return self._h_gridded
 *         cdef np.float64_t[:, :] gridCH
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1750
 *         cdef np.int64_t ii, ind, dim
 *         cdef np.float64_t len
 *         cdef int epc = 4 if self._dim==3 else 2             # <<<<<<<<<<<<<<
 *         dim = self._dim
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1750,0,__PYX_ERR(0, 1750, __pyx_L1_error))
  if (((__pyx_v_self->_dim == 3) != 0)) {
    __pyx_t_3 = 4;
  } else {
    __pyx_t_3 = 2;
  }
  __pyx_v_epc = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":1751
 *         cdef np.float64_t len
 *         cdef int epc = 4 if self._dim==3 else 2
 *         dim = self._dim             # <<<<<<<<<<<<<<
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)
 *         gridCH = self._h_gridded
 */
  __Pyx_TraceLine(1751,0,__PYX_ERR(0, 1751, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_4;

  /* "discretize/_extensions/tree_ext.pyx":1752
 *         cdef int epc = 4 if self._dim==3 else 2
 *         dim = self._dim
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *         gridCH = self._h_gridded
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(1752,0,__PYX_ERR(0, 1752, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
  __pyx_t_5 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_9) < 0) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_GIVEREF(__pyx_t_9);
  __Pyx_GOTREF(__pyx_v_self->_h_gridded);
  __Pyx_DECREF(__pyx_v_self->_h_gridded);
  __pyx_v_self->_h_gridded = __pyx_t_9;
  __pyx_t_9 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1753
 *         dim = self._dim
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)
 *         gridCH = self._h_gridded             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             ind = cell.index
 */
  __Pyx_TraceLine(1753,0,__PYX_ERR(0, 1753, __pyx_L1_error))
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_h_gridded, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 1753, __pyx_L1_error)
  __pyx_v_gridCH = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":1754
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)
 *         gridCH = self._h_gridded
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(dim):
 */
  __Pyx_TraceLine(1754,0,__PYX_ERR(0, 1754, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":1755
 *         gridCH = self._h_gridded
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             for ii in range(dim):
 *                 gridCH[ind, ii] = cell.edges[ii*epc].length
 */
    __Pyx_TraceLine(1755,0,__PYX_ERR(0, 1755, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":1756
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             for ii in range(dim):             # <<<<<<<<<<<<<<
 *                 gridCH[ind, ii] = cell.edges[ii*epc].length
 * 
 */
    __Pyx_TraceLine(1756,0,__PYX_ERR(0, 1756, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_dim;
    __pyx_t_16 = __pyx_t_15;
    for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) {
      __pyx_v_ii = __pyx_t_17;

      /* "discretize/_extensions/tree_ext.pyx":1757
 *             ind = cell.index
 *             for ii in range(dim):
 *                 gridCH[ind, ii] = cell.edges[ii*epc].length             # <<<<<<<<<<<<<<
 * 
 *         return self._h_gridded
 */
      __Pyx_TraceLine(1757,0,__PYX_ERR(0, 1757, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_cell->edges[(__pyx_v_ii * __pyx_v_epc)])->length;
      __pyx_t_19 = __pyx_v_ind;
      __pyx_t_20 = __pyx_v_ii;
      __pyx_t_3 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_gridCH.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_3 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_gridCH.shape[0])) __pyx_t_3 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_gridCH.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_3 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_gridCH.shape[1])) __pyx_t_3 = 1;
      if (unlikely(__pyx_t_3 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_3);
        __PYX_ERR(0, 1757, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridCH.data + __pyx_t_19 * __pyx_v_gridCH.strides[0]) ) + __pyx_t_20 * __pyx_v_gridCH.strides[1]) )) = __pyx_t_18;
    }

    /* "discretize/_extensions/tree_ext.pyx":1754
 *         self._h_gridded = np.empty((self.n_cells, dim), dtype=np.float64)
 *         gridCH = self._h_gridded
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(dim):
 */
    __Pyx_TraceLine(1754,0,__PYX_ERR(0, 1754, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":1759
 *                 gridCH[ind, ii] = cell.edges[ii*epc].length
 * 
 *         return self._h_gridded             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1759,0,__PYX_ERR(0, 1759, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_h_gridded);
  __pyx_r = __pyx_v_self->_h_gridded;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1732
 * 
 *     @property
 *     def h_gridded(self):             # <<<<<<<<<<<<<<
 *         """Gridded cell dimensions.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.h_gridded.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridCH, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1762
 * 
 *     @property
 *     def edges_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging x-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridEx = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1762, 0, __PYX_ERR(0, 1762, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1776
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1776,0,__PYX_ERR(0, 1776, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_edges_x == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1777
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_x is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 *             gridEx = self._edges_x
 */
    __Pyx_TraceLine(1777,0,__PYX_ERR(0, 1777, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1778
 *         if self._edges_x is None:
 *             dim = self._dim
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridEx = self._edges_x
 *             for it in self.tree.edges_x:
 */
    __Pyx_TraceLine(1778,0,__PYX_ERR(0, 1778, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_edges_x);
    __Pyx_DECREF(__pyx_v_self->_edges_x);
    __pyx_v_self->_edges_x = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1779
 *             dim = self._dim
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 *             gridEx = self._edges_x             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_x:
 *                 edge = it.second
 */
    __Pyx_TraceLine(1779,0,__PYX_ERR(0, 1779, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_edges_x, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1779, __pyx_L1_error)
    __pyx_v_gridEx = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1780
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 *             gridEx = self._edges_x
 *             for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
    __Pyx_TraceLine(1780,0,__PYX_ERR(0, 1780, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->edges_x;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1781
 *             gridEx = self._edges_x
 *             for it in self.tree.edges_x:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if not edge.hanging:
 *                     ind = edge.index
 */
      __Pyx_TraceLine(1781,0,__PYX_ERR(0, 1781, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1782
 *             for it in self.tree.edges_x:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(1782,0,__PYX_ERR(0, 1782, __pyx_L1_error))
      __pyx_t_2 = ((!(__pyx_v_edge->hanging != 0)) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":1783
 *                 edge = it.second
 *                 if not edge.hanging:
 *                     ind = edge.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridEx[ind, ii] = edge.location[ii]
 */
        __Pyx_TraceLine(1783,0,__PYX_ERR(0, 1783, __pyx_L1_error))
        __pyx_t_3 = __pyx_v_edge->index;
        __pyx_v_ind = __pyx_t_3;

        /* "discretize/_extensions/tree_ext.pyx":1784
 *                 if not edge.hanging:
 *                     ind = edge.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridEx[ind, ii] = edge.location[ii]
 *         return self._edges_x
 */
        __Pyx_TraceLine(1784,0,__PYX_ERR(0, 1784, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":1785
 *                     ind = edge.index
 *                     for ii in range(dim):
 *                         gridEx[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._edges_x
 * 
 */
          __Pyx_TraceLine(1785,0,__PYX_ERR(0, 1785, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridEx.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridEx.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridEx.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridEx.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 1785, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridEx.data + __pyx_t_17 * __pyx_v_gridEx.strides[0]) ) + __pyx_t_18 * __pyx_v_gridEx.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":1782
 *             for it in self.tree.edges_x:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":1780
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 *             gridEx = self._edges_x
 *             for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
      __Pyx_TraceLine(1780,0,__PYX_ERR(0, 1780, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1776
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_x = np.empty((self.n_edges_x, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1786
 *                     for ii in range(dim):
 *                         gridEx[ind, ii] = edge.location[ii]
 *         return self._edges_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1786,0,__PYX_ERR(0, 1786, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_edges_x);
  __pyx_r = __pyx_v_self->_edges_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1762
 * 
 *     @property
 *     def edges_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging x-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edges_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridEx, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1789
 * 
 *     @property
 *     def hanging_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging x-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridhEx = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Edge *> ::iterator __pyx_t_10;
  std::vector<Edge *>  *__pyx_t_11;
  Edge *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1789, 0, __PYX_ERR(0, 1789, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1803
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1803,0,__PYX_ERR(0, 1803, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_edges_x == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1804
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_x is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 *             gridhEx = self._hanging_edges_x
 */
    __Pyx_TraceLine(1804,0,__PYX_ERR(0, 1804, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1805
 *         if self._hanging_edges_x is None:
 *             dim = self._dim
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhEx = self._hanging_edges_x
 *             for edge in self.tree.hanging_edges_x:
 */
    __Pyx_TraceLine(1805,0,__PYX_ERR(0, 1805, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_x);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_x);
    __pyx_v_self->_hanging_edges_x = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1806
 *             dim = self._dim
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 *             gridhEx = self._hanging_edges_x             # <<<<<<<<<<<<<<
 *             for edge in self.tree.hanging_edges_x:
 *                 ind = edge.index-self.n_edges_x
 */
    __Pyx_TraceLine(1806,0,__PYX_ERR(0, 1806, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_hanging_edges_x, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1806, __pyx_L1_error)
    __pyx_v_gridhEx = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1807
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 *             gridhEx = self._hanging_edges_x
 *             for edge in self.tree.hanging_edges_x:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_x
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(1807,0,__PYX_ERR(0, 1807, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->hanging_edges_x;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_edge = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1808
 *             gridhEx = self._hanging_edges_x
 *             for edge in self.tree.hanging_edges_x:
 *                 ind = edge.index-self.n_edges_x             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhEx[ind, ii] = edge.location[ii]
 */
      __Pyx_TraceLine(1808,0,__PYX_ERR(0, 1808, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_edge->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1808, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1808, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1808, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_13 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1808, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1809
 *             for edge in self.tree.hanging_edges_x:
 *                 ind = edge.index-self.n_edges_x
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhEx[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_x
 */
      __Pyx_TraceLine(1809,0,__PYX_ERR(0, 1809, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_dim;
      __pyx_t_14 = __pyx_t_13;
      for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
        __pyx_v_ii = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":1810
 *                 ind = edge.index-self.n_edges_x
 *                 for ii in range(dim):
 *                     gridhEx[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_edges_x
 * 
 */
        __Pyx_TraceLine(1810,0,__PYX_ERR(0, 1810, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_ind;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_gridhEx.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_gridhEx.shape[0])) __pyx_t_18 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridhEx.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridhEx.shape[1])) __pyx_t_18 = 1;
        if (unlikely(__pyx_t_18 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_18);
          __PYX_ERR(0, 1810, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridhEx.data + __pyx_t_16 * __pyx_v_gridhEx.strides[0]) ) + __pyx_t_17 * __pyx_v_gridhEx.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":1807
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 *             gridhEx = self._hanging_edges_x
 *             for edge in self.tree.hanging_edges_x:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_x
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(1807,0,__PYX_ERR(0, 1807, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1803
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_x = np.empty((self.n_hanging_edges_x, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1811
 *                 for ii in range(dim):
 *                     gridhEx[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1811,0,__PYX_ERR(0, 1811, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_edges_x);
  __pyx_r = __pyx_v_self->_hanging_edges_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1789
 * 
 *     @property
 *     def hanging_edges_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging x-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_edges_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridhEx, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1814
 * 
 *     @property
 *     def edges_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging y-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridEy = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1814, 0, __PYX_ERR(0, 1814, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1828
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1828,0,__PYX_ERR(0, 1828, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_edges_y == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1829
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_y is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 *             gridEy = self._edges_y
 */
    __Pyx_TraceLine(1829,0,__PYX_ERR(0, 1829, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1830
 *         if self._edges_y is None:
 *             dim = self._dim
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridEy = self._edges_y
 *             for it in self.tree.edges_y:
 */
    __Pyx_TraceLine(1830,0,__PYX_ERR(0, 1830, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_edges_y);
    __Pyx_DECREF(__pyx_v_self->_edges_y);
    __pyx_v_self->_edges_y = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1831
 *             dim = self._dim
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 *             gridEy = self._edges_y             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_y:
 *                 edge = it.second
 */
    __Pyx_TraceLine(1831,0,__PYX_ERR(0, 1831, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_edges_y, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __pyx_v_gridEy = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1832
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 *             gridEy = self._edges_y
 *             for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
    __Pyx_TraceLine(1832,0,__PYX_ERR(0, 1832, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->edges_y;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1833
 *             gridEy = self._edges_y
 *             for it in self.tree.edges_y:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if not edge.hanging:
 *                     ind = edge.index
 */
      __Pyx_TraceLine(1833,0,__PYX_ERR(0, 1833, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1834
 *             for it in self.tree.edges_y:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(1834,0,__PYX_ERR(0, 1834, __pyx_L1_error))
      __pyx_t_2 = ((!(__pyx_v_edge->hanging != 0)) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":1835
 *                 edge = it.second
 *                 if not edge.hanging:
 *                     ind = edge.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridEy[ind, ii] = edge.location[ii]
 */
        __Pyx_TraceLine(1835,0,__PYX_ERR(0, 1835, __pyx_L1_error))
        __pyx_t_3 = __pyx_v_edge->index;
        __pyx_v_ind = __pyx_t_3;

        /* "discretize/_extensions/tree_ext.pyx":1836
 *                 if not edge.hanging:
 *                     ind = edge.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridEy[ind, ii] = edge.location[ii]
 *         return self._edges_y
 */
        __Pyx_TraceLine(1836,0,__PYX_ERR(0, 1836, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":1837
 *                     ind = edge.index
 *                     for ii in range(dim):
 *                         gridEy[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._edges_y
 * 
 */
          __Pyx_TraceLine(1837,0,__PYX_ERR(0, 1837, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridEy.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridEy.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridEy.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridEy.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 1837, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridEy.data + __pyx_t_17 * __pyx_v_gridEy.strides[0]) ) + __pyx_t_18 * __pyx_v_gridEy.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":1834
 *             for it in self.tree.edges_y:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":1832
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 *             gridEy = self._edges_y
 *             for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
      __Pyx_TraceLine(1832,0,__PYX_ERR(0, 1832, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1828
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_y = np.empty((self.n_edges_y, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1838
 *                     for ii in range(dim):
 *                         gridEy[ind, ii] = edge.location[ii]
 *         return self._edges_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1838,0,__PYX_ERR(0, 1838, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_edges_y);
  __pyx_r = __pyx_v_self->_edges_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1814
 * 
 *     @property
 *     def edges_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging y-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edges_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridEy, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1841
 * 
 *     @property
 *     def hanging_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging y-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridhEy = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Edge *> ::iterator __pyx_t_10;
  std::vector<Edge *>  *__pyx_t_11;
  Edge *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1841, 0, __PYX_ERR(0, 1841, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1855
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1855,0,__PYX_ERR(0, 1855, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_edges_y == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1856
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_y is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 *             gridhEy = self._hanging_edges_y
 */
    __Pyx_TraceLine(1856,0,__PYX_ERR(0, 1856, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1857
 *         if self._hanging_edges_y is None:
 *             dim = self._dim
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhEy = self._hanging_edges_y
 *             for edge in self.tree.hanging_edges_y:
 */
    __Pyx_TraceLine(1857,0,__PYX_ERR(0, 1857, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_y);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_y);
    __pyx_v_self->_hanging_edges_y = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1858
 *             dim = self._dim
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 *             gridhEy = self._hanging_edges_y             # <<<<<<<<<<<<<<
 *             for edge in self.tree.hanging_edges_y:
 *                 ind = edge.index-self.n_edges_y
 */
    __Pyx_TraceLine(1858,0,__PYX_ERR(0, 1858, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_hanging_edges_y, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1858, __pyx_L1_error)
    __pyx_v_gridhEy = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1859
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 *             gridhEy = self._hanging_edges_y
 *             for edge in self.tree.hanging_edges_y:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_y
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(1859,0,__PYX_ERR(0, 1859, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->hanging_edges_y;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_edge = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1860
 *             gridhEy = self._hanging_edges_y
 *             for edge in self.tree.hanging_edges_y:
 *                 ind = edge.index-self.n_edges_y             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhEy[ind, ii] = edge.location[ii]
 */
      __Pyx_TraceLine(1860,0,__PYX_ERR(0, 1860, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_edge->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1860, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1860, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1860, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_13 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1860, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1861
 *             for edge in self.tree.hanging_edges_y:
 *                 ind = edge.index-self.n_edges_y
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhEy[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_y
 */
      __Pyx_TraceLine(1861,0,__PYX_ERR(0, 1861, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_dim;
      __pyx_t_14 = __pyx_t_13;
      for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
        __pyx_v_ii = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":1862
 *                 ind = edge.index-self.n_edges_y
 *                 for ii in range(dim):
 *                     gridhEy[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_edges_y
 * 
 */
        __Pyx_TraceLine(1862,0,__PYX_ERR(0, 1862, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_ind;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_gridhEy.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_gridhEy.shape[0])) __pyx_t_18 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridhEy.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridhEy.shape[1])) __pyx_t_18 = 1;
        if (unlikely(__pyx_t_18 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_18);
          __PYX_ERR(0, 1862, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridhEy.data + __pyx_t_16 * __pyx_v_gridhEy.strides[0]) ) + __pyx_t_17 * __pyx_v_gridhEy.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":1859
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 *             gridhEy = self._hanging_edges_y
 *             for edge in self.tree.hanging_edges_y:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_y
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(1859,0,__PYX_ERR(0, 1859, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1855
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_y = np.empty((self.n_hanging_edges_y, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1863
 *                 for ii in range(dim):
 *                     gridhEy[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1863,0,__PYX_ERR(0, 1863, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_edges_y);
  __pyx_r = __pyx_v_self->_hanging_edges_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1841
 * 
 *     @property
 *     def hanging_edges_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging y-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_edges_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridhEy, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1866
 * 
 *     @property
 *     def edges_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging z-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridEz = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1866, 0, __PYX_ERR(0, 1866, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1880
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1880,0,__PYX_ERR(0, 1880, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_edges_z == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1881
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_z is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 *             gridEz = self._edges_z
 */
    __Pyx_TraceLine(1881,0,__PYX_ERR(0, 1881, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1882
 *         if self._edges_z is None:
 *             dim = self._dim
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridEz = self._edges_z
 *             for it in self.tree.edges_z:
 */
    __Pyx_TraceLine(1882,0,__PYX_ERR(0, 1882, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1882, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_edges_z);
    __Pyx_DECREF(__pyx_v_self->_edges_z);
    __pyx_v_self->_edges_z = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1883
 *             dim = self._dim
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 *             gridEz = self._edges_z             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 */
    __Pyx_TraceLine(1883,0,__PYX_ERR(0, 1883, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_edges_z, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1883, __pyx_L1_error)
    __pyx_v_gridEz = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1884
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 *             gridEz = self._edges_z
 *             for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
    __Pyx_TraceLine(1884,0,__PYX_ERR(0, 1884, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->edges_z;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1885
 *             gridEz = self._edges_z
 *             for it in self.tree.edges_z:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if not edge.hanging:
 *                     ind = edge.index
 */
      __Pyx_TraceLine(1885,0,__PYX_ERR(0, 1885, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1886
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(1886,0,__PYX_ERR(0, 1886, __pyx_L1_error))
      __pyx_t_2 = ((!(__pyx_v_edge->hanging != 0)) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":1887
 *                 edge = it.second
 *                 if not edge.hanging:
 *                     ind = edge.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridEz[ind, ii] = edge.location[ii]
 */
        __Pyx_TraceLine(1887,0,__PYX_ERR(0, 1887, __pyx_L1_error))
        __pyx_t_3 = __pyx_v_edge->index;
        __pyx_v_ind = __pyx_t_3;

        /* "discretize/_extensions/tree_ext.pyx":1888
 *                 if not edge.hanging:
 *                     ind = edge.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridEz[ind, ii] = edge.location[ii]
 *         return self._edges_z
 */
        __Pyx_TraceLine(1888,0,__PYX_ERR(0, 1888, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":1889
 *                     ind = edge.index
 *                     for ii in range(dim):
 *                         gridEz[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._edges_z
 * 
 */
          __Pyx_TraceLine(1889,0,__PYX_ERR(0, 1889, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridEz.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridEz.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridEz.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridEz.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 1889, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridEz.data + __pyx_t_17 * __pyx_v_gridEz.strides[0]) ) + __pyx_t_18 * __pyx_v_gridEz.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":1886
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 *                 if not edge.hanging:             # <<<<<<<<<<<<<<
 *                     ind = edge.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":1884
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 *             gridEz = self._edges_z
 *             for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if not edge.hanging:
 */
      __Pyx_TraceLine(1884,0,__PYX_ERR(0, 1884, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1880
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._edges_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._edges_z = np.empty((self.n_edges_z, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1890
 *                     for ii in range(dim):
 *                         gridEz[ind, ii] = edge.location[ii]
 *         return self._edges_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1890,0,__PYX_ERR(0, 1890, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_edges_z);
  __pyx_r = __pyx_v_self->_edges_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1866
 * 
 *     @property
 *     def edges_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging z-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edges_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridEz, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1893
 * 
 *     @property
 *     def hanging_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging z-edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridhEz = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Edge *> ::iterator __pyx_t_10;
  std::vector<Edge *>  *__pyx_t_11;
  Edge *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1893, 0, __PYX_ERR(0, 1893, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1907
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1907,0,__PYX_ERR(0, 1907, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_edges_z == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":1908
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_z is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 *             gridhEz = self._hanging_edges_z
 */
    __Pyx_TraceLine(1908,0,__PYX_ERR(0, 1908, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":1909
 *         if self._hanging_edges_z is None:
 *             dim = self._dim
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhEz = self._hanging_edges_z
 *             for edge in self.tree.hanging_edges_z:
 */
    __Pyx_TraceLine(1909,0,__PYX_ERR(0, 1909, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_edges_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_edges_z);
    __Pyx_DECREF(__pyx_v_self->_hanging_edges_z);
    __pyx_v_self->_hanging_edges_z = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1910
 *             dim = self._dim
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 *             gridhEz = self._hanging_edges_z             # <<<<<<<<<<<<<<
 *             for edge in self.tree.hanging_edges_z:
 *                 ind = edge.index-self.n_edges_z
 */
    __Pyx_TraceLine(1910,0,__PYX_ERR(0, 1910, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_hanging_edges_z, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1910, __pyx_L1_error)
    __pyx_v_gridhEz = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1911
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 *             gridhEz = self._hanging_edges_z
 *             for edge in self.tree.hanging_edges_z:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_z
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(1911,0,__PYX_ERR(0, 1911, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->hanging_edges_z;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_edge = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1912
 *             gridhEz = self._hanging_edges_z
 *             for edge in self.tree.hanging_edges_z:
 *                 ind = edge.index-self.n_edges_z             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhEz[ind, ii] = edge.location[ii]
 */
      __Pyx_TraceLine(1912,0,__PYX_ERR(0, 1912, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_edge->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1912, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1912, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1912, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_13 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1912, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1913
 *             for edge in self.tree.hanging_edges_z:
 *                 ind = edge.index-self.n_edges_z
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhEz[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_z
 */
      __Pyx_TraceLine(1913,0,__PYX_ERR(0, 1913, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_dim;
      __pyx_t_14 = __pyx_t_13;
      for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
        __pyx_v_ii = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":1914
 *                 ind = edge.index-self.n_edges_z
 *                 for ii in range(dim):
 *                     gridhEz[ind, ii] = edge.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_edges_z
 * 
 */
        __Pyx_TraceLine(1914,0,__PYX_ERR(0, 1914, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_ind;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_gridhEz.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_gridhEz.shape[0])) __pyx_t_18 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridhEz.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridhEz.shape[1])) __pyx_t_18 = 1;
        if (unlikely(__pyx_t_18 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_18);
          __PYX_ERR(0, 1914, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridhEz.data + __pyx_t_16 * __pyx_v_gridhEz.strides[0]) ) + __pyx_t_17 * __pyx_v_gridhEz.strides[1]) )) = (__pyx_v_edge->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":1911
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 *             gridhEz = self._hanging_edges_z
 *             for edge in self.tree.hanging_edges_z:             # <<<<<<<<<<<<<<
 *                 ind = edge.index-self.n_edges_z
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(1911,0,__PYX_ERR(0, 1911, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1907
 *         cdef Edge *edge
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_edges_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_edges_z = np.empty((self.n_hanging_edges_z, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1915
 *                 for ii in range(dim):
 *                     gridhEz[ind, ii] = edge.location[ii]
 *         return self._hanging_edges_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1915,0,__PYX_ERR(0, 1915, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_edges_z);
  __pyx_r = __pyx_v_self->_hanging_edges_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1893
 * 
 *     @property
 *     def hanging_edges_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging z-edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_edges_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridhEz, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1918
 * 
 *     @property
 *     def boundary_edges(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary edge locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_edges_x = NULL;
  PyObject *__pyx_v_edges_y = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_boundary_x = NULL;
  PyObject *__pyx_v_is_boundary_y = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_v_edges_z = NULL;
  PyObject *__pyx_v_is_boundary_z = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1918, 0, __PYX_ERR(0, 1918, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1931
 *             Gridded boundary edge locations
 *         """
 *         edges_x = self.edges_x             # <<<<<<<<<<<<<<
 *         edges_y = self.edges_y
 *         x0, xF = self._xs[0], self._xs[-1]
 */
  __Pyx_TraceLine(1931,0,__PYX_ERR(0, 1931, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1931, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_edges_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1932
 *         """
 *         edges_x = self.edges_x
 *         edges_y = self.edges_y             # <<<<<<<<<<<<<<
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 */
  __Pyx_TraceLine(1932,0,__PYX_ERR(0, 1932, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1932, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_edges_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1933
 *         edges_x = self.edges_x
 *         edges_y = self.edges_y
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 */
  __Pyx_TraceLine(1933,0,__PYX_ERR(0, 1933, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1933, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1933, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1933, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1933, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1934
 *         edges_y = self.edges_y
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_boundary_x = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_boundary_y = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 */
  __Pyx_TraceLine(1934,0,__PYX_ERR(0, 1934, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1934, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1934, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1934, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1934, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 1934, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1934, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1935
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)             # <<<<<<<<<<<<<<
 *         is_boundary_y = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 * 
 */
  __Pyx_TraceLine(1935,0,__PYX_ERR(0, 1935, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_is_boundary_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1936
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_boundary_y = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)             # <<<<<<<<<<<<<<
 * 
 *         if self.dim > 2:
 */
  __Pyx_TraceLine(1936,0,__PYX_ERR(0, 1936, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_is_boundary_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":1938
 *         is_boundary_y = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z
 */
  __Pyx_TraceLine(1938,0,__PYX_ERR(0, 1938, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1938, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1938, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":1939
 * 
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             edges_z = self.edges_z
 * 
 */
    __Pyx_TraceLine(1939,0,__PYX_ERR(0, 1939, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1939, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 1939, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1939, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 1939, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 1939, __pyx_L1_error)
    }
    __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_z0 = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_v_zF = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1940
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z             # <<<<<<<<<<<<<<
 * 
 *             is_boundary_x |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)
 */
    __Pyx_TraceLine(1940,0,__PYX_ERR(0, 1940, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_edges_z = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1942
 *             edges_z = self.edges_z
 * 
 *             is_boundary_x |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             is_boundary_y |= (edges_y[:, 2] == z0) | (edges_y[:, 2] == zF)
 *             is_boundary_z = (
 */
    __Pyx_TraceLine(1942,0,__PYX_ERR(0, 1942, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__23); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__23); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceOr(__pyx_v_is_boundary_x, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1942, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_boundary_x, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1943
 * 
 *             is_boundary_x |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)
 *             is_boundary_y |= (edges_y[:, 2] == z0) | (edges_y[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             is_boundary_z = (
 *                 (edges_z[:, 0] == x0)
 */
    __Pyx_TraceLine(1943,0,__PYX_ERR(0, 1943, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_InPlaceOr(__pyx_v_is_boundary_y, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_boundary_y, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1945
 *             is_boundary_y |= (edges_y[:, 2] == z0) | (edges_y[:, 2] == zF)
 *             is_boundary_z = (
 *                 (edges_z[:, 0] == x0)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)
 */
    __Pyx_TraceLine(1945,0,__PYX_ERR(0, 1945, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1945, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1946
 *             is_boundary_z = (
 *                 (edges_z[:, 0] == x0)
 *                 | (edges_z[:, 0] == xF)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 1] == y0)
 *                 | (edges_z[:, 1] == yF)
 */
    __Pyx_TraceLine(1946,0,__PYX_ERR(0, 1946, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1946, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1946, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1946, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1947
 *                 (edges_z[:, 0] == x0)
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 1] == yF)
 *             )
 */
    __Pyx_TraceLine(1947,0,__PYX_ERR(0, 1947, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1947, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1948
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)
 *                 | (edges_z[:, 1] == yF)             # <<<<<<<<<<<<<<
 *             )
 *             return np.r_[
 */
    __Pyx_TraceLine(1948,0,__PYX_ERR(0, 1948, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1948, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_is_boundary_z = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1950
 *                 | (edges_z[:, 1] == yF)
 *             )
 *             return np.r_[             # <<<<<<<<<<<<<<
 *                 edges_x[is_boundary_x],
 *                 edges_y[is_boundary_y],
 */
    __Pyx_TraceLine(1950,0,__PYX_ERR(0, 1950, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1951
 *             )
 *             return np.r_[
 *                 edges_x[is_boundary_x],             # <<<<<<<<<<<<<<
 *                 edges_y[is_boundary_y],
 *                 edges_z[is_boundary_z]
 */
    __Pyx_TraceLine(1951,0,__PYX_ERR(0, 1951, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_v_is_boundary_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1951, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "discretize/_extensions/tree_ext.pyx":1952
 *             return np.r_[
 *                 edges_x[is_boundary_x],
 *                 edges_y[is_boundary_y],             # <<<<<<<<<<<<<<
 *                 edges_z[is_boundary_z]
 *             ]
 */
    __Pyx_TraceLine(1952,0,__PYX_ERR(0, 1952, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_v_is_boundary_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discretize/_extensions/tree_ext.pyx":1953
 *                 edges_x[is_boundary_x],
 *                 edges_y[is_boundary_y],
 *                 edges_z[is_boundary_z]             # <<<<<<<<<<<<<<
 *             ]
 *         else:
 */
    __Pyx_TraceLine(1953,0,__PYX_ERR(0, 1953, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_v_is_boundary_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "discretize/_extensions/tree_ext.pyx":1950
 *                 | (edges_z[:, 1] == yF)
 *             )
 *             return np.r_[             # <<<<<<<<<<<<<<
 *                 edges_x[is_boundary_x],
 *                 edges_y[is_boundary_y],
 */
    __Pyx_TraceLine(1950,0,__PYX_ERR(0, 1950, __pyx_L1_error))
    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
    __pyx_t_5 = 0;
    __pyx_t_1 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1950, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":1938
 *         is_boundary_y = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1956
 *             ]
 *         else:
 *             return np.r_[edges_x[is_boundary_x], edges_y[is_boundary_y]]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1956,0,__PYX_ERR(0, 1956, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_r); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_v_is_boundary_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_v_is_boundary_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1918
 * 
 *     @property
 *     def boundary_edges(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary edge locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.boundary_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_edges_x);
  __Pyx_XDECREF(__pyx_v_edges_y);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_boundary_x);
  __Pyx_XDECREF(__pyx_v_is_boundary_y);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XDECREF(__pyx_v_edges_z);
  __Pyx_XDECREF(__pyx_v_is_boundary_z);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1959
 * 
 *     @property
 *     def faces_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging x-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridFx = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1959, 0, __PYX_ERR(0, 1959, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1970
 *             Gridded locations of all non-hanging x-faces
 *         """
 *         if(self._dim == 2): return self.edges_y             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[:, :] gridFx
 */
  __Pyx_TraceLine(1970,0,__PYX_ERR(0, 1970, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1970, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":1975
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(1975,0,__PYX_ERR(0, 1975, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_faces_x == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":1976
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_x is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 *             gridFx = self._faces_x
 */
    __Pyx_TraceLine(1976,0,__PYX_ERR(0, 1976, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_4;

    /* "discretize/_extensions/tree_ext.pyx":1977
 *         if self._faces_x is None:
 *             dim = self._dim
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridFx = self._faces_x
 *             for it in self.tree.faces_x:
 */
    __Pyx_TraceLine(1977,0,__PYX_ERR(0, 1977, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_faces_x);
    __Pyx_DECREF(__pyx_v_self->_faces_x);
    __pyx_v_self->_faces_x = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":1978
 *             dim = self._dim
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 *             gridFx = self._faces_x             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_x:
 *                 face = it.second
 */
    __Pyx_TraceLine(1978,0,__PYX_ERR(0, 1978, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_faces_x, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1978, __pyx_L1_error)
    __pyx_v_gridFx = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":1979
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 *             gridFx = self._faces_x
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
    __Pyx_TraceLine(1979,0,__PYX_ERR(0, 1979, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_x;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":1980
 *             gridFx = self._faces_x
 *             for it in self.tree.faces_x:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if not face.hanging:
 *                     ind = face.index
 */
      __Pyx_TraceLine(1980,0,__PYX_ERR(0, 1980, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":1981
 *             for it in self.tree.faces_x:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(1981,0,__PYX_ERR(0, 1981, __pyx_L1_error))
      __pyx_t_3 = ((!(__pyx_v_face->hanging != 0)) != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":1982
 *                 face = it.second
 *                 if not face.hanging:
 *                     ind = face.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridFx[ind, ii] = face.location[ii]
 */
        __Pyx_TraceLine(1982,0,__PYX_ERR(0, 1982, __pyx_L1_error))
        __pyx_t_4 = __pyx_v_face->index;
        __pyx_v_ind = __pyx_t_4;

        /* "discretize/_extensions/tree_ext.pyx":1983
 *                 if not face.hanging:
 *                     ind = face.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridFx[ind, ii] = face.location[ii]
 *         return self._faces_x
 */
        __Pyx_TraceLine(1983,0,__PYX_ERR(0, 1983, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":1984
 *                     ind = face.index
 *                     for ii in range(dim):
 *                         gridFx[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._faces_x
 * 
 */
          __Pyx_TraceLine(1984,0,__PYX_ERR(0, 1984, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridFx.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridFx.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridFx.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridFx.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 1984, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridFx.data + __pyx_t_17 * __pyx_v_gridFx.strides[0]) ) + __pyx_t_18 * __pyx_v_gridFx.strides[1]) )) = (__pyx_v_face->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":1981
 *             for it in self.tree.faces_x:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":1979
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 *             gridFx = self._faces_x
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
      __Pyx_TraceLine(1979,0,__PYX_ERR(0, 1979, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":1975
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_x = np.empty((self.n_faces_x, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":1985
 *                     for ii in range(dim):
 *                         gridFx[ind, ii] = face.location[ii]
 *         return self._faces_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(1985,0,__PYX_ERR(0, 1985, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_faces_x);
  __pyx_r = __pyx_v_self->_faces_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1959
 * 
 *     @property
 *     def faces_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging x-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.faces_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridFx, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":1988
 * 
 *     @property
 *     def faces_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging y-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridFy = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1988, 0, __PYX_ERR(0, 1988, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":1999
 *             Gridded locations of all non-hanging y-faces
 *         """
 *         if(self._dim == 2): return self.edges_x             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:, :] gridFy
 *         cdef Face *face
 */
  __Pyx_TraceLine(1999,0,__PYX_ERR(0, 1999, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2003
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(2003,0,__PYX_ERR(0, 2003, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_faces_y == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":2004
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_y is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 *             gridFy = self._faces_y
 */
    __Pyx_TraceLine(2004,0,__PYX_ERR(0, 2004, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_4;

    /* "discretize/_extensions/tree_ext.pyx":2005
 *         if self._faces_y is None:
 *             dim = self._dim
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridFy = self._faces_y
 *             for it in self.tree.faces_y:
 */
    __Pyx_TraceLine(2005,0,__PYX_ERR(0, 2005, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_faces_y);
    __Pyx_DECREF(__pyx_v_self->_faces_y);
    __pyx_v_self->_faces_y = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2006
 *             dim = self._dim
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 *             gridFy = self._faces_y             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_y:
 *                 face = it.second
 */
    __Pyx_TraceLine(2006,0,__PYX_ERR(0, 2006, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_faces_y, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2006, __pyx_L1_error)
    __pyx_v_gridFy = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2007
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 *             gridFy = self._faces_y
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
    __Pyx_TraceLine(2007,0,__PYX_ERR(0, 2007, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_y;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2008
 *             gridFy = self._faces_y
 *             for it in self.tree.faces_y:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if not face.hanging:
 *                     ind = face.index
 */
      __Pyx_TraceLine(2008,0,__PYX_ERR(0, 2008, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2009
 *             for it in self.tree.faces_y:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(2009,0,__PYX_ERR(0, 2009, __pyx_L1_error))
      __pyx_t_3 = ((!(__pyx_v_face->hanging != 0)) != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":2010
 *                 face = it.second
 *                 if not face.hanging:
 *                     ind = face.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridFy[ind, ii] = face.location[ii]
 */
        __Pyx_TraceLine(2010,0,__PYX_ERR(0, 2010, __pyx_L1_error))
        __pyx_t_4 = __pyx_v_face->index;
        __pyx_v_ind = __pyx_t_4;

        /* "discretize/_extensions/tree_ext.pyx":2011
 *                 if not face.hanging:
 *                     ind = face.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridFy[ind, ii] = face.location[ii]
 *         return self._faces_y
 */
        __Pyx_TraceLine(2011,0,__PYX_ERR(0, 2011, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":2012
 *                     ind = face.index
 *                     for ii in range(dim):
 *                         gridFy[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._faces_y
 * 
 */
          __Pyx_TraceLine(2012,0,__PYX_ERR(0, 2012, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridFy.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridFy.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridFy.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridFy.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 2012, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridFy.data + __pyx_t_17 * __pyx_v_gridFy.strides[0]) ) + __pyx_t_18 * __pyx_v_gridFy.strides[1]) )) = (__pyx_v_face->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":2009
 *             for it in self.tree.faces_y:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2007
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 *             gridFy = self._faces_y
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
      __Pyx_TraceLine(2007,0,__PYX_ERR(0, 2007, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2003
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_y = np.empty((self.n_faces_y, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2013
 *                     for ii in range(dim):
 *                         gridFy[ind, ii] = face.location[ii]
 *         return self._faces_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2013,0,__PYX_ERR(0, 2013, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_faces_y);
  __pyx_r = __pyx_v_self->_faces_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":1988
 * 
 *     @property
 *     def faces_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging y-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.faces_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridFy, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2016
 * 
 *     @property
 *     def faces_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging z-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridFz = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  __pyx_t_5numpy_int64_t __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2016, 0, __PYX_ERR(0, 2016, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2027
 *             Gridded locations of all non-hanging z-faces
 *         """
 *         if(self._dim == 2): return self.cell_centers             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[:, :] gridFz
 */
  __Pyx_TraceLine(2027,0,__PYX_ERR(0, 2027, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cell_centers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2027, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2032
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(2032,0,__PYX_ERR(0, 2032, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_faces_z == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":2033
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_z is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 *             gridFz = self._faces_z
 */
    __Pyx_TraceLine(2033,0,__PYX_ERR(0, 2033, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_4;

    /* "discretize/_extensions/tree_ext.pyx":2034
 *         if self._faces_z is None:
 *             dim = self._dim
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridFz = self._faces_z
 *             for it in self.tree.faces_z:
 */
    __Pyx_TraceLine(2034,0,__PYX_ERR(0, 2034, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_faces_z);
    __Pyx_DECREF(__pyx_v_self->_faces_z);
    __pyx_v_self->_faces_z = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2035
 *             dim = self._dim
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 *             gridFz = self._faces_z             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_z:
 *                 face = it.second
 */
    __Pyx_TraceLine(2035,0,__PYX_ERR(0, 2035, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_faces_z, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2035, __pyx_L1_error)
    __pyx_v_gridFz = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2036
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 *             gridFz = self._faces_z
 *             for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
    __Pyx_TraceLine(2036,0,__PYX_ERR(0, 2036, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_z;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2037
 *             gridFz = self._faces_z
 *             for it in self.tree.faces_z:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if not face.hanging:
 *                     ind = face.index
 */
      __Pyx_TraceLine(2037,0,__PYX_ERR(0, 2037, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2038
 *             for it in self.tree.faces_z:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      __Pyx_TraceLine(2038,0,__PYX_ERR(0, 2038, __pyx_L1_error))
      __pyx_t_3 = ((!(__pyx_v_face->hanging != 0)) != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":2039
 *                 face = it.second
 *                 if not face.hanging:
 *                     ind = face.index             # <<<<<<<<<<<<<<
 *                     for ii in range(dim):
 *                         gridFz[ind, ii] = face.location[ii]
 */
        __Pyx_TraceLine(2039,0,__PYX_ERR(0, 2039, __pyx_L1_error))
        __pyx_t_4 = __pyx_v_face->index;
        __pyx_v_ind = __pyx_t_4;

        /* "discretize/_extensions/tree_ext.pyx":2040
 *                 if not face.hanging:
 *                     ind = face.index
 *                     for ii in range(dim):             # <<<<<<<<<<<<<<
 *                         gridFz[ind, ii] = face.location[ii]
 *         return self._faces_z
 */
        __Pyx_TraceLine(2040,0,__PYX_ERR(0, 2040, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_dim;
        __pyx_t_15 = __pyx_t_14;
        for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
          __pyx_v_ii = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":2041
 *                     ind = face.index
 *                     for ii in range(dim):
 *                         gridFz[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._faces_z
 * 
 */
          __Pyx_TraceLine(2041,0,__PYX_ERR(0, 2041, __pyx_L1_error))
          __pyx_t_17 = __pyx_v_ind;
          __pyx_t_18 = __pyx_v_ii;
          __pyx_t_19 = -1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_gridFz.shape[0];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_gridFz.shape[0])) __pyx_t_19 = 0;
          if (__pyx_t_18 < 0) {
            __pyx_t_18 += __pyx_v_gridFz.shape[1];
            if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
          } else if (unlikely(__pyx_t_18 >= __pyx_v_gridFz.shape[1])) __pyx_t_19 = 1;
          if (unlikely(__pyx_t_19 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_19);
            __PYX_ERR(0, 2041, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridFz.data + __pyx_t_17 * __pyx_v_gridFz.strides[0]) ) + __pyx_t_18 * __pyx_v_gridFz.strides[1]) )) = (__pyx_v_face->location[__pyx_v_ii]);
        }

        /* "discretize/_extensions/tree_ext.pyx":2038
 *             for it in self.tree.faces_z:
 *                 face = it.second
 *                 if not face.hanging:             # <<<<<<<<<<<<<<
 *                     ind = face.index
 *                     for ii in range(dim):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2036
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 *             gridFz = self._faces_z
 *             for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if not face.hanging:
 */
      __Pyx_TraceLine(2036,0,__PYX_ERR(0, 2036, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2032
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._faces_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._faces_z = np.empty((self.n_faces_z, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2042
 *                     for ii in range(dim):
 *                         gridFz[ind, ii] = face.location[ii]
 *         return self._faces_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2042,0,__PYX_ERR(0, 2042, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_faces_z);
  __pyx_r = __pyx_v_self->_faces_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2016
 * 
 *     @property
 *     def faces_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of non-hanging z-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.faces_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridFz, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2045
 * 
 *     @property
 *     def hanging_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging x-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_v_gridhFx = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  std::vector<Face *> ::iterator __pyx_t_9;
  std::vector<Face *>  *__pyx_t_10;
  Face *__pyx_t_11;
  __pyx_t_5numpy_int64_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2045, 0, __PYX_ERR(0, 2045, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2056
 *             Gridded locations of all hanging x-faces
 *         """
 *         if(self._dim == 2): return self.hanging_edges_y             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[:, :] gridFx
 */
  __Pyx_TraceLine(2056,0,__PYX_ERR(0, 2056, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hanging_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2061
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(2061,0,__PYX_ERR(0, 2061, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_faces_x == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":2062
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_x is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 *             gridhFx = self._hanging_faces_x
 */
    __Pyx_TraceLine(2062,0,__PYX_ERR(0, 2062, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_4;

    /* "discretize/_extensions/tree_ext.pyx":2063
 *         if self._hanging_faces_x is None:
 *             dim = self._dim
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhFx = self._hanging_faces_x
 *             for face in self.tree.hanging_faces_x:
 */
    __Pyx_TraceLine(2063,0,__PYX_ERR(0, 2063, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_x);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_x);
    __pyx_v_self->_hanging_faces_x = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2064
 *             dim = self._dim
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 *             gridhFx = self._hanging_faces_x             # <<<<<<<<<<<<<<
 *             for face in self.tree.hanging_faces_x:
 *                 ind = face.index-self.n_faces_x
 */
    __Pyx_TraceLine(2064,0,__PYX_ERR(0, 2064, __pyx_L1_error))
    __pyx_t_8 = __pyx_v_self->_hanging_faces_x;
    __Pyx_INCREF(__pyx_t_8);
    __pyx_v_gridhFx = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2065
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 *             gridhFx = self._hanging_faces_x
 *             for face in self.tree.hanging_faces_x:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_x
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(2065,0,__PYX_ERR(0, 2065, __pyx_L1_error))
    __pyx_t_10 = &__pyx_v_self->tree->hanging_faces_x;
    __pyx_t_9 = __pyx_t_10->begin();
    for (;;) {
      if (!(__pyx_t_9 != __pyx_t_10->end())) break;
      __pyx_t_11 = *__pyx_t_9;
      ++__pyx_t_9;
      __pyx_v_face = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2066
 *             gridhFx = self._hanging_faces_x
 *             for face in self.tree.hanging_faces_x:
 *                 ind = face.index-self.n_faces_x             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhFx[ind, ii] = face.location[ii]
 */
      __Pyx_TraceLine(2066,0,__PYX_ERR(0, 2066, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_face->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2066, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2066, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2066, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_12 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2066, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2067
 *             for face in self.tree.hanging_faces_x:
 *                 ind = face.index-self.n_faces_x
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhFx[ind, ii] = face.location[ii]
 *         return self._hanging_faces_x
 */
      __Pyx_TraceLine(2067,0,__PYX_ERR(0, 2067, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_dim;
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_ii = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":2068
 *                 ind = face.index-self.n_faces_x
 *                 for ii in range(dim):
 *                     gridhFx[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_faces_x
 * 
 */
        __Pyx_TraceLine(2068,0,__PYX_ERR(0, 2068, __pyx_L1_error))
        __pyx_t_6 = PyFloat_FromDouble((__pyx_v_face->location[__pyx_v_ii])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2068, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyInt_From_npy_int64(__pyx_v_ind); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2068, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_npy_int64(__pyx_v_ii); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2068, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2068, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_gridhFx, __pyx_t_5, __pyx_t_6) < 0)) __PYX_ERR(0, 2068, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }

      /* "discretize/_extensions/tree_ext.pyx":2065
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 *             gridhFx = self._hanging_faces_x
 *             for face in self.tree.hanging_faces_x:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_x
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(2065,0,__PYX_ERR(0, 2065, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2061
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_x is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_x = np.empty((self.n_hanging_faces_x, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2069
 *                 for ii in range(dim):
 *                     gridhFx[ind, ii] = face.location[ii]
 *         return self._hanging_faces_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2069,0,__PYX_ERR(0, 2069, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_faces_x);
  __pyx_r = __pyx_v_self->_hanging_faces_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2045
 * 
 *     @property
 *     def hanging_faces_x(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging x-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_faces_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_gridhFx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2072
 * 
 *     @property
 *     def hanging_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging y-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridhFy = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Face *> ::iterator __pyx_t_10;
  std::vector<Face *>  *__pyx_t_11;
  Face *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2072, 0, __PYX_ERR(0, 2072, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2083
 *             Gridded locations of all hanging y-faces
 *         """
 *         if(self._dim == 2): return self.hanging_edges_x             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[:, :] gridhFy
 */
  __Pyx_TraceLine(2083,0,__PYX_ERR(0, 2083, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hanging_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2083, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2088
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(2088,0,__PYX_ERR(0, 2088, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_faces_y == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":2089
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_y is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 *             gridhFy = self._hanging_faces_y
 */
    __Pyx_TraceLine(2089,0,__PYX_ERR(0, 2089, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_4;

    /* "discretize/_extensions/tree_ext.pyx":2090
 *         if self._hanging_faces_y is None:
 *             dim = self._dim
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhFy = self._hanging_faces_y
 *             for face in self.tree.hanging_faces_y:
 */
    __Pyx_TraceLine(2090,0,__PYX_ERR(0, 2090, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_y);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_y);
    __pyx_v_self->_hanging_faces_y = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2091
 *             dim = self._dim
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 *             gridhFy = self._hanging_faces_y             # <<<<<<<<<<<<<<
 *             for face in self.tree.hanging_faces_y:
 *                 ind = face.index-self.n_faces_y
 */
    __Pyx_TraceLine(2091,0,__PYX_ERR(0, 2091, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_hanging_faces_y, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2091, __pyx_L1_error)
    __pyx_v_gridhFy = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2092
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 *             gridhFy = self._hanging_faces_y
 *             for face in self.tree.hanging_faces_y:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_y
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(2092,0,__PYX_ERR(0, 2092, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->hanging_faces_y;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_face = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2093
 *             gridhFy = self._hanging_faces_y
 *             for face in self.tree.hanging_faces_y:
 *                 ind = face.index-self.n_faces_y             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhFy[ind, ii] = face.location[ii]
 */
      __Pyx_TraceLine(2093,0,__PYX_ERR(0, 2093, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_face->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyNumber_Subtract(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_npy_int64(__pyx_t_6); if (unlikely((__pyx_t_13 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2093, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2094
 *             for face in self.tree.hanging_faces_y:
 *                 ind = face.index-self.n_faces_y
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhFy[ind, ii] = face.location[ii]
 *         return self._hanging_faces_y
 */
      __Pyx_TraceLine(2094,0,__PYX_ERR(0, 2094, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_dim;
      __pyx_t_14 = __pyx_t_13;
      for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
        __pyx_v_ii = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":2095
 *                 ind = face.index-self.n_faces_y
 *                 for ii in range(dim):
 *                     gridhFy[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_faces_y
 * 
 */
        __Pyx_TraceLine(2095,0,__PYX_ERR(0, 2095, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_ind;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_gridhFy.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_gridhFy.shape[0])) __pyx_t_18 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridhFy.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridhFy.shape[1])) __pyx_t_18 = 1;
        if (unlikely(__pyx_t_18 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_18);
          __PYX_ERR(0, 2095, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridhFy.data + __pyx_t_16 * __pyx_v_gridhFy.strides[0]) ) + __pyx_t_17 * __pyx_v_gridhFy.strides[1]) )) = (__pyx_v_face->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":2092
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 *             gridhFy = self._hanging_faces_y
 *             for face in self.tree.hanging_faces_y:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_y
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(2092,0,__PYX_ERR(0, 2092, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2088
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_y is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_y = np.empty((self.n_hanging_faces_y, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2096
 *                 for ii in range(dim):
 *                     gridhFy[ind, ii] = face.location[ii]
 *         return self._hanging_faces_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2096,0,__PYX_ERR(0, 2096, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_faces_y);
  __pyx_r = __pyx_v_self->_hanging_faces_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2072
 * 
 *     @property
 *     def hanging_faces_y(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging y-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_faces_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridhFy, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2099
 * 
 *     @property
 *     def hanging_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging z-faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_gridhFz = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_dim;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Face *> ::iterator __pyx_t_10;
  std::vector<Face *>  *__pyx_t_11;
  Face *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2099, 0, __PYX_ERR(0, 2099, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2110
 *             Gridded locations of all hanging z-faces
 *         """
 *         if(self._dim == 2): return np.array([])             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[:, :] gridhFz
 */
  __Pyx_TraceLine(2110,0,__PYX_ERR(0, 2110, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2115
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 */
  __Pyx_TraceLine(2115,0,__PYX_ERR(0, 2115, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_hanging_faces_z == Py_None);
  __pyx_t_6 = (__pyx_t_1 != 0);
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":2116
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_z is None:
 *             dim = self._dim             # <<<<<<<<<<<<<<
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 *             gridhFz = self._hanging_faces_z
 */
    __Pyx_TraceLine(2116,0,__PYX_ERR(0, 2116, __pyx_L1_error))
    __pyx_t_7 = __pyx_v_self->_dim;
    __pyx_v_dim = __pyx_t_7;

    /* "discretize/_extensions/tree_ext.pyx":2117
 *         if self._hanging_faces_z is None:
 *             dim = self._dim
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)             # <<<<<<<<<<<<<<
 *             gridhFz = self._hanging_faces_z
 *             for face in self.tree.hanging_faces_z:
 */
    __Pyx_TraceLine(2117,0,__PYX_ERR(0, 2117, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_hanging_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_From_npy_int64(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2117, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_hanging_faces_z);
    __Pyx_DECREF(__pyx_v_self->_hanging_faces_z);
    __pyx_v_self->_hanging_faces_z = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2118
 *             dim = self._dim
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 *             gridhFz = self._hanging_faces_z             # <<<<<<<<<<<<<<
 *             for face in self.tree.hanging_faces_z:
 *                 ind = face.index-self.n_faces_z
 */
    __Pyx_TraceLine(2118,0,__PYX_ERR(0, 2118, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_hanging_faces_z, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2118, __pyx_L1_error)
    __pyx_v_gridhFz = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2119
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 *             gridhFz = self._hanging_faces_z
 *             for face in self.tree.hanging_faces_z:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_z
 *                 for ii in range(dim):
 */
    __Pyx_TraceLine(2119,0,__PYX_ERR(0, 2119, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->hanging_faces_z;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_face = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2120
 *             gridhFz = self._hanging_faces_z
 *             for face in self.tree.hanging_faces_z:
 *                 ind = face.index-self.n_faces_z             # <<<<<<<<<<<<<<
 *                 for ii in range(dim):
 *                     gridhFz[ind, ii] = face.location[ii]
 */
      __Pyx_TraceLine(2120,0,__PYX_ERR(0, 2120, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_face->index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2120, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2120, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyNumber_Subtract(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2120, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_npy_int64(__pyx_t_3); if (unlikely((__pyx_t_13 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2120, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2121
 *             for face in self.tree.hanging_faces_z:
 *                 ind = face.index-self.n_faces_z
 *                 for ii in range(dim):             # <<<<<<<<<<<<<<
 *                     gridhFz[ind, ii] = face.location[ii]
 *         return self._hanging_faces_z
 */
      __Pyx_TraceLine(2121,0,__PYX_ERR(0, 2121, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_dim;
      __pyx_t_14 = __pyx_t_13;
      for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
        __pyx_v_ii = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":2122
 *                 ind = face.index-self.n_faces_z
 *                 for ii in range(dim):
 *                     gridhFz[ind, ii] = face.location[ii]             # <<<<<<<<<<<<<<
 *         return self._hanging_faces_z
 * 
 */
        __Pyx_TraceLine(2122,0,__PYX_ERR(0, 2122, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_ind;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_gridhFz.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_gridhFz.shape[0])) __pyx_t_18 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_gridhFz.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_gridhFz.shape[1])) __pyx_t_18 = 1;
        if (unlikely(__pyx_t_18 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_18);
          __PYX_ERR(0, 2122, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_gridhFz.data + __pyx_t_16 * __pyx_v_gridhFz.strides[0]) ) + __pyx_t_17 * __pyx_v_gridhFz.strides[1]) )) = (__pyx_v_face->location[__pyx_v_ii]);
      }

      /* "discretize/_extensions/tree_ext.pyx":2119
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 *             gridhFz = self._hanging_faces_z
 *             for face in self.tree.hanging_faces_z:             # <<<<<<<<<<<<<<
 *                 ind = face.index-self.n_faces_z
 *                 for ii in range(dim):
 */
      __Pyx_TraceLine(2119,0,__PYX_ERR(0, 2119, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2115
 *         cdef Face *face
 *         cdef np.int64_t ii, ind, dim
 *         if self._hanging_faces_z is None:             # <<<<<<<<<<<<<<
 *             dim = self._dim
 *             self._hanging_faces_z = np.empty((self.n_hanging_faces_z, dim), dtype=np.float64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2123
 *                 for ii in range(dim):
 *                     gridhFz[ind, ii] = face.location[ii]
 *         return self._hanging_faces_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2123,0,__PYX_ERR(0, 2123, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_hanging_faces_z);
  __pyx_r = __pyx_v_self->_hanging_faces_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2099
 * 
 *     @property
 *     def hanging_faces_z(self):             # <<<<<<<<<<<<<<
 *         """Gridded locations of hanging z-faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.hanging_faces_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_gridhFz, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2126
 * 
 *     @property
 *     def boundary_faces(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary face locations.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_faces_x = NULL;
  PyObject *__pyx_v_faces_y = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_boundary_x = NULL;
  PyObject *__pyx_v_is_boundary_y = NULL;
  PyObject *__pyx_v_boundary_faces = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_v_faces_z = NULL;
  PyObject *__pyx_v_is_boundary_z = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2126, 0, __PYX_ERR(0, 2126, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2139
 *             Gridded boundary face locations
 *         """
 *         faces_x = self.faces_x             # <<<<<<<<<<<<<<
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]
 */
  __Pyx_TraceLine(2139,0,__PYX_ERR(0, 2139, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2140
 *         """
 *         faces_x = self.faces_x
 *         faces_y = self.faces_y             # <<<<<<<<<<<<<<
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 */
  __Pyx_TraceLine(2140,0,__PYX_ERR(0, 2140, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2141
 *         faces_x = self.faces_x
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF)
 */
  __Pyx_TraceLine(2141,0,__PYX_ERR(0, 2141, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2141, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2141, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2141, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2141, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2142
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_boundary_x = (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF)
 *         is_boundary_y = (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 */
  __Pyx_TraceLine(2142,0,__PYX_ERR(0, 2142, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2142, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2142, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2142, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2142, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2143
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF)             # <<<<<<<<<<<<<<
 *         is_boundary_y = (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 * 
 */
  __Pyx_TraceLine(2143,0,__PYX_ERR(0, 2143, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2143, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2143, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2143, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2143, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2143, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_is_boundary_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2144
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary_x = (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF)
 *         is_boundary_y = (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)             # <<<<<<<<<<<<<<
 * 
 *         boundary_faces = np.r_[faces_x[is_boundary_x], faces_y[is_boundary_y]]
 */
  __Pyx_TraceLine(2144,0,__PYX_ERR(0, 2144, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2144, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2144, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2144, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2144, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2144, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_is_boundary_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2146
 *         is_boundary_y = (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 * 
 *         boundary_faces = np.r_[faces_x[is_boundary_x], faces_y[is_boundary_y]]             # <<<<<<<<<<<<<<
 * 
 *         if self.dim > 2:
 */
  __Pyx_TraceLine(2146,0,__PYX_ERR(0, 2146, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_v_is_boundary_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_v_is_boundary_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __pyx_t_1 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_boundary_faces = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2148
 *         boundary_faces = np.r_[faces_x[is_boundary_x], faces_y[is_boundary_y]]
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z
 */
  __Pyx_TraceLine(2148,0,__PYX_ERR(0, 2148, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2148, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2148, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":2149
 * 
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             faces_z = self.faces_z
 * 
 */
    __Pyx_TraceLine(2149,0,__PYX_ERR(0, 2149, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2149, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 2149, __pyx_L1_error)
    }
    __pyx_t_6 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2149, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 2149, __pyx_L1_error)
    }
    __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_z0 = __pyx_t_6;
    __pyx_t_6 = 0;
    __pyx_v_zF = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2150
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z             # <<<<<<<<<<<<<<
 * 
 *             is_boundary_z = (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 */
    __Pyx_TraceLine(2150,0,__PYX_ERR(0, 2150, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2150, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_faces_z = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2152
 *             faces_z = self.faces_z
 * 
 *             is_boundary_z = (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             boundary_faces = np.r_[boundary_faces, faces_z[is_boundary_z]]
 *         return boundary_faces
 */
    __Pyx_TraceLine(2152,0,__PYX_ERR(0, 2152, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2152, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2152, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_is_boundary_z = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2153
 * 
 *             is_boundary_z = (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 *             boundary_faces = np.r_[boundary_faces, faces_z[is_boundary_z]]             # <<<<<<<<<<<<<<
 *         return boundary_faces
 * 
 */
    __Pyx_TraceLine(2153,0,__PYX_ERR(0, 2153, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2153, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2153, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_v_is_boundary_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2153, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2153, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_boundary_faces);
    __Pyx_GIVEREF(__pyx_v_boundary_faces);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_boundary_faces);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2153, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_boundary_faces, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2148
 *         boundary_faces = np.r_[faces_x[is_boundary_x], faces_y[is_boundary_y]]
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2154
 *             is_boundary_z = (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 *             boundary_faces = np.r_[boundary_faces, faces_z[is_boundary_z]]
 *         return boundary_faces             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2154,0,__PYX_ERR(0, 2154, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_boundary_faces);
  __pyx_r = __pyx_v_boundary_faces;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2126
 * 
 *     @property
 *     def boundary_faces(self):             # <<<<<<<<<<<<<<
 *         """Gridded boundary face locations.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.boundary_faces.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_faces_x);
  __Pyx_XDECREF(__pyx_v_faces_y);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_boundary_x);
  __Pyx_XDECREF(__pyx_v_is_boundary_y);
  __Pyx_XDECREF(__pyx_v_boundary_faces);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XDECREF(__pyx_v_faces_z);
  __Pyx_XDECREF(__pyx_v_is_boundary_z);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2157
 * 
 *     @property
 *     def boundary_face_outward_normals(self):             # <<<<<<<<<<<<<<
 *         """Outward normals of boundary faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_faces_x = NULL;
  PyObject *__pyx_v_faces_y = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_bxm = NULL;
  PyObject *__pyx_v_is_boundary_x = NULL;
  PyObject *__pyx_v_is_bym = NULL;
  PyObject *__pyx_v_is_boundary_y = NULL;
  PyObject *__pyx_v_is_boundary = NULL;
  PyObject *__pyx_v_switch = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_v_faces_z = NULL;
  PyObject *__pyx_v_is_bzm = NULL;
  PyObject *__pyx_v_is_boundary_z = NULL;
  PyObject *__pyx_v_face_normals = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2157, 0, __PYX_ERR(0, 2157, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2168
 *             Outward normals of boundary faces
 *         """
 *         faces_x = self.faces_x             # <<<<<<<<<<<<<<
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]
 */
  __Pyx_TraceLine(2168,0,__PYX_ERR(0, 2168, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2169
 *         """
 *         faces_x = self.faces_x
 *         faces_y = self.faces_y             # <<<<<<<<<<<<<<
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 */
  __Pyx_TraceLine(2169,0,__PYX_ERR(0, 2169, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2170
 *         faces_x = self.faces_x
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bxm = faces_x[:, 0] == x0
 */
  __Pyx_TraceLine(2170,0,__PYX_ERR(0, 2170, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2170, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2170, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2170, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2170, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2171
 *         faces_y = self.faces_y
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_bxm = faces_x[:, 0] == x0
 *         is_boundary_x = is_bxm | (faces_x[:, 0] == xF)
 */
  __Pyx_TraceLine(2171,0,__PYX_ERR(0, 2171, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2171, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2171, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2171, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 2171, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2172
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bxm = faces_x[:, 0] == x0             # <<<<<<<<<<<<<<
 *         is_boundary_x = is_bxm | (faces_x[:, 0] == xF)
 *         is_bym = faces_y[:, 1] == y0
 */
  __Pyx_TraceLine(2172,0,__PYX_ERR(0, 2172, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_bxm = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2173
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bxm = faces_x[:, 0] == x0
 *         is_boundary_x = is_bxm | (faces_x[:, 0] == xF)             # <<<<<<<<<<<<<<
 *         is_bym = faces_y[:, 1] == y0
 *         is_boundary_y = is_bym | (faces_y[:, 1] == yF)
 */
  __Pyx_TraceLine(2173,0,__PYX_ERR(0, 2173, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Or(__pyx_v_is_bxm, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_boundary_x = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2174
 *         is_bxm = faces_x[:, 0] == x0
 *         is_boundary_x = is_bxm | (faces_x[:, 0] == xF)
 *         is_bym = faces_y[:, 1] == y0             # <<<<<<<<<<<<<<
 *         is_boundary_y = is_bym | (faces_y[:, 1] == yF)
 * 
 */
  __Pyx_TraceLine(2174,0,__PYX_ERR(0, 2174, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2174, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_is_bym = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2175
 *         is_boundary_x = is_bxm | (faces_x[:, 0] == xF)
 *         is_bym = faces_y[:, 1] == y0
 *         is_boundary_y = is_bym | (faces_y[:, 1] == yF)             # <<<<<<<<<<<<<<
 * 
 *         is_boundary = np.r_[is_boundary_x, is_boundary_y]
 */
  __Pyx_TraceLine(2175,0,__PYX_ERR(0, 2175, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2175, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_v_is_bym, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_is_boundary_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2177
 *         is_boundary_y = is_bym | (faces_y[:, 1] == yF)
 * 
 *         is_boundary = np.r_[is_boundary_x, is_boundary_y]             # <<<<<<<<<<<<<<
 *         switch = np.r_[is_bxm, is_bym]
 * 
 */
  __Pyx_TraceLine(2177,0,__PYX_ERR(0, 2177, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_is_boundary_x);
  __Pyx_GIVEREF(__pyx_v_is_boundary_x);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_is_boundary_x);
  __Pyx_INCREF(__pyx_v_is_boundary_y);
  __Pyx_GIVEREF(__pyx_v_is_boundary_y);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_is_boundary_y);
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_boundary = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2178
 * 
 *         is_boundary = np.r_[is_boundary_x, is_boundary_y]
 *         switch = np.r_[is_bxm, is_bym]             # <<<<<<<<<<<<<<
 * 
 *         if self.dim > 2:
 */
  __Pyx_TraceLine(2178,0,__PYX_ERR(0, 2178, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_r); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_is_bxm);
  __Pyx_GIVEREF(__pyx_v_is_bxm);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_is_bxm);
  __Pyx_INCREF(__pyx_v_is_bym);
  __Pyx_GIVEREF(__pyx_v_is_bym);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_is_bym);
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_switch = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2180
 *         switch = np.r_[is_bxm, is_bym]
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z
 */
  __Pyx_TraceLine(2180,0,__PYX_ERR(0, 2180, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":2181
 * 
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             faces_z = self.faces_z
 *             is_bzm = faces_z[:, 2] == z0
 */
    __Pyx_TraceLine(2181,0,__PYX_ERR(0, 2181, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2181, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 2181, __pyx_L1_error)
    }
    __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 2181, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 2181, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_z0 = __pyx_t_5;
    __pyx_t_5 = 0;
    __pyx_v_zF = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2182
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z             # <<<<<<<<<<<<<<
 *             is_bzm = faces_z[:, 2] == z0
 *             is_boundary_z = is_bzm | (faces_z[:, 2] == zF)
 */
    __Pyx_TraceLine(2182,0,__PYX_ERR(0, 2182, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_faces_z = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2183
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z
 *             is_bzm = faces_z[:, 2] == z0             # <<<<<<<<<<<<<<
 *             is_boundary_z = is_bzm | (faces_z[:, 2] == zF)
 * 
 */
    __Pyx_TraceLine(2183,0,__PYX_ERR(0, 2183, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2183, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2183, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_is_bzm = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2184
 *             faces_z = self.faces_z
 *             is_bzm = faces_z[:, 2] == z0
 *             is_boundary_z = is_bzm | (faces_z[:, 2] == zF)             # <<<<<<<<<<<<<<
 * 
 *             is_boundary = np.r_[is_boundary, is_boundary_z]
 */
    __Pyx_TraceLine(2184,0,__PYX_ERR(0, 2184, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2184, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_v_is_bzm, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_is_boundary_z = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2186
 *             is_boundary_z = is_bzm | (faces_z[:, 2] == zF)
 * 
 *             is_boundary = np.r_[is_boundary, is_boundary_z]             # <<<<<<<<<<<<<<
 *             switch = np.r_[switch, is_bzm]
 * 
 */
    __Pyx_TraceLine(2186,0,__PYX_ERR(0, 2186, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_is_boundary);
    __Pyx_GIVEREF(__pyx_v_is_boundary);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_is_boundary);
    __Pyx_INCREF(__pyx_v_is_boundary_z);
    __Pyx_GIVEREF(__pyx_v_is_boundary_z);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_is_boundary_z);
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_boundary, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2187
 * 
 *             is_boundary = np.r_[is_boundary, is_boundary_z]
 *             switch = np.r_[switch, is_bzm]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(2187,0,__PYX_ERR(0, 2187, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_switch);
    __Pyx_GIVEREF(__pyx_v_switch);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_switch);
    __Pyx_INCREF(__pyx_v_is_bzm);
    __Pyx_GIVEREF(__pyx_v_is_bzm);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_is_bzm);
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_switch, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2180
 *         switch = np.r_[is_bxm, is_bym]
 * 
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             faces_z = self.faces_z
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2190
 * 
 * 
 *         face_normals = self.face_normals.copy()             # <<<<<<<<<<<<<<
 *         face_normals[switch] *= -1
 *         return face_normals[is_boundary]
 */
  __Pyx_TraceLine(2190,0,__PYX_ERR(0, 2190, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_face_normals); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_face_normals = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2191
 * 
 *         face_normals = self.face_normals.copy()
 *         face_normals[switch] *= -1             # <<<<<<<<<<<<<<
 *         return face_normals[is_boundary]
 * 
 */
  __Pyx_TraceLine(2191,0,__PYX_ERR(0, 2191, __pyx_L1_error))
  __Pyx_INCREF(__pyx_v_switch);
  __pyx_t_4 = __pyx_v_switch;
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_face_normals, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_InPlaceMultiply(__pyx_t_5, __pyx_int_neg_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(PyObject_SetItem(__pyx_v_face_normals, __pyx_t_4, __pyx_t_1) < 0)) __PYX_ERR(0, 2191, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2192
 *         face_normals = self.face_normals.copy()
 *         face_normals[switch] *= -1
 *         return face_normals[is_boundary]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2192,0,__PYX_ERR(0, 2192, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_face_normals, __pyx_v_is_boundary); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2157
 * 
 *     @property
 *     def boundary_face_outward_normals(self):             # <<<<<<<<<<<<<<
 *         """Outward normals of boundary faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.boundary_face_outward_normals.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_faces_x);
  __Pyx_XDECREF(__pyx_v_faces_y);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_bxm);
  __Pyx_XDECREF(__pyx_v_is_boundary_x);
  __Pyx_XDECREF(__pyx_v_is_bym);
  __Pyx_XDECREF(__pyx_v_is_boundary_y);
  __Pyx_XDECREF(__pyx_v_is_boundary);
  __Pyx_XDECREF(__pyx_v_switch);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XDECREF(__pyx_v_faces_z);
  __Pyx_XDECREF(__pyx_v_is_bzm);
  __Pyx_XDECREF(__pyx_v_is_boundary_z);
  __Pyx_XDECREF(__pyx_v_face_normals);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2195
 * 
 *     @property
 *     def cell_volumes(self):             # <<<<<<<<<<<<<<
 *         """Return cell volumes.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_vol = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_9;
  std::vector<Cell *>  *__pyx_t_10;
  Cell *__pyx_t_11;
  double __pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2195, 0, __PYX_ERR(0, 2195, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2211
 *         """
 *         cdef np.float64_t[:] vol
 *         if self._cell_volumes is None:             # <<<<<<<<<<<<<<
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)
 *             vol = self._cell_volumes
 */
  __Pyx_TraceLine(2211,0,__PYX_ERR(0, 2211, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_cell_volumes == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2212
 *         cdef np.float64_t[:] vol
 *         if self._cell_volumes is None:
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             vol = self._cell_volumes
 *             for cell in self.tree.cells:
 */
    __Pyx_TraceLine(2212,0,__PYX_ERR(0, 2212, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_self->_cell_volumes);
    __Pyx_DECREF(__pyx_v_self->_cell_volumes);
    __pyx_v_self->_cell_volumes = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2213
 *         if self._cell_volumes is None:
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)
 *             vol = self._cell_volumes             # <<<<<<<<<<<<<<
 *             for cell in self.tree.cells:
 *                 vol[cell.index] = cell.volume
 */
    __Pyx_TraceLine(2213,0,__PYX_ERR(0, 2213, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_cell_volumes, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 2213, __pyx_L1_error)
    __pyx_v_vol = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2214
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)
 *             vol = self._cell_volumes
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 vol[cell.index] = cell.volume
 *         return self._cell_volumes
 */
    __Pyx_TraceLine(2214,0,__PYX_ERR(0, 2214, __pyx_L1_error))
    __pyx_t_10 = &__pyx_v_self->tree->cells;
    __pyx_t_9 = __pyx_t_10->begin();
    for (;;) {
      if (!(__pyx_t_9 != __pyx_t_10->end())) break;
      __pyx_t_11 = *__pyx_t_9;
      ++__pyx_t_9;
      __pyx_v_cell = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2215
 *             vol = self._cell_volumes
 *             for cell in self.tree.cells:
 *                 vol[cell.index] = cell.volume             # <<<<<<<<<<<<<<
 *         return self._cell_volumes
 * 
 */
      __Pyx_TraceLine(2215,0,__PYX_ERR(0, 2215, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_cell->volume;
      __pyx_t_13 = __pyx_v_cell->index;
      __pyx_t_14 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_v_vol.shape[0];
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_v_vol.shape[0])) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 2215, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_vol.data + __pyx_t_13 * __pyx_v_vol.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2214
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)
 *             vol = self._cell_volumes
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 vol[cell.index] = cell.volume
 *         return self._cell_volumes
 */
      __Pyx_TraceLine(2214,0,__PYX_ERR(0, 2214, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":2211
 *         """
 *         cdef np.float64_t[:] vol
 *         if self._cell_volumes is None:             # <<<<<<<<<<<<<<
 *             self._cell_volumes = np.empty(self.n_cells, dtype=np.float64)
 *             vol = self._cell_volumes
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2216
 *             for cell in self.tree.cells:
 *                 vol[cell.index] = cell.volume
 *         return self._cell_volumes             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2216,0,__PYX_ERR(0, 2216, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_cell_volumes);
  __pyx_r = __pyx_v_self->_cell_volumes;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2195
 * 
 *     @property
 *     def cell_volumes(self):             # <<<<<<<<<<<<<<
 *         """Return cell volumes.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.cell_volumes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_vol, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2219
 * 
 *     @property
 *     def face_areas(self):             # <<<<<<<<<<<<<<
 *         """Returns the areas of all cell faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_area = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_offset;
  Face *__pyx_v_face;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  double __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  int __pyx_t_16;
  int_t __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2219, 0, __PYX_ERR(0, 2219, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2234
 *             - *3D:* returns the x, y and z-face areas in order
 *         """
 *         if self._dim == 2 and self._face_areas is None:             # <<<<<<<<<<<<<<
 *             self._face_areas = np.r_[self.edge_lengths[self.n_edges_x:], self.edge_lengths[:self.n_edges_x]]
 *         cdef np.float64_t[:] area
 */
  __Pyx_TraceLine(2234,0,__PYX_ERR(0, 2234, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->_face_areas == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":2235
 *         """
 *         if self._dim == 2 and self._face_areas is None:
 *             self._face_areas = np.r_[self.edge_lengths[self.n_edges_x:], self.edge_lengths[:self.n_edges_x]]             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] area
 *         cdef int_t ind, offset = 0
 */
    __Pyx_TraceLine(2235,0,__PYX_ERR(0, 2235, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edge_lengths); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_t_4, 0, 0, &__pyx_t_6, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edge_lengths); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_t_6, 0, 0, NULL, &__pyx_t_4, NULL, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_8);
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_self->_face_areas);
    __Pyx_DECREF(__pyx_v_self->_face_areas);
    __pyx_v_self->_face_areas = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2234
 *             - *3D:* returns the x, y and z-face areas in order
 *         """
 *         if self._dim == 2 and self._face_areas is None:             # <<<<<<<<<<<<<<
 *             self._face_areas = np.r_[self.edge_lengths[self.n_edges_x:], self.edge_lengths[:self.n_edges_x]]
 *         cdef np.float64_t[:] area
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2237
 *             self._face_areas = np.r_[self.edge_lengths[self.n_edges_x:], self.edge_lengths[:self.n_edges_x]]
 *         cdef np.float64_t[:] area
 *         cdef int_t ind, offset = 0             # <<<<<<<<<<<<<<
 *         cdef Face *face
 *         if self._face_areas is None:
 */
  __Pyx_TraceLine(2237,0,__PYX_ERR(0, 2237, __pyx_L1_error))
  __pyx_v_offset = 0;

  /* "discretize/_extensions/tree_ext.pyx":2239
 *         cdef int_t ind, offset = 0
 *         cdef Face *face
 *         if self._face_areas is None:             # <<<<<<<<<<<<<<
 *             self._face_areas = np.empty(self.n_faces, dtype=np.float64)
 *             area = self._face_areas
 */
  __Pyx_TraceLine(2239,0,__PYX_ERR(0, 2239, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_face_areas == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":2240
 *         cdef Face *face
 *         if self._face_areas is None:
 *             self._face_areas = np.empty(self.n_faces, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             area = self._face_areas
 * 
 */
    __Pyx_TraceLine(2240,0,__PYX_ERR(0, 2240, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_GOTREF(__pyx_v_self->_face_areas);
    __Pyx_DECREF(__pyx_v_self->_face_areas);
    __pyx_v_self->_face_areas = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2241
 *         if self._face_areas is None:
 *             self._face_areas = np.empty(self.n_faces, dtype=np.float64)
 *             area = self._face_areas             # <<<<<<<<<<<<<<
 * 
 *             for it in self.tree.faces_x:
 */
    __Pyx_TraceLine(2241,0,__PYX_ERR(0, 2241, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_face_areas, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2241, __pyx_L1_error)
    __pyx_v_area = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2243
 *             area = self._face_areas
 * 
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
    __Pyx_TraceLine(2243,0,__PYX_ERR(0, 2243, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_x;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2244
 * 
 *             for it in self.tree.faces_x:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if face.hanging: continue
 *                 area[face.index] = face.area
 */
      __Pyx_TraceLine(2244,0,__PYX_ERR(0, 2244, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2245
 *             for it in self.tree.faces_x:
 *                 face = it.second
 *                 if face.hanging: continue             # <<<<<<<<<<<<<<
 *                 area[face.index] = face.area
 * 
 */
      __Pyx_TraceLine(2245,0,__PYX_ERR(0, 2245, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_face->hanging != 0);
      if (__pyx_t_3) {
        goto __pyx_L7_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":2246
 *                 face = it.second
 *                 if face.hanging: continue
 *                 area[face.index] = face.area             # <<<<<<<<<<<<<<
 * 
 *             offset = self.n_faces_x
 */
      __Pyx_TraceLine(2246,0,__PYX_ERR(0, 2246, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_face->area;
      __pyx_t_15 = __pyx_v_face->index;
      __pyx_t_16 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_area.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_16 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_area.shape[0])) __pyx_t_16 = 0;
      if (unlikely(__pyx_t_16 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_16);
        __PYX_ERR(0, 2246, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_area.data + __pyx_t_15 * __pyx_v_area.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":2243
 *             area = self._face_areas
 * 
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
      __Pyx_TraceLine(2243,0,__PYX_ERR(0, 2243, __pyx_L1_error))
      __pyx_L7_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2248
 *                 area[face.index] = face.area
 * 
 *             offset = self.n_faces_x             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_y:
 *                 face = it.second
 */
    __Pyx_TraceLine(2248,0,__PYX_ERR(0, 2248, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2248, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_17 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_17 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2248, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_offset = __pyx_t_17;

    /* "discretize/_extensions/tree_ext.pyx":2249
 * 
 *             offset = self.n_faces_x
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
    __Pyx_TraceLine(2249,0,__PYX_ERR(0, 2249, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_y;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2250
 *             offset = self.n_faces_x
 *             for it in self.tree.faces_y:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if face.hanging: continue
 *                 area[face.index + offset] = face.area
 */
      __Pyx_TraceLine(2250,0,__PYX_ERR(0, 2250, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2251
 *             for it in self.tree.faces_y:
 *                 face = it.second
 *                 if face.hanging: continue             # <<<<<<<<<<<<<<
 *                 area[face.index + offset] = face.area
 * 
 */
      __Pyx_TraceLine(2251,0,__PYX_ERR(0, 2251, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_face->hanging != 0);
      if (__pyx_t_3) {
        goto __pyx_L10_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":2252
 *                 face = it.second
 *                 if face.hanging: continue
 *                 area[face.index + offset] = face.area             # <<<<<<<<<<<<<<
 * 
 *             offset = self.n_faces_x + self.n_faces_y
 */
      __Pyx_TraceLine(2252,0,__PYX_ERR(0, 2252, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_face->area;
      __pyx_t_15 = (__pyx_v_face->index + __pyx_v_offset);
      __pyx_t_16 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_area.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_16 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_area.shape[0])) __pyx_t_16 = 0;
      if (unlikely(__pyx_t_16 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_16);
        __PYX_ERR(0, 2252, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_area.data + __pyx_t_15 * __pyx_v_area.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":2249
 * 
 *             offset = self.n_faces_x
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
      __Pyx_TraceLine(2249,0,__PYX_ERR(0, 2249, __pyx_L1_error))
      __pyx_L10_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2254
 *                 area[face.index + offset] = face.area
 * 
 *             offset = self.n_faces_x + self.n_faces_y             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_z:
 *                 face = it.second
 */
    __Pyx_TraceLine(2254,0,__PYX_ERR(0, 2254, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2254, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2254, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = PyNumber_Add(__pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2254, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_17 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_17 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2254, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_offset = __pyx_t_17;

    /* "discretize/_extensions/tree_ext.pyx":2255
 * 
 *             offset = self.n_faces_x + self.n_faces_y
 *             for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
    __Pyx_TraceLine(2255,0,__PYX_ERR(0, 2255, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->faces_z;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_it = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2256
 *             offset = self.n_faces_x + self.n_faces_y
 *             for it in self.tree.faces_z:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if face.hanging: continue
 *                 area[face.index + offset] = face.area
 */
      __Pyx_TraceLine(2256,0,__PYX_ERR(0, 2256, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2257
 *             for it in self.tree.faces_z:
 *                 face = it.second
 *                 if face.hanging: continue             # <<<<<<<<<<<<<<
 *                 area[face.index + offset] = face.area
 *         return self._face_areas
 */
      __Pyx_TraceLine(2257,0,__PYX_ERR(0, 2257, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_face->hanging != 0);
      if (__pyx_t_3) {
        goto __pyx_L13_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":2258
 *                 face = it.second
 *                 if face.hanging: continue
 *                 area[face.index + offset] = face.area             # <<<<<<<<<<<<<<
 *         return self._face_areas
 * 
 */
      __Pyx_TraceLine(2258,0,__PYX_ERR(0, 2258, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_face->area;
      __pyx_t_15 = (__pyx_v_face->index + __pyx_v_offset);
      __pyx_t_16 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_area.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_16 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_area.shape[0])) __pyx_t_16 = 0;
      if (unlikely(__pyx_t_16 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_16);
        __PYX_ERR(0, 2258, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_area.data + __pyx_t_15 * __pyx_v_area.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":2255
 * 
 *             offset = self.n_faces_x + self.n_faces_y
 *             for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging: continue
 */
      __Pyx_TraceLine(2255,0,__PYX_ERR(0, 2255, __pyx_L1_error))
      __pyx_L13_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2239
 *         cdef int_t ind, offset = 0
 *         cdef Face *face
 *         if self._face_areas is None:             # <<<<<<<<<<<<<<
 *             self._face_areas = np.empty(self.n_faces, dtype=np.float64)
 *             area = self._face_areas
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2259
 *                 if face.hanging: continue
 *                 area[face.index + offset] = face.area
 *         return self._face_areas             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2259,0,__PYX_ERR(0, 2259, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_face_areas);
  __pyx_r = __pyx_v_self->_face_areas;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2219
 * 
 *     @property
 *     def face_areas(self):             # <<<<<<<<<<<<<<
 *         """Returns the areas of all cell faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.face_areas.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_area, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2262
 * 
 *     @property
 *     def edge_lengths(self):             # <<<<<<<<<<<<<<
 *         """Returns the lengths of all edges in the mesh.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_edge_l = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  int_t __pyx_v_offset;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_9;
  edge_map_t *__pyx_t_10;
  std::pair<int_t,Edge *>  __pyx_t_11;
  Edge *__pyx_t_12;
  double __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  int __pyx_t_15;
  int_t __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2262, 0, __PYX_ERR(0, 2262, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2279
 *         cdef Edge *edge
 *         cdef int_t ind, offset
 *         if self._edge_lengths is None:             # <<<<<<<<<<<<<<
 *             self._edge_lengths = np.empty(self.n_edges, dtype=np.float64)
 *             edge_l = self._edge_lengths
 */
  __Pyx_TraceLine(2279,0,__PYX_ERR(0, 2279, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_edge_lengths == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2280
 *         cdef int_t ind, offset
 *         if self._edge_lengths is None:
 *             self._edge_lengths = np.empty(self.n_edges, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             edge_l = self._edge_lengths
 * 
 */
    __Pyx_TraceLine(2280,0,__PYX_ERR(0, 2280, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_self->_edge_lengths);
    __Pyx_DECREF(__pyx_v_self->_edge_lengths);
    __pyx_v_self->_edge_lengths = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2281
 *         if self._edge_lengths is None:
 *             self._edge_lengths = np.empty(self.n_edges, dtype=np.float64)
 *             edge_l = self._edge_lengths             # <<<<<<<<<<<<<<
 * 
 *             for it in self.tree.edges_x:
 */
    __Pyx_TraceLine(2281,0,__PYX_ERR(0, 2281, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_self->_edge_lengths, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 2281, __pyx_L1_error)
    __pyx_v_edge_l = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2283
 *             edge_l = self._edge_lengths
 * 
 *             for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
    __Pyx_TraceLine(2283,0,__PYX_ERR(0, 2283, __pyx_L1_error))
    __pyx_t_10 = &__pyx_v_self->tree->edges_x;
    __pyx_t_9 = __pyx_t_10->begin();
    for (;;) {
      if (!(__pyx_t_9 != __pyx_t_10->end())) break;
      __pyx_t_11 = *__pyx_t_9;
      ++__pyx_t_9;
      __pyx_v_it = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2284
 * 
 *             for it in self.tree.edges_x:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if edge.hanging: continue
 *                 edge_l[edge.index] = edge.length
 */
      __Pyx_TraceLine(2284,0,__PYX_ERR(0, 2284, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2285
 *             for it in self.tree.edges_x:
 *                 edge = it.second
 *                 if edge.hanging: continue             # <<<<<<<<<<<<<<
 *                 edge_l[edge.index] = edge.length
 * 
 */
      __Pyx_TraceLine(2285,0,__PYX_ERR(0, 2285, __pyx_L1_error))
      __pyx_t_2 = (__pyx_v_edge->hanging != 0);
      if (__pyx_t_2) {
        goto __pyx_L4_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":2286
 *                 edge = it.second
 *                 if edge.hanging: continue
 *                 edge_l[edge.index] = edge.length             # <<<<<<<<<<<<<<
 * 
 *             offset = self.n_edges_x
 */
      __Pyx_TraceLine(2286,0,__PYX_ERR(0, 2286, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_edge->length;
      __pyx_t_14 = __pyx_v_edge->index;
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_edge_l.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_edge_l.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 2286, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_edge_l.data + __pyx_t_14 * __pyx_v_edge_l.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2283
 *             edge_l = self._edge_lengths
 * 
 *             for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
      __Pyx_TraceLine(2283,0,__PYX_ERR(0, 2283, __pyx_L1_error))
      __pyx_L4_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2288
 *                 edge_l[edge.index] = edge.length
 * 
 *             offset = self.n_edges_x             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_y:
 *                 edge = it.second
 */
    __Pyx_TraceLine(2288,0,__PYX_ERR(0, 2288, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_16 = __Pyx_PyInt_As_int_t(__pyx_t_7); if (unlikely((__pyx_t_16 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2288, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_offset = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2289
 * 
 *             offset = self.n_edges_x
 *             for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
    __Pyx_TraceLine(2289,0,__PYX_ERR(0, 2289, __pyx_L1_error))
    __pyx_t_10 = &__pyx_v_self->tree->edges_y;
    __pyx_t_9 = __pyx_t_10->begin();
    for (;;) {
      if (!(__pyx_t_9 != __pyx_t_10->end())) break;
      __pyx_t_11 = *__pyx_t_9;
      ++__pyx_t_9;
      __pyx_v_it = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2290
 *             offset = self.n_edges_x
 *             for it in self.tree.edges_y:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if edge.hanging: continue
 *                 edge_l[edge.index + offset] = edge.length
 */
      __Pyx_TraceLine(2290,0,__PYX_ERR(0, 2290, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":2291
 *             for it in self.tree.edges_y:
 *                 edge = it.second
 *                 if edge.hanging: continue             # <<<<<<<<<<<<<<
 *                 edge_l[edge.index + offset] = edge.length
 * 
 */
      __Pyx_TraceLine(2291,0,__PYX_ERR(0, 2291, __pyx_L1_error))
      __pyx_t_2 = (__pyx_v_edge->hanging != 0);
      if (__pyx_t_2) {
        goto __pyx_L7_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":2292
 *                 edge = it.second
 *                 if edge.hanging: continue
 *                 edge_l[edge.index + offset] = edge.length             # <<<<<<<<<<<<<<
 * 
 *             if self._dim > 2:
 */
      __Pyx_TraceLine(2292,0,__PYX_ERR(0, 2292, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_edge->length;
      __pyx_t_14 = (__pyx_v_edge->index + __pyx_v_offset);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_edge_l.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_edge_l.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 2292, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_edge_l.data + __pyx_t_14 * __pyx_v_edge_l.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":2289
 * 
 *             offset = self.n_edges_x
 *             for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
      __Pyx_TraceLine(2289,0,__PYX_ERR(0, 2289, __pyx_L1_error))
      __pyx_L7_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2294
 *                 edge_l[edge.index + offset] = edge.length
 * 
 *             if self._dim > 2:             # <<<<<<<<<<<<<<
 *                 offset = self.n_edges_x + self.n_edges_y
 *                 for it in self.tree.edges_z:
 */
    __Pyx_TraceLine(2294,0,__PYX_ERR(0, 2294, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_self->_dim > 2) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":2295
 * 
 *             if self._dim > 2:
 *                 offset = self.n_edges_x + self.n_edges_y             # <<<<<<<<<<<<<<
 *                 for it in self.tree.edges_z:
 *                     edge = it.second
 */
      __Pyx_TraceLine(2295,0,__PYX_ERR(0, 2295, __pyx_L1_error))
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2295, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2295, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyNumber_Add(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2295, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_16 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_16 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2295, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_offset = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":2296
 *             if self._dim > 2:
 *                 offset = self.n_edges_x + self.n_edges_y
 *                 for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                     edge = it.second
 *                     if edge.hanging: continue
 */
      __Pyx_TraceLine(2296,0,__PYX_ERR(0, 2296, __pyx_L1_error))
      __pyx_t_10 = &__pyx_v_self->tree->edges_z;
      __pyx_t_9 = __pyx_t_10->begin();
      for (;;) {
        if (!(__pyx_t_9 != __pyx_t_10->end())) break;
        __pyx_t_11 = *__pyx_t_9;
        ++__pyx_t_9;
        __pyx_v_it = __pyx_t_11;

        /* "discretize/_extensions/tree_ext.pyx":2297
 *                 offset = self.n_edges_x + self.n_edges_y
 *                 for it in self.tree.edges_z:
 *                     edge = it.second             # <<<<<<<<<<<<<<
 *                     if edge.hanging: continue
 *                     edge_l[edge.index + offset] = edge.length
 */
        __Pyx_TraceLine(2297,0,__PYX_ERR(0, 2297, __pyx_L1_error))
        __pyx_t_12 = __pyx_v_it.second;
        __pyx_v_edge = __pyx_t_12;

        /* "discretize/_extensions/tree_ext.pyx":2298
 *                 for it in self.tree.edges_z:
 *                     edge = it.second
 *                     if edge.hanging: continue             # <<<<<<<<<<<<<<
 *                     edge_l[edge.index + offset] = edge.length
 *         return self._edge_lengths
 */
        __Pyx_TraceLine(2298,0,__PYX_ERR(0, 2298, __pyx_L1_error))
        __pyx_t_2 = (__pyx_v_edge->hanging != 0);
        if (__pyx_t_2) {
          goto __pyx_L11_continue;
        }

        /* "discretize/_extensions/tree_ext.pyx":2299
 *                     edge = it.second
 *                     if edge.hanging: continue
 *                     edge_l[edge.index + offset] = edge.length             # <<<<<<<<<<<<<<
 *         return self._edge_lengths
 * 
 */
        __Pyx_TraceLine(2299,0,__PYX_ERR(0, 2299, __pyx_L1_error))
        __pyx_t_13 = __pyx_v_edge->length;
        __pyx_t_14 = (__pyx_v_edge->index + __pyx_v_offset);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_edge_l.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_edge_l.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 2299, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_edge_l.data + __pyx_t_14 * __pyx_v_edge_l.strides[0]) )) = __pyx_t_13;

        /* "discretize/_extensions/tree_ext.pyx":2296
 *             if self._dim > 2:
 *                 offset = self.n_edges_x + self.n_edges_y
 *                 for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                     edge = it.second
 *                     if edge.hanging: continue
 */
        __Pyx_TraceLine(2296,0,__PYX_ERR(0, 2296, __pyx_L1_error))
        __pyx_L11_continue:;
      }

      /* "discretize/_extensions/tree_ext.pyx":2294
 *                 edge_l[edge.index + offset] = edge.length
 * 
 *             if self._dim > 2:             # <<<<<<<<<<<<<<
 *                 offset = self.n_edges_x + self.n_edges_y
 *                 for it in self.tree.edges_z:
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2279
 *         cdef Edge *edge
 *         cdef int_t ind, offset
 *         if self._edge_lengths is None:             # <<<<<<<<<<<<<<
 *             self._edge_lengths = np.empty(self.n_edges, dtype=np.float64)
 *             edge_l = self._edge_lengths
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2300
 *                     if edge.hanging: continue
 *                     edge_l[edge.index + offset] = edge.length
 *         return self._edge_lengths             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2300,0,__PYX_ERR(0, 2300, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_edge_lengths);
  __pyx_r = __pyx_v_self->_edge_lengths;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2262
 * 
 *     @property
 *     def edge_lengths(self):             # <<<<<<<<<<<<<<
 *         """Returns the lengths of all edges in the mesh.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edge_lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_edge_l, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2303
 * 
 *     @property
 *     def cell_boundary_indices(self):             # <<<<<<<<<<<<<<
 *         """Returns the indices of the x, y (and z) boundary cells.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_indxu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indxd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indyu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indyd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indzu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indzd = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_nxu;
  int_t __pyx_v_nxd;
  int_t __pyx_v_nyu;
  int_t __pyx_v_nyd;
  int_t __pyx_v_nzu;
  int_t __pyx_v_nzd;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_ixd = NULL;
  PyObject *__pyx_v_ixu = NULL;
  PyObject *__pyx_v_iyd = NULL;
  PyObject *__pyx_v_iyu = NULL;
  PyObject *__pyx_v_izd = NULL;
  PyObject *__pyx_v_izu = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_7;
  std::vector<Cell *> ::iterator __pyx_t_8;
  std::vector<Cell *>  *__pyx_t_9;
  Cell *__pyx_t_10;
  PY_LONG_LONG __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2303, 0, __PYX_ERR(0, 2303, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2356
 *         """
 *         cdef np.int64_t[:] indxu, indxd, indyu, indyd, indzu, indzd
 *         indxu = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         indxd = np.empty(self.n_cells, dtype=np.int64)
 *         indyu = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(2356,0,__PYX_ERR(0, 2356, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2356, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_indxu = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2357
 *         cdef np.int64_t[:] indxu, indxd, indyu, indyd, indzu, indzd
 *         indxu = np.empty(self.n_cells, dtype=np.int64)
 *         indxd = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         indyu = np.empty(self.n_cells, dtype=np.int64)
 *         indyd = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(2357,0,__PYX_ERR(0, 2357, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2357, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_indxd = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2358
 *         indxu = np.empty(self.n_cells, dtype=np.int64)
 *         indxd = np.empty(self.n_cells, dtype=np.int64)
 *         indyu = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         indyd = np.empty(self.n_cells, dtype=np.int64)
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(2358,0,__PYX_ERR(0, 2358, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2358, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_indyu = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2359
 *         indxd = np.empty(self.n_cells, dtype=np.int64)
 *         indyu = np.empty(self.n_cells, dtype=np.int64)
 *         indyd = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             indzu = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(2359,0,__PYX_ERR(0, 2359, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_indyd = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2360
 *         indyu = np.empty(self.n_cells, dtype=np.int64)
 *         indyd = np.empty(self.n_cells, dtype=np.int64)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             indzu = np.empty(self.n_cells, dtype=np.int64)
 *             indzd = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(2360,0,__PYX_ERR(0, 2360, __pyx_L1_error))
  __pyx_t_7 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":2361
 *         indyd = np.empty(self.n_cells, dtype=np.int64)
 *         if self._dim == 3:
 *             indzu = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             indzd = np.empty(self.n_cells, dtype=np.int64)
 *         cdef int_t nxu, nxd, nyu, nyd, nzu, nzd
 */
    __Pyx_TraceLine(2361,0,__PYX_ERR(0, 2361, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2361, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_indzu = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2362
 *         if self._dim == 3:
 *             indzu = np.empty(self.n_cells, dtype=np.int64)
 *             indzd = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef int_t nxu, nxd, nyu, nyd, nzu, nzd
 *         nxu = 0
 */
    __Pyx_TraceLine(2362,0,__PYX_ERR(0, 2362, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_indzd = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2360
 *         indyu = np.empty(self.n_cells, dtype=np.int64)
 *         indyd = np.empty(self.n_cells, dtype=np.int64)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             indzu = np.empty(self.n_cells, dtype=np.int64)
 *             indzd = np.empty(self.n_cells, dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2364
 *             indzd = np.empty(self.n_cells, dtype=np.int64)
 *         cdef int_t nxu, nxd, nyu, nyd, nzu, nzd
 *         nxu = 0             # <<<<<<<<<<<<<<
 *         nxd = 0
 *         nyu = 0
 */
  __Pyx_TraceLine(2364,0,__PYX_ERR(0, 2364, __pyx_L1_error))
  __pyx_v_nxu = 0;

  /* "discretize/_extensions/tree_ext.pyx":2365
 *         cdef int_t nxu, nxd, nyu, nyd, nzu, nzd
 *         nxu = 0
 *         nxd = 0             # <<<<<<<<<<<<<<
 *         nyu = 0
 *         nyd = 0
 */
  __Pyx_TraceLine(2365,0,__PYX_ERR(0, 2365, __pyx_L1_error))
  __pyx_v_nxd = 0;

  /* "discretize/_extensions/tree_ext.pyx":2366
 *         nxu = 0
 *         nxd = 0
 *         nyu = 0             # <<<<<<<<<<<<<<
 *         nyd = 0
 *         nzu = 0
 */
  __Pyx_TraceLine(2366,0,__PYX_ERR(0, 2366, __pyx_L1_error))
  __pyx_v_nyu = 0;

  /* "discretize/_extensions/tree_ext.pyx":2367
 *         nxd = 0
 *         nyu = 0
 *         nyd = 0             # <<<<<<<<<<<<<<
 *         nzu = 0
 *         nzd = 0
 */
  __Pyx_TraceLine(2367,0,__PYX_ERR(0, 2367, __pyx_L1_error))
  __pyx_v_nyd = 0;

  /* "discretize/_extensions/tree_ext.pyx":2368
 *         nyu = 0
 *         nyd = 0
 *         nzu = 0             # <<<<<<<<<<<<<<
 *         nzd = 0
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(2368,0,__PYX_ERR(0, 2368, __pyx_L1_error))
  __pyx_v_nzu = 0;

  /* "discretize/_extensions/tree_ext.pyx":2369
 *         nyd = 0
 *         nzu = 0
 *         nzd = 0             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             if cell.neighbors[0] == NULL:
 */
  __Pyx_TraceLine(2369,0,__PYX_ERR(0, 2369, __pyx_L1_error))
  __pyx_v_nzd = 0;

  /* "discretize/_extensions/tree_ext.pyx":2370
 *         nzu = 0
 *         nzd = 0
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             if cell.neighbors[0] == NULL:
 *                 indxd[nxd] = cell.index
 */
  __Pyx_TraceLine(2370,0,__PYX_ERR(0, 2370, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->cells;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_cell = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":2371
 *         nzd = 0
 *         for cell in self.tree.cells:
 *             if cell.neighbors[0] == NULL:             # <<<<<<<<<<<<<<
 *                 indxd[nxd] = cell.index
 *                 nxd += 1
 */
    __Pyx_TraceLine(2371,0,__PYX_ERR(0, 2371, __pyx_L1_error))
    __pyx_t_7 = (((__pyx_v_cell->neighbors[0]) == NULL) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":2372
 *         for cell in self.tree.cells:
 *             if cell.neighbors[0] == NULL:
 *                 indxd[nxd] = cell.index             # <<<<<<<<<<<<<<
 *                 nxd += 1
 *             if cell.neighbors[1] == NULL:
 */
      __Pyx_TraceLine(2372,0,__PYX_ERR(0, 2372, __pyx_L1_error))
      __pyx_t_11 = __pyx_v_cell->index;
      __pyx_t_12 = __pyx_v_nxd;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_indxd.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_indxd.shape[0])) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 2372, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indxd.data + __pyx_t_12 * __pyx_v_indxd.strides[0]) )) = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2373
 *             if cell.neighbors[0] == NULL:
 *                 indxd[nxd] = cell.index
 *                 nxd += 1             # <<<<<<<<<<<<<<
 *             if cell.neighbors[1] == NULL:
 *                 indxu[nxu] = cell.index
 */
      __Pyx_TraceLine(2373,0,__PYX_ERR(0, 2373, __pyx_L1_error))
      __pyx_v_nxd = (__pyx_v_nxd + 1);

      /* "discretize/_extensions/tree_ext.pyx":2371
 *         nzd = 0
 *         for cell in self.tree.cells:
 *             if cell.neighbors[0] == NULL:             # <<<<<<<<<<<<<<
 *                 indxd[nxd] = cell.index
 *                 nxd += 1
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2374
 *                 indxd[nxd] = cell.index
 *                 nxd += 1
 *             if cell.neighbors[1] == NULL:             # <<<<<<<<<<<<<<
 *                 indxu[nxu] = cell.index
 *                 nxu += 1
 */
    __Pyx_TraceLine(2374,0,__PYX_ERR(0, 2374, __pyx_L1_error))
    __pyx_t_7 = (((__pyx_v_cell->neighbors[1]) == NULL) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":2375
 *                 nxd += 1
 *             if cell.neighbors[1] == NULL:
 *                 indxu[nxu] = cell.index             # <<<<<<<<<<<<<<
 *                 nxu += 1
 *             if cell.neighbors[2] == NULL:
 */
      __Pyx_TraceLine(2375,0,__PYX_ERR(0, 2375, __pyx_L1_error))
      __pyx_t_11 = __pyx_v_cell->index;
      __pyx_t_12 = __pyx_v_nxu;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_indxu.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_indxu.shape[0])) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 2375, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indxu.data + __pyx_t_12 * __pyx_v_indxu.strides[0]) )) = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2376
 *             if cell.neighbors[1] == NULL:
 *                 indxu[nxu] = cell.index
 *                 nxu += 1             # <<<<<<<<<<<<<<
 *             if cell.neighbors[2] == NULL:
 *                 indyd[nyd] = cell.index
 */
      __Pyx_TraceLine(2376,0,__PYX_ERR(0, 2376, __pyx_L1_error))
      __pyx_v_nxu = (__pyx_v_nxu + 1);

      /* "discretize/_extensions/tree_ext.pyx":2374
 *                 indxd[nxd] = cell.index
 *                 nxd += 1
 *             if cell.neighbors[1] == NULL:             # <<<<<<<<<<<<<<
 *                 indxu[nxu] = cell.index
 *                 nxu += 1
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2377
 *                 indxu[nxu] = cell.index
 *                 nxu += 1
 *             if cell.neighbors[2] == NULL:             # <<<<<<<<<<<<<<
 *                 indyd[nyd] = cell.index
 *                 nyd += 1
 */
    __Pyx_TraceLine(2377,0,__PYX_ERR(0, 2377, __pyx_L1_error))
    __pyx_t_7 = (((__pyx_v_cell->neighbors[2]) == NULL) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":2378
 *                 nxu += 1
 *             if cell.neighbors[2] == NULL:
 *                 indyd[nyd] = cell.index             # <<<<<<<<<<<<<<
 *                 nyd += 1
 *             if cell.neighbors[3] == NULL:
 */
      __Pyx_TraceLine(2378,0,__PYX_ERR(0, 2378, __pyx_L1_error))
      __pyx_t_11 = __pyx_v_cell->index;
      __pyx_t_12 = __pyx_v_nyd;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_indyd.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_indyd.shape[0])) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 2378, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indyd.data + __pyx_t_12 * __pyx_v_indyd.strides[0]) )) = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2379
 *             if cell.neighbors[2] == NULL:
 *                 indyd[nyd] = cell.index
 *                 nyd += 1             # <<<<<<<<<<<<<<
 *             if cell.neighbors[3] == NULL:
 *                 indyu[nyu] = cell.index
 */
      __Pyx_TraceLine(2379,0,__PYX_ERR(0, 2379, __pyx_L1_error))
      __pyx_v_nyd = (__pyx_v_nyd + 1);

      /* "discretize/_extensions/tree_ext.pyx":2377
 *                 indxu[nxu] = cell.index
 *                 nxu += 1
 *             if cell.neighbors[2] == NULL:             # <<<<<<<<<<<<<<
 *                 indyd[nyd] = cell.index
 *                 nyd += 1
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2380
 *                 indyd[nyd] = cell.index
 *                 nyd += 1
 *             if cell.neighbors[3] == NULL:             # <<<<<<<<<<<<<<
 *                 indyu[nyu] = cell.index
 *                 nyu += 1
 */
    __Pyx_TraceLine(2380,0,__PYX_ERR(0, 2380, __pyx_L1_error))
    __pyx_t_7 = (((__pyx_v_cell->neighbors[3]) == NULL) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":2381
 *                 nyd += 1
 *             if cell.neighbors[3] == NULL:
 *                 indyu[nyu] = cell.index             # <<<<<<<<<<<<<<
 *                 nyu += 1
 *             if self._dim == 3:
 */
      __Pyx_TraceLine(2381,0,__PYX_ERR(0, 2381, __pyx_L1_error))
      __pyx_t_11 = __pyx_v_cell->index;
      __pyx_t_12 = __pyx_v_nyu;
      __pyx_t_13 = -1;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_indyu.shape[0];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_indyu.shape[0])) __pyx_t_13 = 0;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 2381, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indyu.data + __pyx_t_12 * __pyx_v_indyu.strides[0]) )) = __pyx_t_11;

      /* "discretize/_extensions/tree_ext.pyx":2382
 *             if cell.neighbors[3] == NULL:
 *                 indyu[nyu] = cell.index
 *                 nyu += 1             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 if cell.neighbors[4] == NULL:
 */
      __Pyx_TraceLine(2382,0,__PYX_ERR(0, 2382, __pyx_L1_error))
      __pyx_v_nyu = (__pyx_v_nyu + 1);

      /* "discretize/_extensions/tree_ext.pyx":2380
 *                 indyd[nyd] = cell.index
 *                 nyd += 1
 *             if cell.neighbors[3] == NULL:             # <<<<<<<<<<<<<<
 *                 indyu[nyu] = cell.index
 *                 nyu += 1
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2383
 *                 indyu[nyu] = cell.index
 *                 nyu += 1
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 if cell.neighbors[4] == NULL:
 *                     indzd[nzd] = cell.index
 */
    __Pyx_TraceLine(2383,0,__PYX_ERR(0, 2383, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_7) {

      /* "discretize/_extensions/tree_ext.pyx":2384
 *                 nyu += 1
 *             if self._dim == 3:
 *                 if cell.neighbors[4] == NULL:             # <<<<<<<<<<<<<<
 *                     indzd[nzd] = cell.index
 *                     nzd += 1
 */
      __Pyx_TraceLine(2384,0,__PYX_ERR(0, 2384, __pyx_L1_error))
      __pyx_t_7 = (((__pyx_v_cell->neighbors[4]) == NULL) != 0);
      if (__pyx_t_7) {

        /* "discretize/_extensions/tree_ext.pyx":2385
 *             if self._dim == 3:
 *                 if cell.neighbors[4] == NULL:
 *                     indzd[nzd] = cell.index             # <<<<<<<<<<<<<<
 *                     nzd += 1
 *                 if cell.neighbors[5] == NULL:
 */
        __Pyx_TraceLine(2385,0,__PYX_ERR(0, 2385, __pyx_L1_error))
        __pyx_t_11 = __pyx_v_cell->index;
        if (unlikely(!__pyx_v_indzd.memview)) { __Pyx_RaiseUnboundLocalError("indzd"); __PYX_ERR(0, 2385, __pyx_L1_error) }
        __pyx_t_12 = __pyx_v_nzd;
        __pyx_t_13 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_indzd.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_indzd.shape[0])) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 2385, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indzd.data + __pyx_t_12 * __pyx_v_indzd.strides[0]) )) = __pyx_t_11;

        /* "discretize/_extensions/tree_ext.pyx":2386
 *                 if cell.neighbors[4] == NULL:
 *                     indzd[nzd] = cell.index
 *                     nzd += 1             # <<<<<<<<<<<<<<
 *                 if cell.neighbors[5] == NULL:
 *                     indzu[nzu] = cell.index
 */
        __Pyx_TraceLine(2386,0,__PYX_ERR(0, 2386, __pyx_L1_error))
        __pyx_v_nzd = (__pyx_v_nzd + 1);

        /* "discretize/_extensions/tree_ext.pyx":2384
 *                 nyu += 1
 *             if self._dim == 3:
 *                 if cell.neighbors[4] == NULL:             # <<<<<<<<<<<<<<
 *                     indzd[nzd] = cell.index
 *                     nzd += 1
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2387
 *                     indzd[nzd] = cell.index
 *                     nzd += 1
 *                 if cell.neighbors[5] == NULL:             # <<<<<<<<<<<<<<
 *                     indzu[nzu] = cell.index
 *                     nzu += 1
 */
      __Pyx_TraceLine(2387,0,__PYX_ERR(0, 2387, __pyx_L1_error))
      __pyx_t_7 = (((__pyx_v_cell->neighbors[5]) == NULL) != 0);
      if (__pyx_t_7) {

        /* "discretize/_extensions/tree_ext.pyx":2388
 *                     nzd += 1
 *                 if cell.neighbors[5] == NULL:
 *                     indzu[nzu] = cell.index             # <<<<<<<<<<<<<<
 *                     nzu += 1
 *         ixd = np.array(indxd)[:nxd]
 */
        __Pyx_TraceLine(2388,0,__PYX_ERR(0, 2388, __pyx_L1_error))
        __pyx_t_11 = __pyx_v_cell->index;
        if (unlikely(!__pyx_v_indzu.memview)) { __Pyx_RaiseUnboundLocalError("indzu"); __PYX_ERR(0, 2388, __pyx_L1_error) }
        __pyx_t_12 = __pyx_v_nzu;
        __pyx_t_13 = -1;
        if (__pyx_t_12 < 0) {
          __pyx_t_12 += __pyx_v_indzu.shape[0];
          if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
        } else if (unlikely(__pyx_t_12 >= __pyx_v_indzu.shape[0])) __pyx_t_13 = 0;
        if (unlikely(__pyx_t_13 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_13);
          __PYX_ERR(0, 2388, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indzu.data + __pyx_t_12 * __pyx_v_indzu.strides[0]) )) = __pyx_t_11;

        /* "discretize/_extensions/tree_ext.pyx":2389
 *                 if cell.neighbors[5] == NULL:
 *                     indzu[nzu] = cell.index
 *                     nzu += 1             # <<<<<<<<<<<<<<
 *         ixd = np.array(indxd)[:nxd]
 *         ixu = np.array(indxu)[:nxu]
 */
        __Pyx_TraceLine(2389,0,__PYX_ERR(0, 2389, __pyx_L1_error))
        __pyx_v_nzu = (__pyx_v_nzu + 1);

        /* "discretize/_extensions/tree_ext.pyx":2387
 *                     indzd[nzd] = cell.index
 *                     nzd += 1
 *                 if cell.neighbors[5] == NULL:             # <<<<<<<<<<<<<<
 *                     indzu[nzu] = cell.index
 *                     nzu += 1
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2383
 *                 indyu[nyu] = cell.index
 *                 nyu += 1
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 if cell.neighbors[4] == NULL:
 *                     indzd[nzd] = cell.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2370
 *         nzu = 0
 *         nzd = 0
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             if cell.neighbors[0] == NULL:
 *                 indxd[nxd] = cell.index
 */
    __Pyx_TraceLine(2370,0,__PYX_ERR(0, 2370, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":2390
 *                     indzu[nzu] = cell.index
 *                     nzu += 1
 *         ixd = np.array(indxd)[:nxd]             # <<<<<<<<<<<<<<
 *         ixu = np.array(indxu)[:nxu]
 *         iyd = np.array(indyd)[:nyd]
 */
  __Pyx_TraceLine(2390,0,__PYX_ERR(0, 2390, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_indxd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_t_4, 0, __pyx_v_nxd, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ixd = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2391
 *                     nzu += 1
 *         ixd = np.array(indxd)[:nxd]
 *         ixu = np.array(indxu)[:nxu]             # <<<<<<<<<<<<<<
 *         iyd = np.array(indyd)[:nyd]
 *         iyu = np.array(indyu)[:nyu]
 */
  __Pyx_TraceLine(2391,0,__PYX_ERR(0, 2391, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_indxu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_t_3, 0, __pyx_v_nxu, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ixu = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2392
 *         ixd = np.array(indxd)[:nxd]
 *         ixu = np.array(indxu)[:nxu]
 *         iyd = np.array(indyd)[:nyd]             # <<<<<<<<<<<<<<
 *         iyu = np.array(indyu)[:nyu]
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(2392,0,__PYX_ERR(0, 2392, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_indyd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_t_5, 0, __pyx_v_nyd, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_iyd = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2393
 *         ixu = np.array(indxu)[:nxu]
 *         iyd = np.array(indyd)[:nyd]
 *         iyu = np.array(indyu)[:nyu]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             izd = np.array(indzd)[:nzd]
 */
  __Pyx_TraceLine(2393,0,__PYX_ERR(0, 2393, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_indyu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_t_4, 0, __pyx_v_nyu, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_iyu = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2394
 *         iyd = np.array(indyd)[:nyd]
 *         iyu = np.array(indyu)[:nyu]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             izd = np.array(indzd)[:nzd]
 *             izu = np.array(indzu)[:nzu]
 */
  __Pyx_TraceLine(2394,0,__PYX_ERR(0, 2394, __pyx_L1_error))
  __pyx_t_7 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_7) {

    /* "discretize/_extensions/tree_ext.pyx":2395
 *         iyu = np.array(indyu)[:nyu]
 *         if self._dim == 3:
 *             izd = np.array(indzd)[:nzd]             # <<<<<<<<<<<<<<
 *             izu = np.array(indzu)[:nzu]
 *             return ixd, ixu, iyd, iyu, izd, izu
 */
    __Pyx_TraceLine(2395,0,__PYX_ERR(0, 2395, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_v_indzd.memview)) { __Pyx_RaiseUnboundLocalError("indzd"); __PYX_ERR(0, 2395, __pyx_L1_error) }
    __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_indzd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_t_3, 0, __pyx_v_nzd, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_izd = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2396
 *         if self._dim == 3:
 *             izd = np.array(indzd)[:nzd]
 *             izu = np.array(indzu)[:nzu]             # <<<<<<<<<<<<<<
 *             return ixd, ixu, iyd, iyu, izd, izu
 *         else:
 */
    __Pyx_TraceLine(2396,0,__PYX_ERR(0, 2396, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_v_indzu.memview)) { __Pyx_RaiseUnboundLocalError("indzu"); __PYX_ERR(0, 2396, __pyx_L1_error) }
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_indzu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_t_5, 0, __pyx_v_nzu, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_izu = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2397
 *             izd = np.array(indzd)[:nzd]
 *             izu = np.array(indzu)[:nzu]
 *             return ixd, ixu, iyd, iyu, izd, izu             # <<<<<<<<<<<<<<
 *         else:
 *             return ixd, ixu, iyd, iyu
 */
    __Pyx_TraceLine(2397,0,__PYX_ERR(0, 2397, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_ixd);
    __Pyx_GIVEREF(__pyx_v_ixd);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_ixd);
    __Pyx_INCREF(__pyx_v_ixu);
    __Pyx_GIVEREF(__pyx_v_ixu);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_ixu);
    __Pyx_INCREF(__pyx_v_iyd);
    __Pyx_GIVEREF(__pyx_v_iyd);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_iyd);
    __Pyx_INCREF(__pyx_v_iyu);
    __Pyx_GIVEREF(__pyx_v_iyu);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_iyu);
    __Pyx_INCREF(__pyx_v_izd);
    __Pyx_GIVEREF(__pyx_v_izd);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_izd);
    __Pyx_INCREF(__pyx_v_izu);
    __Pyx_GIVEREF(__pyx_v_izu);
    PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_izu);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2394
 *         iyd = np.array(indyd)[:nyd]
 *         iyu = np.array(indyu)[:nyu]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             izd = np.array(indzd)[:nzd]
 *             izu = np.array(indzu)[:nzu]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2399
 *             return ixd, ixu, iyd, iyu, izd, izu
 *         else:
 *             return ixd, ixu, iyd, iyu             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2399,0,__PYX_ERR(0, 2399, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2399, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_ixd);
    __Pyx_GIVEREF(__pyx_v_ixd);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_ixd);
    __Pyx_INCREF(__pyx_v_ixu);
    __Pyx_GIVEREF(__pyx_v_ixu);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_ixu);
    __Pyx_INCREF(__pyx_v_iyd);
    __Pyx_GIVEREF(__pyx_v_iyd);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_iyd);
    __Pyx_INCREF(__pyx_v_iyu);
    __Pyx_GIVEREF(__pyx_v_iyu);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_iyu);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2303
 * 
 *     @property
 *     def cell_boundary_indices(self):             # <<<<<<<<<<<<<<
 *         """Returns the indices of the x, y (and z) boundary cells.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.cell_boundary_indices.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_indxu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indxd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indyu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indyd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indzu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indzd, 1);
  __Pyx_XDECREF(__pyx_v_ixd);
  __Pyx_XDECREF(__pyx_v_ixu);
  __Pyx_XDECREF(__pyx_v_iyd);
  __Pyx_XDECREF(__pyx_v_iyu);
  __Pyx_XDECREF(__pyx_v_izd);
  __Pyx_XDECREF(__pyx_v_izu);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2402
 * 
 *     @property
 *     def face_boundary_indices(self):             # <<<<<<<<<<<<<<
 *         """Returns the indices of the x, y (and z) boundary faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_cell_boundary_inds = NULL;
  __Pyx_memviewslice __pyx_v_c_indxu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_c_indxd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_c_indyu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_c_indyd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_c_indzu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_c_indzd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indxu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indxd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indyu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indyd = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indzu = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_f_indzd = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_v_ixd = NULL;
  PyObject *__pyx_v_ixu = NULL;
  PyObject *__pyx_v_iyd = NULL;
  PyObject *__pyx_v_iyu = NULL;
  PyObject *__pyx_v_izd = NULL;
  PyObject *__pyx_v_izu = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_11 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_memviewslice __pyx_t_14 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_15 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  int __pyx_t_20;
  int_t __pyx_t_21;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2402, 0, __PYX_ERR(0, 2402, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2453
 *         >>> plt.show()
 *         """
 *         cell_boundary_inds = self.cell_boundary_indices             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] c_indxu, c_indxd, c_indyu, c_indyd, c_indzu, c_indzd
 *         cdef np.int64_t[:] f_indxu, f_indxd, f_indyu, f_indyd, f_indzu, f_indzd
 */
  __Pyx_TraceLine(2453,0,__PYX_ERR(0, 2453, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cell_boundary_indices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_cell_boundary_inds = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2456
 *         cdef np.int64_t[:] c_indxu, c_indxd, c_indyu, c_indyd, c_indzu, c_indzd
 *         cdef np.int64_t[:] f_indxu, f_indxd, f_indyu, f_indyd, f_indzu, f_indzd
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             c_indxd, c_indxu, c_indyd, c_indyu = cell_boundary_inds
 *         else:
 */
  __Pyx_TraceLine(2456,0,__PYX_ERR(0, 2456, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2457
 *         cdef np.int64_t[:] f_indxu, f_indxd, f_indyu, f_indyd, f_indzu, f_indzd
 *         if self._dim == 2:
 *             c_indxd, c_indxu, c_indyd, c_indyu = cell_boundary_inds             # <<<<<<<<<<<<<<
 *         else:
 *             c_indxd, c_indxu, c_indyd, c_indyu, c_indzd, c_indzu = cell_boundary_inds
 */
    __Pyx_TraceLine(2457,0,__PYX_ERR(0, 2457, __pyx_L1_error))
    if ((likely(PyTuple_CheckExact(__pyx_v_cell_boundary_inds))) || (PyList_CheckExact(__pyx_v_cell_boundary_inds))) {
      PyObject* sequence = __pyx_v_cell_boundary_inds;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2457, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_4,&__pyx_t_5};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2457, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_3,&__pyx_t_4,&__pyx_t_5};
      __pyx_t_6 = PyObject_GetIter(__pyx_v_cell_boundary_inds); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_7(__pyx_t_6); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 4) < 0) __PYX_ERR(0, 2457, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L5_unpacking_done;
      __pyx_L4_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2457, __pyx_L1_error)
      __pyx_L5_unpacking_done:;
    }
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_c_indxd = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;
    __pyx_v_c_indxu = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
    __pyx_v_c_indyd = __pyx_t_10;
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;
    __pyx_v_c_indyu = __pyx_t_11;
    __pyx_t_11.memview = NULL;
    __pyx_t_11.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2456
 *         cdef np.int64_t[:] c_indxu, c_indxd, c_indyu, c_indyd, c_indzu, c_indzd
 *         cdef np.int64_t[:] f_indxu, f_indxd, f_indyu, f_indyd, f_indzu, f_indzd
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             c_indxd, c_indxu, c_indyd, c_indyu = cell_boundary_inds
 *         else:
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":2459
 *             c_indxd, c_indxu, c_indyd, c_indyu = cell_boundary_inds
 *         else:
 *             c_indxd, c_indxu, c_indyd, c_indyu, c_indzd, c_indzu = cell_boundary_inds             # <<<<<<<<<<<<<<
 * 
 *         f_indxd = np.empty(c_indxd.shape[0], dtype=np.int64)
 */
  __Pyx_TraceLine(2459,0,__PYX_ERR(0, 2459, __pyx_L1_error))
  /*else*/ {
    if ((likely(PyTuple_CheckExact(__pyx_v_cell_boundary_inds))) || (PyList_CheckExact(__pyx_v_cell_boundary_inds))) {
      PyObject* sequence = __pyx_v_cell_boundary_inds;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 6)) {
        if (size > 6) __Pyx_RaiseTooManyValuesError(6);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2459, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 3); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 4); 
        __pyx_t_12 = PyTuple_GET_ITEM(sequence, 5); 
      } else {
        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 3); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 4); 
        __pyx_t_12 = PyList_GET_ITEM(sequence, 5); 
      }
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_12);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[6] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_3,&__pyx_t_1,&__pyx_t_6,&__pyx_t_12};
        for (i=0; i < 6; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2459, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[6] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_3,&__pyx_t_1,&__pyx_t_6,&__pyx_t_12};
      __pyx_t_13 = PyObject_GetIter(__pyx_v_cell_boundary_inds); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_7 = Py_TYPE(__pyx_t_13)->tp_iternext;
      for (index=0; index < 6; index++) {
        PyObject* item = __pyx_t_7(__pyx_t_13); if (unlikely(!item)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_13), 6) < 0) __PYX_ERR(0, 2459, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2459, __pyx_L1_error)
      __pyx_L7_unpacking_done:;
    }
    __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_12, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_v_c_indxd = __pyx_t_11;
    __pyx_t_11.memview = NULL;
    __pyx_t_11.data = NULL;
    __pyx_v_c_indxu = __pyx_t_10;
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;
    __pyx_v_c_indyd = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
    __pyx_v_c_indyu = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;
    __pyx_v_c_indzd = __pyx_t_14;
    __pyx_t_14.memview = NULL;
    __pyx_t_14.data = NULL;
    __pyx_v_c_indzu = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":2461
 *             c_indxd, c_indxu, c_indyd, c_indyu, c_indzd, c_indzu = cell_boundary_inds
 * 
 *         f_indxd = np.empty(c_indxd.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 *         f_indxu = np.empty(c_indxu.shape[0], dtype=np.int64)
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)
 */
  __Pyx_TraceLine(2461,0,__PYX_ERR(0, 2461, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = PyInt_FromSsize_t((__pyx_v_c_indxd.shape[0])); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12);
  __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2461, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_f_indxd = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2462
 * 
 *         f_indxd = np.empty(c_indxd.shape[0], dtype=np.int64)
 *         f_indxu = np.empty(c_indxu.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)
 */
  __Pyx_TraceLine(2462,0,__PYX_ERR(0, 2462, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromSsize_t((__pyx_v_c_indxu.shape[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2462, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_f_indxu = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2463
 *         f_indxd = np.empty(c_indxd.shape[0], dtype=np.int64)
 *         f_indxu = np.empty(c_indxu.shape[0], dtype=np.int64)
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(2463,0,__PYX_ERR(0, 2463, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t((__pyx_v_c_indyd.shape[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_f_indyd = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2464
 *         f_indxu = np.empty(c_indxu.shape[0], dtype=np.int64)
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             for i in range(f_indxd.shape[0]):
 */
  __Pyx_TraceLine(2464,0,__PYX_ERR(0, 2464, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyInt_FromSsize_t((__pyx_v_c_indyu.shape[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_12) < 0) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_12, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2464, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_v_f_indyu = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2465
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index
 */
  __Pyx_TraceLine(2465,0,__PYX_ERR(0, 2465, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2466
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)
 *         if self._dim == 2:
 *             for i in range(f_indxd.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index
 *             for i in range(f_indxu.shape[0]):
 */
    __Pyx_TraceLine(2466,0,__PYX_ERR(0, 2466, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indxd.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2467
 *         if self._dim == 2:
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].edges[3].index
 */
      __Pyx_TraceLine(2467,0,__PYX_ERR(0, 2467, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indxd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indxd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2467, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indxd.data + __pyx_t_19 * __pyx_v_c_indxd.strides[0]) )))])->edges[2])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indxd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indxd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2467, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indxd.data + __pyx_t_19 * __pyx_v_f_indxd.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2468
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index
 *             for i in range(f_indxu.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].edges[3].index
 *             for i in range(f_indyd.shape[0]):
 */
    __Pyx_TraceLine(2468,0,__PYX_ERR(0, 2468, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indxu.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2469
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].edges[3].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].edges[0].index
 */
      __Pyx_TraceLine(2469,0,__PYX_ERR(0, 2469, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indxu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indxu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2469, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indxu.data + __pyx_t_19 * __pyx_v_c_indxu.strides[0]) )))])->edges[3])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indxu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indxu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2469, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indxu.data + __pyx_t_19 * __pyx_v_f_indxu.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2470
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].edges[3].index
 *             for i in range(f_indyd.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].edges[0].index
 *             for i in range(f_indyu.shape[0]):
 */
    __Pyx_TraceLine(2470,0,__PYX_ERR(0, 2470, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indyd.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2471
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].edges[3].index
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].edges[0].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index
 */
      __Pyx_TraceLine(2471,0,__PYX_ERR(0, 2471, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indyd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indyd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2471, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indyd.data + __pyx_t_19 * __pyx_v_c_indyd.strides[0]) )))])->edges[0])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indyd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indyd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2471, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indyd.data + __pyx_t_19 * __pyx_v_f_indyd.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2472
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].edges[0].index
 *             for i in range(f_indyu.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index
 *         if self._dim == 3:
 */
    __Pyx_TraceLine(2472,0,__PYX_ERR(0, 2472, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indyu.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2473
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].edges[0].index
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             f_indzd = np.empty(c_indzd.shape[0], dtype=np.int64)
 */
      __Pyx_TraceLine(2473,0,__PYX_ERR(0, 2473, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indyu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indyu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2473, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indyu.data + __pyx_t_19 * __pyx_v_c_indyu.strides[0]) )))])->edges[1])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indyu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indyu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2473, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indyu.data + __pyx_t_19 * __pyx_v_f_indyu.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2465
 *         f_indyd = np.empty(c_indyd.shape[0], dtype=np.int64)
 *         f_indyu = np.empty(c_indyu.shape[0], dtype=np.int64)
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].edges[2].index
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2474
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             f_indzd = np.empty(c_indzd.shape[0], dtype=np.int64)
 *             f_indzu = np.empty(c_indzu.shape[0], dtype=np.int64)
 */
  __Pyx_TraceLine(2474,0,__PYX_ERR(0, 2474, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2475
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index
 *         if self._dim == 3:
 *             f_indzd = np.empty(c_indzd.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 *             f_indzu = np.empty(c_indzu.shape[0], dtype=np.int64)
 * 
 */
    __Pyx_TraceLine(2475,0,__PYX_ERR(0, 2475, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (unlikely(!__pyx_v_c_indzd.memview)) { __Pyx_RaiseUnboundLocalError("c_indzd"); __PYX_ERR(0, 2475, __pyx_L1_error) }
    __pyx_t_12 = PyInt_FromSsize_t((__pyx_v_c_indzd.shape[0])); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12);
    __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_f_indzd = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2476
 *         if self._dim == 3:
 *             f_indzd = np.empty(c_indzd.shape[0], dtype=np.int64)
 *             f_indzu = np.empty(c_indzu.shape[0], dtype=np.int64)             # <<<<<<<<<<<<<<
 * 
 *             for i in range(f_indxd.shape[0]):
 */
    __Pyx_TraceLine(2476,0,__PYX_ERR(0, 2476, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_v_c_indzu.memview)) { __Pyx_RaiseUnboundLocalError("c_indzu"); __PYX_ERR(0, 2476, __pyx_L1_error) }
    __pyx_t_4 = PyInt_FromSsize_t((__pyx_v_c_indzu.shape[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_f_indzu = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2478
 *             f_indzu = np.empty(c_indzu.shape[0], dtype=np.int64)
 * 
 *             for i in range(f_indxd.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].faces[0].index
 *             for i in range(f_indxu.shape[0]):
 */
    __Pyx_TraceLine(2478,0,__PYX_ERR(0, 2478, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indxd.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2479
 * 
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].faces[0].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].faces[1].index
 */
      __Pyx_TraceLine(2479,0,__PYX_ERR(0, 2479, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indxd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indxd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2479, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indxd.data + __pyx_t_19 * __pyx_v_c_indxd.strides[0]) )))])->faces[0])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indxd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indxd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2479, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indxd.data + __pyx_t_19 * __pyx_v_f_indxd.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2480
 *             for i in range(f_indxd.shape[0]):
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].faces[0].index
 *             for i in range(f_indxu.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].faces[1].index
 *             for i in range(f_indyd.shape[0]):
 */
    __Pyx_TraceLine(2480,0,__PYX_ERR(0, 2480, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indxu.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2481
 *                 f_indxd[i] = self.tree.cells[c_indxd[i]].faces[0].index
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].faces[1].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].faces[2].index
 */
      __Pyx_TraceLine(2481,0,__PYX_ERR(0, 2481, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indxu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indxu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2481, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indxu.data + __pyx_t_19 * __pyx_v_c_indxu.strides[0]) )))])->faces[1])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indxu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indxu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2481, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indxu.data + __pyx_t_19 * __pyx_v_f_indxu.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2482
 *             for i in range(f_indxu.shape[0]):
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].faces[1].index
 *             for i in range(f_indyd.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].faces[2].index
 *             for i in range(f_indyu.shape[0]):
 */
    __Pyx_TraceLine(2482,0,__PYX_ERR(0, 2482, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indyd.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2483
 *                 f_indxu[i] = self.tree.cells[c_indxu[i]].faces[1].index
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].faces[2].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].faces[3].index
 */
      __Pyx_TraceLine(2483,0,__PYX_ERR(0, 2483, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indyd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indyd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2483, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indyd.data + __pyx_t_19 * __pyx_v_c_indyd.strides[0]) )))])->faces[2])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indyd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indyd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2483, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indyd.data + __pyx_t_19 * __pyx_v_f_indyd.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2484
 *             for i in range(f_indyd.shape[0]):
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].faces[2].index
 *             for i in range(f_indyu.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].faces[3].index
 *             for i in range(f_indzd.shape[0]):
 */
    __Pyx_TraceLine(2484,0,__PYX_ERR(0, 2484, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indyu.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2485
 *                 f_indyd[i] = self.tree.cells[c_indyd[i]].faces[2].index
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].faces[3].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indzd.shape[0]):
 *                 f_indzd[i] = self.tree.cells[c_indzd[i]].faces[4].index
 */
      __Pyx_TraceLine(2485,0,__PYX_ERR(0, 2485, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indyu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indyu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2485, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indyu.data + __pyx_t_19 * __pyx_v_c_indyu.strides[0]) )))])->faces[3])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indyu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indyu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2485, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indyu.data + __pyx_t_19 * __pyx_v_f_indyu.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2486
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].faces[3].index
 *             for i in range(f_indzd.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indzd[i] = self.tree.cells[c_indzd[i]].faces[4].index
 *             for i in range(f_indzu.shape[0]):
 */
    __Pyx_TraceLine(2486,0,__PYX_ERR(0, 2486, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indzd.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2487
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].faces[3].index
 *             for i in range(f_indzd.shape[0]):
 *                 f_indzd[i] = self.tree.cells[c_indzd[i]].faces[4].index             # <<<<<<<<<<<<<<
 *             for i in range(f_indzu.shape[0]):
 *                 f_indzu[i] = self.tree.cells[c_indzu[i]].faces[5].index
 */
      __Pyx_TraceLine(2487,0,__PYX_ERR(0, 2487, __pyx_L1_error))
      if (unlikely(!__pyx_v_c_indzd.memview)) { __Pyx_RaiseUnboundLocalError("c_indzd"); __PYX_ERR(0, 2487, __pyx_L1_error) }
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indzd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indzd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2487, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indzd.data + __pyx_t_19 * __pyx_v_c_indzd.strides[0]) )))])->faces[4])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indzd.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indzd.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2487, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indzd.data + __pyx_t_19 * __pyx_v_f_indzd.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2488
 *             for i in range(f_indzd.shape[0]):
 *                 f_indzd[i] = self.tree.cells[c_indzd[i]].faces[4].index
 *             for i in range(f_indzu.shape[0]):             # <<<<<<<<<<<<<<
 *                 f_indzu[i] = self.tree.cells[c_indzu[i]].faces[5].index
 *         ixd = np.array(f_indxd)
 */
    __Pyx_TraceLine(2488,0,__PYX_ERR(0, 2488, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_f_indzu.shape[0]);
    __pyx_t_17 = __pyx_t_16;
    for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
      __pyx_v_i = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2489
 *                 f_indzd[i] = self.tree.cells[c_indzd[i]].faces[4].index
 *             for i in range(f_indzu.shape[0]):
 *                 f_indzu[i] = self.tree.cells[c_indzu[i]].faces[5].index             # <<<<<<<<<<<<<<
 *         ixd = np.array(f_indxd)
 *         ixu = np.array(f_indxu)
 */
      __Pyx_TraceLine(2489,0,__PYX_ERR(0, 2489, __pyx_L1_error))
      if (unlikely(!__pyx_v_c_indzu.memview)) { __Pyx_RaiseUnboundLocalError("c_indzu"); __PYX_ERR(0, 2489, __pyx_L1_error) }
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_c_indzu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_c_indzu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2489, __pyx_L1_error)
      }
      __pyx_t_21 = ((__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_c_indzu.data + __pyx_t_19 * __pyx_v_c_indzu.strides[0]) )))])->faces[5])->index;
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_f_indzu.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_f_indzu.shape[0])) __pyx_t_20 = 0;
      if (unlikely(__pyx_t_20 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_20);
        __PYX_ERR(0, 2489, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_f_indzu.data + __pyx_t_19 * __pyx_v_f_indzu.strides[0]) )) = __pyx_t_21;
    }

    /* "discretize/_extensions/tree_ext.pyx":2474
 *             for i in range(f_indyu.shape[0]):
 *                 f_indyu[i] = self.tree.cells[c_indyu[i]].edges[1].index
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             f_indzd = np.empty(c_indzd.shape[0], dtype=np.int64)
 *             f_indzu = np.empty(c_indzu.shape[0], dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2490
 *             for i in range(f_indzu.shape[0]):
 *                 f_indzu[i] = self.tree.cells[c_indzu[i]].faces[5].index
 *         ixd = np.array(f_indxd)             # <<<<<<<<<<<<<<
 *         ixu = np.array(f_indxu)
 *         iyd = np.array(f_indyd)
 */
  __Pyx_TraceLine(2490,0,__PYX_ERR(0, 2490, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_f_indxd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_12, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ixd = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2491
 *                 f_indzu[i] = self.tree.cells[c_indzu[i]].faces[5].index
 *         ixd = np.array(f_indxd)
 *         ixu = np.array(f_indxu)             # <<<<<<<<<<<<<<
 *         iyd = np.array(f_indyd)
 *         iyu = np.array(f_indyu)
 */
  __Pyx_TraceLine(2491,0,__PYX_ERR(0, 2491, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_f_indxu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ixu = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2492
 *         ixd = np.array(f_indxd)
 *         ixu = np.array(f_indxu)
 *         iyd = np.array(f_indyd)             # <<<<<<<<<<<<<<
 *         iyu = np.array(f_indyu)
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(2492,0,__PYX_ERR(0, 2492, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_f_indyd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_12, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_iyd = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2493
 *         ixu = np.array(f_indxu)
 *         iyd = np.array(f_indyd)
 *         iyu = np.array(f_indyu)             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             izd = np.array(f_indzd)
 */
  __Pyx_TraceLine(2493,0,__PYX_ERR(0, 2493, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_f_indyu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_iyu = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2494
 *         iyd = np.array(f_indyd)
 *         iyu = np.array(f_indyu)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             izd = np.array(f_indzd)
 *             izu = np.array(f_indzu)
 */
  __Pyx_TraceLine(2494,0,__PYX_ERR(0, 2494, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2495
 *         iyu = np.array(f_indyu)
 *         if self._dim == 3:
 *             izd = np.array(f_indzd)             # <<<<<<<<<<<<<<
 *             izu = np.array(f_indzu)
 *             return ixd, ixu, iyd, iyu, izd, izu
 */
    __Pyx_TraceLine(2495,0,__PYX_ERR(0, 2495, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_v_f_indzd.memview)) { __Pyx_RaiseUnboundLocalError("f_indzd"); __PYX_ERR(0, 2495, __pyx_L1_error) }
    __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_f_indzd, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_12 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_12, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_izd = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2496
 *         if self._dim == 3:
 *             izd = np.array(f_indzd)
 *             izu = np.array(f_indzu)             # <<<<<<<<<<<<<<
 *             return ixd, ixu, iyd, iyu, izd, izu
 *         else:
 */
    __Pyx_TraceLine(2496,0,__PYX_ERR(0, 2496, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_v_f_indzu.memview)) { __Pyx_RaiseUnboundLocalError("f_indzu"); __PYX_ERR(0, 2496, __pyx_L1_error) }
    __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_f_indzu, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_12 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_12, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_izu = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2497
 *             izd = np.array(f_indzd)
 *             izu = np.array(f_indzu)
 *             return ixd, ixu, iyd, iyu, izd, izu             # <<<<<<<<<<<<<<
 *         else:
 *             return ixd, ixu, iyd, iyu
 */
    __Pyx_TraceLine(2497,0,__PYX_ERR(0, 2497, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_ixd);
    __Pyx_GIVEREF(__pyx_v_ixd);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ixd);
    __Pyx_INCREF(__pyx_v_ixu);
    __Pyx_GIVEREF(__pyx_v_ixu);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_ixu);
    __Pyx_INCREF(__pyx_v_iyd);
    __Pyx_GIVEREF(__pyx_v_iyd);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_iyd);
    __Pyx_INCREF(__pyx_v_iyu);
    __Pyx_GIVEREF(__pyx_v_iyu);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_iyu);
    __Pyx_INCREF(__pyx_v_izd);
    __Pyx_GIVEREF(__pyx_v_izd);
    PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_izd);
    __Pyx_INCREF(__pyx_v_izu);
    __Pyx_GIVEREF(__pyx_v_izu);
    PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_v_izu);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2494
 *         iyd = np.array(f_indyd)
 *         iyu = np.array(f_indyu)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             izd = np.array(f_indzd)
 *             izu = np.array(f_indzu)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2499
 *             return ixd, ixu, iyd, iyu, izd, izu
 *         else:
 *             return ixd, ixu, iyd, iyu             # <<<<<<<<<<<<<<
 * 
 *     def get_boundary_cells(self, active_ind=None, direction='zu'):
 */
  __Pyx_TraceLine(2499,0,__PYX_ERR(0, 2499, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_ixd);
    __Pyx_GIVEREF(__pyx_v_ixd);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ixd);
    __Pyx_INCREF(__pyx_v_ixu);
    __Pyx_GIVEREF(__pyx_v_ixu);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_ixu);
    __Pyx_INCREF(__pyx_v_iyd);
    __Pyx_GIVEREF(__pyx_v_iyd);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_iyd);
    __Pyx_INCREF(__pyx_v_iyu);
    __Pyx_GIVEREF(__pyx_v_iyu);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_iyu);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":2402
 * 
 *     @property
 *     def face_boundary_indices(self):             # <<<<<<<<<<<<<<
 *         """Returns the indices of the x, y (and z) boundary faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.face_boundary_indices.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cell_boundary_inds);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indxu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indxd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indyu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indyd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indzu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_c_indzd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indxu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indxd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indyu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indyd, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indzu, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_f_indzd, 1);
  __Pyx_XDECREF(__pyx_v_ixd);
  __Pyx_XDECREF(__pyx_v_ixu);
  __Pyx_XDECREF(__pyx_v_iyd);
  __Pyx_XDECREF(__pyx_v_iyu);
  __Pyx_XDECREF(__pyx_v_izd);
  __Pyx_XDECREF(__pyx_v_izu);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2501
 *             return ixd, ixu, iyd, iyu
 * 
 *     def get_boundary_cells(self, active_ind=None, direction='zu'):             # <<<<<<<<<<<<<<
 *         """Return the indices of boundary cells in a given direction given an active index array.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29get_boundary_cells(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_28get_boundary_cells[] = "_TreeMesh.get_boundary_cells(self, active_ind=None, direction=u'zu')\nReturn the indices of boundary cells in a given direction given an active index array.\n\n        Parameters\n        ----------\n        active_ind : array_like of bool, optional\n            If not None, then this must show which cells are active\n        direction: {'zu', 'zd', 'xu', 'xd', 'yu', 'yd'}\n            The requested direction to return\n\n        Returns\n        -------\n        numpy.ndarray of int\n            Array of indices for the boundary cells in the requested direction\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29get_boundary_cells(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_active_ind = 0;
  PyObject *__pyx_v_direction = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_boundary_cells (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_active_ind,&__pyx_n_s_direction,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)__pyx_n_u_zu);
    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 (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_active_ind);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_direction);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_boundary_cells") < 0)) __PYX_ERR(0, 2501, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_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;
      }
    }
    __pyx_v_active_ind = values[0];
    __pyx_v_direction = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_boundary_cells", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2501, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.get_boundary_cells", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_28get_boundary_cells(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_active_ind, __pyx_v_direction);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_28get_boundary_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_active_ind, PyObject *__pyx_v_direction) {
  PyObject *__pyx_v_dir_str = NULL;
  int_t __pyx_v_dir_ind;
  __Pyx_memviewslice __pyx_v_act = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_is_on_boundary = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  Cell *__pyx_v_neighbor;
  PyObject *__pyx_v_is_bound = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  int __pyx_t_14;
  __pyx_t_5numpy_int8_t __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_boundary_cells", 0);
  __Pyx_TraceCall("get_boundary_cells", __pyx_f[0], 2501, 0, __PYX_ERR(0, 2501, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_active_ind);
  __Pyx_INCREF(__pyx_v_direction);

  /* "discretize/_extensions/tree_ext.pyx":2517
 *         """
 * 
 *         direction = direction.lower()             # <<<<<<<<<<<<<<
 *         if direction[0] == 'z' and self._dim == 2:
 *             dir_str = 'y'+direction[1]
 */
  __Pyx_TraceLine(2517,0,__PYX_ERR(0, 2517, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_direction, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2517, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2517, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_direction, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2518
 * 
 *         direction = direction.lower()
 *         if direction[0] == 'z' and self._dim == 2:             # <<<<<<<<<<<<<<
 *             dir_str = 'y'+direction[1]
 *         else:
 */
  __Pyx_TraceLine(2518,0,__PYX_ERR(0, 2518, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_direction, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2518, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_z, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2518, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_5) {
  } else {
    __pyx_t_4 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = ((__pyx_v_self->_dim == 2) != 0);
  __pyx_t_4 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_4) {

    /* "discretize/_extensions/tree_ext.pyx":2519
 *         direction = direction.lower()
 *         if direction[0] == 'z' and self._dim == 2:
 *             dir_str = 'y'+direction[1]             # <<<<<<<<<<<<<<
 *         else:
 *             dir_str = direction
 */
    __Pyx_TraceLine(2519,0,__PYX_ERR(0, 2519, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_direction, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2519, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Add(__pyx_n_u_y, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2519, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_dir_str = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2518
 * 
 *         direction = direction.lower()
 *         if direction[0] == 'z' and self._dim == 2:             # <<<<<<<<<<<<<<
 *             dir_str = 'y'+direction[1]
 *         else:
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":2521
 *             dir_str = 'y'+direction[1]
 *         else:
 *             dir_str = direction             # <<<<<<<<<<<<<<
 *         cdef int_t dir_ind = {'xd':0, 'xu':1, 'yd':2, 'yu':3, 'zd':4, 'zu':5}[dir_str]
 *         if active_ind is None:
 */
  __Pyx_TraceLine(2521,0,__PYX_ERR(0, 2521, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(__pyx_v_direction);
    __pyx_v_dir_str = __pyx_v_direction;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":2522
 *         else:
 *             dir_str = direction
 *         cdef int_t dir_ind = {'xd':0, 'xu':1, 'yd':2, 'yu':3, 'zd':4, 'zu':5}[dir_str]             # <<<<<<<<<<<<<<
 *         if active_ind is None:
 *             return self.cell_boundary_indices[dir_ind]
 */
  __Pyx_TraceLine(2522,0,__PYX_ERR(0, 2522, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_xd, __pyx_int_0) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_xu, __pyx_int_1) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_yd, __pyx_int_2) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_yu, __pyx_int_3) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_zd, __pyx_int_4) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_zu, __pyx_int_5) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_t_2, __pyx_v_dir_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyInt_As_int_t(__pyx_t_1); if (unlikely((__pyx_t_6 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2522, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_dir_ind = __pyx_t_6;

  /* "discretize/_extensions/tree_ext.pyx":2523
 *             dir_str = direction
 *         cdef int_t dir_ind = {'xd':0, 'xu':1, 'yd':2, 'yu':3, 'zd':4, 'zu':5}[dir_str]
 *         if active_ind is None:             # <<<<<<<<<<<<<<
 *             return self.cell_boundary_indices[dir_ind]
 * 
 */
  __Pyx_TraceLine(2523,0,__PYX_ERR(0, 2523, __pyx_L1_error))
  __pyx_t_4 = (__pyx_v_active_ind == Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "discretize/_extensions/tree_ext.pyx":2524
 *         cdef int_t dir_ind = {'xd':0, 'xu':1, 'yd':2, 'yu':3, 'zd':4, 'zu':5}[dir_str]
 *         if active_ind is None:
 *             return self.cell_boundary_indices[dir_ind]             # <<<<<<<<<<<<<<
 * 
 *         active_ind = np.require(active_ind, dtype=np.int8, requirements='C')
 */
    __Pyx_TraceLine(2524,0,__PYX_ERR(0, 2524, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cell_boundary_indices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2524, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_dir_ind, int_t, 1, __Pyx_PyInt_From_int_t, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2523
 *             dir_str = direction
 *         cdef int_t dir_ind = {'xd':0, 'xu':1, 'yd':2, 'yu':3, 'zd':4, 'zu':5}[dir_str]
 *         if active_ind is None:             # <<<<<<<<<<<<<<
 *             return self.cell_boundary_indices[dir_ind]
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2526
 *             return self.cell_boundary_indices[dir_ind]
 * 
 *         active_ind = np.require(active_ind, dtype=np.int8, requirements='C')             # <<<<<<<<<<<<<<
 *         cdef np.int8_t[:] act = active_ind
 *         cdef np.int8_t[:] is_on_boundary = np.zeros(self.n_cells, dtype=np.int8)
 */
  __Pyx_TraceLine(2526,0,__PYX_ERR(0, 2526, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_require); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_active_ind);
  __Pyx_GIVEREF(__pyx_v_active_ind);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_active_ind);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 2526, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2526, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_active_ind, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2527
 * 
 *         active_ind = np.require(active_ind, dtype=np.int8, requirements='C')
 *         cdef np.int8_t[:] act = active_ind             # <<<<<<<<<<<<<<
 *         cdef np.int8_t[:] is_on_boundary = np.zeros(self.n_cells, dtype=np.int8)
 * 
 */
  __Pyx_TraceLine(2527,0,__PYX_ERR(0, 2527, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int8_t(__pyx_v_active_ind, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2527, __pyx_L1_error)
  __pyx_v_act = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2528
 *         active_ind = np.require(active_ind, dtype=np.int8, requirements='C')
 *         cdef np.int8_t[:] act = active_ind
 *         cdef np.int8_t[:] is_on_boundary = np.zeros(self.n_cells, dtype=np.int8)             # <<<<<<<<<<<<<<
 * 
 *         cdef c_Cell *cell
 */
  __Pyx_TraceLine(2528,0,__PYX_ERR(0, 2528, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int8_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_is_on_boundary = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2533
 *         cdef c_Cell *neighbor
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             if not act[cell.index]:
 *                 continue
 */
  __Pyx_TraceLine(2533,0,__PYX_ERR(0, 2533, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":2534
 * 
 *         for cell in self.tree.cells:
 *             if not act[cell.index]:             # <<<<<<<<<<<<<<
 *                 continue
 *             is_bound = 0
 */
    __Pyx_TraceLine(2534,0,__PYX_ERR(0, 2534, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_t_14 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_act.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 2534, __pyx_L1_error)
    }
    __pyx_t_5 = ((!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0)) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2535
 *         for cell in self.tree.cells:
 *             if not act[cell.index]:
 *                 continue             # <<<<<<<<<<<<<<
 *             is_bound = 0
 *             neighbor = cell.neighbors[dir_ind]
 */
      __Pyx_TraceLine(2535,0,__PYX_ERR(0, 2535, __pyx_L1_error))
      goto __pyx_L7_continue;

      /* "discretize/_extensions/tree_ext.pyx":2534
 * 
 *         for cell in self.tree.cells:
 *             if not act[cell.index]:             # <<<<<<<<<<<<<<
 *                 continue
 *             is_bound = 0
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2536
 *             if not act[cell.index]:
 *                 continue
 *             is_bound = 0             # <<<<<<<<<<<<<<
 *             neighbor = cell.neighbors[dir_ind]
 *             if neighbor is NULL:
 */
    __Pyx_TraceLine(2536,0,__PYX_ERR(0, 2536, __pyx_L1_error))
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_XDECREF_SET(__pyx_v_is_bound, __pyx_int_0);

    /* "discretize/_extensions/tree_ext.pyx":2537
 *                 continue
 *             is_bound = 0
 *             neighbor = cell.neighbors[dir_ind]             # <<<<<<<<<<<<<<
 *             if neighbor is NULL:
 *                 is_bound = 1
 */
    __Pyx_TraceLine(2537,0,__PYX_ERR(0, 2537, __pyx_L1_error))
    __pyx_v_neighbor = (__pyx_v_cell->neighbors[__pyx_v_dir_ind]);

    /* "discretize/_extensions/tree_ext.pyx":2538
 *             is_bound = 0
 *             neighbor = cell.neighbors[dir_ind]
 *             if neighbor is NULL:             # <<<<<<<<<<<<<<
 *                 is_bound = 1
 *             elif neighbor.is_leaf():
 */
    __Pyx_TraceLine(2538,0,__PYX_ERR(0, 2538, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_neighbor == NULL) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2539
 *             neighbor = cell.neighbors[dir_ind]
 *             if neighbor is NULL:
 *                 is_bound = 1             # <<<<<<<<<<<<<<
 *             elif neighbor.is_leaf():
 *                 is_bound = not act[neighbor.index]
 */
      __Pyx_TraceLine(2539,0,__PYX_ERR(0, 2539, __pyx_L1_error))
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_int_1);

      /* "discretize/_extensions/tree_ext.pyx":2538
 *             is_bound = 0
 *             neighbor = cell.neighbors[dir_ind]
 *             if neighbor is NULL:             # <<<<<<<<<<<<<<
 *                 is_bound = 1
 *             elif neighbor.is_leaf():
 */
      goto __pyx_L10;
    }

    /* "discretize/_extensions/tree_ext.pyx":2540
 *             if neighbor is NULL:
 *                 is_bound = 1
 *             elif neighbor.is_leaf():             # <<<<<<<<<<<<<<
 *                 is_bound = not act[neighbor.index]
 *             else:
 */
    __Pyx_TraceLine(2540,0,__PYX_ERR(0, 2540, __pyx_L1_error))
    __pyx_t_5 = (__pyx_v_neighbor->is_leaf() != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2541
 *                 is_bound = 1
 *             elif neighbor.is_leaf():
 *                 is_bound = not act[neighbor.index]             # <<<<<<<<<<<<<<
 *             else:
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:
 */
      __Pyx_TraceLine(2541,0,__PYX_ERR(0, 2541, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_neighbor->index;
      __pyx_t_14 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_v_act.shape[0];
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
      if (unlikely(__pyx_t_14 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_14);
        __PYX_ERR(0, 2541, __pyx_L1_error)
      }
      __pyx_t_7 = __Pyx_PyBool_FromLong((!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2541, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "discretize/_extensions/tree_ext.pyx":2540
 *             if neighbor is NULL:
 *                 is_bound = 1
 *             elif neighbor.is_leaf():             # <<<<<<<<<<<<<<
 *                 is_bound = not act[neighbor.index]
 *             else:
 */
      goto __pyx_L10;
    }

    /* "discretize/_extensions/tree_ext.pyx":2543
 *                 is_bound = not act[neighbor.index]
 *             else:
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 */
    __Pyx_TraceLine(2543,0,__PYX_ERR(0, 2543, __pyx_L1_error))
    /*else*/ {
      switch (__pyx_v_dir_ind) {
        case 1:
        CYTHON_FALLTHROUGH;
        case 3:
        CYTHON_FALLTHROUGH;
        case 5:

        /* "discretize/_extensions/tree_ext.pyx":2544
 *             else:
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])             # <<<<<<<<<<<<<<
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 */
        __Pyx_TraceLine(2544,0,__PYX_ERR(0, 2544, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2544, __pyx_L1_error)
        if (!__pyx_t_5) {
        } else {
          __Pyx_INCREF(__pyx_v_is_bound);
          __pyx_t_7 = __pyx_v_is_bound;
          goto __pyx_L11_bool_binop_done;
        }
        __pyx_t_13 = (__pyx_v_neighbor->children[0])->index;
        __pyx_t_14 = -1;
        if (__pyx_t_13 < 0) {
          __pyx_t_13 += __pyx_v_act.shape[0];
          if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
        } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
        if (unlikely(__pyx_t_14 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_14);
          __PYX_ERR(0, 2544, __pyx_L1_error)
        }
        __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
        __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2544, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __pyx_t_8;
        __pyx_t_8 = 0;
        __pyx_L11_bool_binop_done:;
        __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "discretize/_extensions/tree_ext.pyx":2543
 *                 is_bound = not act[neighbor.index]
 *             else:
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 */
        break;
        default: break;
      }

      /* "discretize/_extensions/tree_ext.pyx":2545
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 */
      __Pyx_TraceLine(2545,0,__PYX_ERR(0, 2545, __pyx_L1_error))
      switch (__pyx_v_dir_ind) {
        case 0:
        CYTHON_FALLTHROUGH;
        case 3:
        CYTHON_FALLTHROUGH;
        case 5:

        /* "discretize/_extensions/tree_ext.pyx":2546
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])             # <<<<<<<<<<<<<<
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 */
        __Pyx_TraceLine(2546,0,__PYX_ERR(0, 2546, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2546, __pyx_L1_error)
        if (!__pyx_t_5) {
        } else {
          __Pyx_INCREF(__pyx_v_is_bound);
          __pyx_t_7 = __pyx_v_is_bound;
          goto __pyx_L13_bool_binop_done;
        }
        __pyx_t_13 = (__pyx_v_neighbor->children[1])->index;
        __pyx_t_14 = -1;
        if (__pyx_t_13 < 0) {
          __pyx_t_13 += __pyx_v_act.shape[0];
          if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
        } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
        if (unlikely(__pyx_t_14 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_14);
          __PYX_ERR(0, 2546, __pyx_L1_error)
        }
        __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
        __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2546, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __pyx_t_8;
        __pyx_t_8 = 0;
        __pyx_L13_bool_binop_done:;
        __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "discretize/_extensions/tree_ext.pyx":2545
 *                 if dir_ind == 1 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[0].index])
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 */
        break;
        default: break;
      }

      /* "discretize/_extensions/tree_ext.pyx":2547
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:
 */
      __Pyx_TraceLine(2547,0,__PYX_ERR(0, 2547, __pyx_L1_error))
      switch (__pyx_v_dir_ind) {
        case 1:
        CYTHON_FALLTHROUGH;
        case 2:
        CYTHON_FALLTHROUGH;
        case 5:

        /* "discretize/_extensions/tree_ext.pyx":2548
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])             # <<<<<<<<<<<<<<
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])
 */
        __Pyx_TraceLine(2548,0,__PYX_ERR(0, 2548, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2548, __pyx_L1_error)
        if (!__pyx_t_5) {
        } else {
          __Pyx_INCREF(__pyx_v_is_bound);
          __pyx_t_7 = __pyx_v_is_bound;
          goto __pyx_L15_bool_binop_done;
        }
        __pyx_t_13 = (__pyx_v_neighbor->children[2])->index;
        __pyx_t_14 = -1;
        if (__pyx_t_13 < 0) {
          __pyx_t_13 += __pyx_v_act.shape[0];
          if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
        } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
        if (unlikely(__pyx_t_14 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_14);
          __PYX_ERR(0, 2548, __pyx_L1_error)
        }
        __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
        __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2548, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __pyx_t_8;
        __pyx_t_8 = 0;
        __pyx_L15_bool_binop_done:;
        __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "discretize/_extensions/tree_ext.pyx":2547
 *                 if dir_ind == 0 or dir_ind == 3 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[1].index])
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:
 */
        break;
        default: break;
      }

      /* "discretize/_extensions/tree_ext.pyx":2549
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])
 * 
 */
      __Pyx_TraceLine(2549,0,__PYX_ERR(0, 2549, __pyx_L1_error))
      switch (__pyx_v_dir_ind) {
        case 0:
        CYTHON_FALLTHROUGH;
        case 2:
        CYTHON_FALLTHROUGH;
        case 5:

        /* "discretize/_extensions/tree_ext.pyx":2550
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])             # <<<<<<<<<<<<<<
 * 
 *                 if self._dim == 3:
 */
        __Pyx_TraceLine(2550,0,__PYX_ERR(0, 2550, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2550, __pyx_L1_error)
        if (!__pyx_t_5) {
        } else {
          __Pyx_INCREF(__pyx_v_is_bound);
          __pyx_t_7 = __pyx_v_is_bound;
          goto __pyx_L17_bool_binop_done;
        }
        __pyx_t_13 = (__pyx_v_neighbor->children[3])->index;
        __pyx_t_14 = -1;
        if (__pyx_t_13 < 0) {
          __pyx_t_13 += __pyx_v_act.shape[0];
          if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
        } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
        if (unlikely(__pyx_t_14 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_14);
          __PYX_ERR(0, 2550, __pyx_L1_error)
        }
        __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
        __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2550, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __pyx_t_8;
        __pyx_t_8 = 0;
        __pyx_L17_bool_binop_done:;
        __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "discretize/_extensions/tree_ext.pyx":2549
 *                 if dir_ind == 1 or dir_ind == 2 or dir_ind == 5:
 *                     is_bound = is_bound or (not act[neighbor.children[2].index])
 *                 if dir_ind == 0 or dir_ind == 2 or dir_ind == 5:             # <<<<<<<<<<<<<<
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])
 * 
 */
        break;
        default: break;
      }

      /* "discretize/_extensions/tree_ext.pyx":2552
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])
 * 
 *                 if self._dim == 3:             # <<<<<<<<<<<<<<
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 */
      __Pyx_TraceLine(2552,0,__PYX_ERR(0, 2552, __pyx_L1_error))
      __pyx_t_5 = ((__pyx_v_self->_dim == 3) != 0);
      if (__pyx_t_5) {

        /* "discretize/_extensions/tree_ext.pyx":2553
 * 
 *                 if self._dim == 3:
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 */
        __Pyx_TraceLine(2553,0,__PYX_ERR(0, 2553, __pyx_L1_error))
        switch (__pyx_v_dir_ind) {
          case 1:
          CYTHON_FALLTHROUGH;
          case 3:
          CYTHON_FALLTHROUGH;
          case 4:

          /* "discretize/_extensions/tree_ext.pyx":2554
 *                 if self._dim == 3:
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])             # <<<<<<<<<<<<<<
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 */
          __Pyx_TraceLine(2554,0,__PYX_ERR(0, 2554, __pyx_L1_error))
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2554, __pyx_L1_error)
          if (!__pyx_t_5) {
          } else {
            __Pyx_INCREF(__pyx_v_is_bound);
            __pyx_t_7 = __pyx_v_is_bound;
            goto __pyx_L20_bool_binop_done;
          }
          __pyx_t_13 = (__pyx_v_neighbor->children[4])->index;
          __pyx_t_14 = -1;
          if (__pyx_t_13 < 0) {
            __pyx_t_13 += __pyx_v_act.shape[0];
            if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
          } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
          if (unlikely(__pyx_t_14 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_14);
            __PYX_ERR(0, 2554, __pyx_L1_error)
          }
          __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2554, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __pyx_t_8;
          __pyx_t_8 = 0;
          __pyx_L20_bool_binop_done:;
          __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":2553
 * 
 *                 if self._dim == 3:
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 */
          break;
          default: break;
        }

        /* "discretize/_extensions/tree_ext.pyx":2555
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 */
        __Pyx_TraceLine(2555,0,__PYX_ERR(0, 2555, __pyx_L1_error))
        switch (__pyx_v_dir_ind) {
          case 0:
          CYTHON_FALLTHROUGH;
          case 3:
          CYTHON_FALLTHROUGH;
          case 4:

          /* "discretize/_extensions/tree_ext.pyx":2556
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])             # <<<<<<<<<<<<<<
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 */
          __Pyx_TraceLine(2556,0,__PYX_ERR(0, 2556, __pyx_L1_error))
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2556, __pyx_L1_error)
          if (!__pyx_t_5) {
          } else {
            __Pyx_INCREF(__pyx_v_is_bound);
            __pyx_t_7 = __pyx_v_is_bound;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_13 = (__pyx_v_neighbor->children[5])->index;
          __pyx_t_14 = -1;
          if (__pyx_t_13 < 0) {
            __pyx_t_13 += __pyx_v_act.shape[0];
            if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
          } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
          if (unlikely(__pyx_t_14 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_14);
            __PYX_ERR(0, 2556, __pyx_L1_error)
          }
          __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2556, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __pyx_t_8;
          __pyx_t_8 = 0;
          __pyx_L22_bool_binop_done:;
          __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":2555
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 */
          break;
          default: break;
        }

        /* "discretize/_extensions/tree_ext.pyx":2557
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:
 */
        __Pyx_TraceLine(2557,0,__PYX_ERR(0, 2557, __pyx_L1_error))
        switch (__pyx_v_dir_ind) {
          case 1:
          CYTHON_FALLTHROUGH;
          case 2:
          CYTHON_FALLTHROUGH;
          case 4:

          /* "discretize/_extensions/tree_ext.pyx":2558
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])             # <<<<<<<<<<<<<<
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[7].index])
 */
          __Pyx_TraceLine(2558,0,__PYX_ERR(0, 2558, __pyx_L1_error))
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2558, __pyx_L1_error)
          if (!__pyx_t_5) {
          } else {
            __Pyx_INCREF(__pyx_v_is_bound);
            __pyx_t_7 = __pyx_v_is_bound;
            goto __pyx_L24_bool_binop_done;
          }
          __pyx_t_13 = (__pyx_v_neighbor->children[6])->index;
          __pyx_t_14 = -1;
          if (__pyx_t_13 < 0) {
            __pyx_t_13 += __pyx_v_act.shape[0];
            if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
          } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
          if (unlikely(__pyx_t_14 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_14);
            __PYX_ERR(0, 2558, __pyx_L1_error)
          }
          __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2558, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __pyx_t_8;
          __pyx_t_8 = 0;
          __pyx_L24_bool_binop_done:;
          __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":2557
 *                     if dir_ind == 0 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[5].index])
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:
 */
          break;
          default: break;
        }

        /* "discretize/_extensions/tree_ext.pyx":2559
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[7].index])
 * 
 */
        __Pyx_TraceLine(2559,0,__PYX_ERR(0, 2559, __pyx_L1_error))
        switch (__pyx_v_dir_ind) {
          case 0:
          CYTHON_FALLTHROUGH;
          case 2:
          CYTHON_FALLTHROUGH;
          case 4:

          /* "discretize/_extensions/tree_ext.pyx":2560
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[7].index])             # <<<<<<<<<<<<<<
 * 
 *             is_on_boundary[cell.index] = is_bound
 */
          __Pyx_TraceLine(2560,0,__PYX_ERR(0, 2560, __pyx_L1_error))
          __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_is_bound); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2560, __pyx_L1_error)
          if (!__pyx_t_5) {
          } else {
            __Pyx_INCREF(__pyx_v_is_bound);
            __pyx_t_7 = __pyx_v_is_bound;
            goto __pyx_L26_bool_binop_done;
          }
          __pyx_t_13 = (__pyx_v_neighbor->children[7])->index;
          __pyx_t_14 = -1;
          if (__pyx_t_13 < 0) {
            __pyx_t_13 += __pyx_v_act.shape[0];
            if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
          } else if (unlikely(__pyx_t_13 >= __pyx_v_act.shape[0])) __pyx_t_14 = 0;
          if (unlikely(__pyx_t_14 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_14);
            __PYX_ERR(0, 2560, __pyx_L1_error)
          }
          __pyx_t_5 = (!((*((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_act.data + __pyx_t_13 * __pyx_v_act.strides[0]) ))) != 0));
          __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2560, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __pyx_t_8;
          __pyx_t_8 = 0;
          __pyx_L26_bool_binop_done:;
          __Pyx_DECREF_SET(__pyx_v_is_bound, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "discretize/_extensions/tree_ext.pyx":2559
 *                     if dir_ind == 1 or dir_ind == 2 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[6].index])
 *                     if dir_ind == 0 or dir_ind == 2 or dir_ind == 4:             # <<<<<<<<<<<<<<
 *                         is_bound = is_bound or (not act[neighbor.children[7].index])
 * 
 */
          break;
          default: break;
        }

        /* "discretize/_extensions/tree_ext.pyx":2552
 *                     is_bound = is_bound or (not act[neighbor.children[3].index])
 * 
 *                 if self._dim == 3:             # <<<<<<<<<<<<<<
 *                     if dir_ind == 1 or dir_ind == 3 or dir_ind == 4:
 *                         is_bound = is_bound or (not act[neighbor.children[4].index])
 */
      }
    }
    __pyx_L10:;

    /* "discretize/_extensions/tree_ext.pyx":2562
 *                         is_bound = is_bound or (not act[neighbor.children[7].index])
 * 
 *             is_on_boundary[cell.index] = is_bound             # <<<<<<<<<<<<<<
 * 
 *         return np.where(is_on_boundary)
 */
    __Pyx_TraceLine(2562,0,__PYX_ERR(0, 2562, __pyx_L1_error))
    __pyx_t_15 = __Pyx_PyInt_As_npy_int8(__pyx_v_is_bound); if (unlikely((__pyx_t_15 == ((npy_int8)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2562, __pyx_L1_error)
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_t_14 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_is_on_boundary.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_is_on_boundary.shape[0])) __pyx_t_14 = 0;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 2562, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int8_t *) ( /* dim=0 */ (__pyx_v_is_on_boundary.data + __pyx_t_13 * __pyx_v_is_on_boundary.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":2533
 *         cdef c_Cell *neighbor
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             if not act[cell.index]:
 *                 continue
 */
    __Pyx_TraceLine(2533,0,__PYX_ERR(0, 2533, __pyx_L1_error))
    __pyx_L7_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":2564
 *             is_on_boundary[cell.index] = is_bound
 * 
 *         return np.where(is_on_boundary)             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
  __Pyx_TraceLine(2564,0,__PYX_ERR(0, 2564, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_where); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_is_on_boundary, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int8_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int8_t, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_7 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_8);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2501
 *             return ixd, ixu, iyd, iyu
 * 
 *     def get_boundary_cells(self, active_ind=None, direction='zu'):             # <<<<<<<<<<<<<<
 *         """Return the indices of boundary cells in a given direction given an active index array.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.get_boundary_cells", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_dir_str);
  __PYX_XDEC_MEMVIEW(&__pyx_v_act, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_is_on_boundary, 1);
  __Pyx_XDECREF(__pyx_v_is_bound);
  __Pyx_XDECREF(__pyx_v_active_ind);
  __Pyx_XDECREF(__pyx_v_direction);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2567
 * 
 *     @cython.cdivision(True)
 *     def get_cells_along_line(self, x0, x1):             # <<<<<<<<<<<<<<
 *         """Find the cells along a line segment defined by two points.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_31get_cells_along_line(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_30get_cells_along_line[] = "_TreeMesh.get_cells_along_line(self, x0, x1)\nFind the cells along a line segment defined by two points.\n\n        Parameters\n        ----------\n        x0,x1 : (dim) array_like\n            Begining and ending point of the line segment.\n\n        Returns\n        -------\n        list of int\n            Indices for cells that contain the a line defined by the two input\n            points, ordered in the direction of the line.\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_31get_cells_along_line(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_x0 = 0;
  PyObject *__pyx_v_x1 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_cells_along_line (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x0,&__pyx_n_s_x1,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_x0)) != 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_x1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_cells_along_line", 1, 2, 2, 1); __PYX_ERR(0, 2567, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_cells_along_line") < 0)) __PYX_ERR(0, 2567, __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_x0 = values[0];
    __pyx_v_x1 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_cells_along_line", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2567, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.get_cells_along_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_30get_cells_along_line(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_x0, __pyx_v_x1);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_30get_cells_along_line(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_x0, PyObject *__pyx_v_x1) {
  __pyx_t_5numpy_float64_t __pyx_v_ax;
  __pyx_t_5numpy_float64_t __pyx_v_ay;
  __pyx_t_5numpy_float64_t __pyx_v_az;
  __pyx_t_5numpy_float64_t __pyx_v_bx;
  __pyx_t_5numpy_float64_t __pyx_v_by;
  __pyx_t_5numpy_float64_t __pyx_v_bz;
  int __pyx_v_dim;
  std::vector<PY_LONG_LONG>  __pyx_v_cell_indexes;
  Cell *__pyx_v_cur_cell;
  Cell *__pyx_v_last_cell;
  Cell *__pyx_v_next_cell;
  int __pyx_v_ix;
  int __pyx_v_iy;
  int __pyx_v_iz;
  double __pyx_v_tx;
  double __pyx_v_ty;
  double __pyx_v_tz;
  double __pyx_v_ipx;
  double __pyx_v_ipy;
  double __pyx_v_ipz;
  long __pyx_v_last_point;
  CYTHON_UNUSED int __pyx_v_iter;
  double *__pyx_v_p0;
  double *__pyx_v_pF;
  double __pyx_v_t;
  double *__pyx_v_cp;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __pyx_t_5numpy_float64_t __pyx_t_3;
  __pyx_t_5numpy_float64_t __pyx_t_4;
  int __pyx_t_5;
  double *__pyx_t_6;
  double __pyx_t_7;
  double __pyx_t_8;
  double __pyx_t_9;
  double __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_cells_along_line", 0);
  __Pyx_TraceCall("get_cells_along_line", __pyx_f[0], 2567, 0, __PYX_ERR(0, 2567, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2583
 *         cdef np.float64_t ax, ay, az, bx, by, bz
 * 
 *         cdef int dim = self.dim             # <<<<<<<<<<<<<<
 *         ax = x0[0]
 *         ay = x0[1]
 */
  __Pyx_TraceLine(2583,0,__PYX_ERR(0, 2583, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2583, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_dim = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":2584
 * 
 *         cdef int dim = self.dim
 *         ax = x0[0]             # <<<<<<<<<<<<<<
 *         ay = x0[1]
 *         az = x0[2] if dim==3 else 0
 */
  __Pyx_TraceLine(2584,0,__PYX_ERR(0, 2584, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x0, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2584, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ax = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2585
 *         cdef int dim = self.dim
 *         ax = x0[0]
 *         ay = x0[1]             # <<<<<<<<<<<<<<
 *         az = x0[2] if dim==3 else 0
 * 
 */
  __Pyx_TraceLine(2585,0,__PYX_ERR(0, 2585, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x0, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2585, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ay = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2586
 *         ax = x0[0]
 *         ay = x0[1]
 *         az = x0[2] if dim==3 else 0             # <<<<<<<<<<<<<<
 * 
 *         bx = x1[0]
 */
  __Pyx_TraceLine(2586,0,__PYX_ERR(0, 2586, __pyx_L1_error))
  if (((__pyx_v_dim == 3) != 0)) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x0, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_4 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2586, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __pyx_t_4;
  } else {
    __pyx_t_3 = 0.0;
  }
  __pyx_v_az = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2588
 *         az = x0[2] if dim==3 else 0
 * 
 *         bx = x1[0]             # <<<<<<<<<<<<<<
 *         by = x1[1]
 *         bz = x1[2] if dim==3 else 0
 */
  __Pyx_TraceLine(2588,0,__PYX_ERR(0, 2588, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2588, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_bx = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2589
 * 
 *         bx = x1[0]
 *         by = x1[1]             # <<<<<<<<<<<<<<
 *         bz = x1[2] if dim==3 else 0
 * 
 */
  __Pyx_TraceLine(2589,0,__PYX_ERR(0, 2589, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2589, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_by = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2590
 *         bx = x1[0]
 *         by = x1[1]
 *         bz = x1[2] if dim==3 else 0             # <<<<<<<<<<<<<<
 * 
 *         cdef vector[long long int] cell_indexes;
 */
  __Pyx_TraceLine(2590,0,__PYX_ERR(0, 2590, __pyx_L1_error))
  if (((__pyx_v_dim == 3) != 0)) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x1, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2590, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_4 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2590, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __pyx_t_4;
  } else {
    __pyx_t_3 = 0.0;
  }
  __pyx_v_bz = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2595
 * 
 *         #find initial cell
 *         cdef c_Cell *cur_cell = self.tree.containing_cell(ax, ay, az)             # <<<<<<<<<<<<<<
 *         cell_indexes.push_back(cur_cell.index)
 *         #find last cell
 */
  __Pyx_TraceLine(2595,0,__PYX_ERR(0, 2595, __pyx_L1_error))
  __pyx_v_cur_cell = __pyx_v_self->tree->containing_cell(__pyx_v_ax, __pyx_v_ay, __pyx_v_az);

  /* "discretize/_extensions/tree_ext.pyx":2596
 *         #find initial cell
 *         cdef c_Cell *cur_cell = self.tree.containing_cell(ax, ay, az)
 *         cell_indexes.push_back(cur_cell.index)             # <<<<<<<<<<<<<<
 *         #find last cell
 *         cdef c_Cell *last_cell = self.tree.containing_cell(bx, by, bz)
 */
  __Pyx_TraceLine(2596,0,__PYX_ERR(0, 2596, __pyx_L1_error))
  try {
    __pyx_v_cell_indexes.push_back(__pyx_v_cur_cell->index);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(0, 2596, __pyx_L1_error)
  }

  /* "discretize/_extensions/tree_ext.pyx":2598
 *         cell_indexes.push_back(cur_cell.index)
 *         #find last cell
 *         cdef c_Cell *last_cell = self.tree.containing_cell(bx, by, bz)             # <<<<<<<<<<<<<<
 *         cdef c_Cell *next_cell
 *         cdef int ix, iy, iz
 */
  __Pyx_TraceLine(2598,0,__PYX_ERR(0, 2598, __pyx_L1_error))
  __pyx_v_last_cell = __pyx_v_self->tree->containing_cell(__pyx_v_bx, __pyx_v_by, __pyx_v_bz);

  /* "discretize/_extensions/tree_ext.pyx":2603
 *         cdef double tx, ty, tz, ipx, ipy, ipz
 * 
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             last_point = 7
 *         else:
 */
  __Pyx_TraceLine(2603,0,__PYX_ERR(0, 2603, __pyx_L1_error))
  __pyx_t_5 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_5) {

    /* "discretize/_extensions/tree_ext.pyx":2604
 * 
 *         if dim==3:
 *             last_point = 7             # <<<<<<<<<<<<<<
 *         else:
 *             last_point = 3
 */
    __Pyx_TraceLine(2604,0,__PYX_ERR(0, 2604, __pyx_L1_error))
    __pyx_v_last_point = 7;

    /* "discretize/_extensions/tree_ext.pyx":2603
 *         cdef double tx, ty, tz, ipx, ipy, ipz
 * 
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             last_point = 7
 *         else:
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":2606
 *             last_point = 7
 *         else:
 *             last_point = 3             # <<<<<<<<<<<<<<
 * 
 *         cdef int iter = 0
 */
  __Pyx_TraceLine(2606,0,__PYX_ERR(0, 2606, __pyx_L1_error))
  /*else*/ {
    __pyx_v_last_point = 3;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":2608
 *             last_point = 3
 * 
 *         cdef int iter = 0             # <<<<<<<<<<<<<<
 * 
 *         while cur_cell.index != last_cell.index:
 */
  __Pyx_TraceLine(2608,0,__PYX_ERR(0, 2608, __pyx_L1_error))
  __pyx_v_iter = 0;

  /* "discretize/_extensions/tree_ext.pyx":2610
 *         cdef int iter = 0
 * 
 *         while cur_cell.index != last_cell.index:             # <<<<<<<<<<<<<<
 *             #find which direction to look:
 *             p0 = cur_cell.points[0].location
 */
  __Pyx_TraceLine(2610,0,__PYX_ERR(0, 2610, __pyx_L1_error))
  while (1) {
    __pyx_t_5 = ((__pyx_v_cur_cell->index != __pyx_v_last_cell->index) != 0);
    if (!__pyx_t_5) break;

    /* "discretize/_extensions/tree_ext.pyx":2612
 *         while cur_cell.index != last_cell.index:
 *             #find which direction to look:
 *             p0 = cur_cell.points[0].location             # <<<<<<<<<<<<<<
 *             pF = cur_cell.points[last_point].location
 * 
 */
    __Pyx_TraceLine(2612,0,__PYX_ERR(0, 2612, __pyx_L1_error))
    __pyx_t_6 = (__pyx_v_cur_cell->points[0])->location;
    __pyx_v_p0 = __pyx_t_6;

    /* "discretize/_extensions/tree_ext.pyx":2613
 *             #find which direction to look:
 *             p0 = cur_cell.points[0].location
 *             pF = cur_cell.points[last_point].location             # <<<<<<<<<<<<<<
 * 
 *             if ax>bx:
 */
    __Pyx_TraceLine(2613,0,__PYX_ERR(0, 2613, __pyx_L1_error))
    __pyx_t_6 = (__pyx_v_cur_cell->points[__pyx_v_last_point])->location;
    __pyx_v_pF = __pyx_t_6;

    /* "discretize/_extensions/tree_ext.pyx":2615
 *             pF = cur_cell.points[last_point].location
 * 
 *             if ax>bx:             # <<<<<<<<<<<<<<
 *                 tx = (p0[0]-ax)/(bx-ax)
 *             elif ax<bx:
 */
    __Pyx_TraceLine(2615,0,__PYX_ERR(0, 2615, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_ax > __pyx_v_bx) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2616
 * 
 *             if ax>bx:
 *                 tx = (p0[0]-ax)/(bx-ax)             # <<<<<<<<<<<<<<
 *             elif ax<bx:
 *                 tx = (pF[0]-ax)/(bx-ax)
 */
      __Pyx_TraceLine(2616,0,__PYX_ERR(0, 2616, __pyx_L1_error))
      __pyx_v_tx = (((__pyx_v_p0[0]) - __pyx_v_ax) / (__pyx_v_bx - __pyx_v_ax));

      /* "discretize/_extensions/tree_ext.pyx":2615
 *             pF = cur_cell.points[last_point].location
 * 
 *             if ax>bx:             # <<<<<<<<<<<<<<
 *                 tx = (p0[0]-ax)/(bx-ax)
 *             elif ax<bx:
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":2617
 *             if ax>bx:
 *                 tx = (p0[0]-ax)/(bx-ax)
 *             elif ax<bx:             # <<<<<<<<<<<<<<
 *                 tx = (pF[0]-ax)/(bx-ax)
 *             else:
 */
    __Pyx_TraceLine(2617,0,__PYX_ERR(0, 2617, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_ax < __pyx_v_bx) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2618
 *                 tx = (p0[0]-ax)/(bx-ax)
 *             elif ax<bx:
 *                 tx = (pF[0]-ax)/(bx-ax)             # <<<<<<<<<<<<<<
 *             else:
 *                 tx = INFINITY
 */
      __Pyx_TraceLine(2618,0,__PYX_ERR(0, 2618, __pyx_L1_error))
      __pyx_v_tx = (((__pyx_v_pF[0]) - __pyx_v_ax) / (__pyx_v_bx - __pyx_v_ax));

      /* "discretize/_extensions/tree_ext.pyx":2617
 *             if ax>bx:
 *                 tx = (p0[0]-ax)/(bx-ax)
 *             elif ax<bx:             # <<<<<<<<<<<<<<
 *                 tx = (pF[0]-ax)/(bx-ax)
 *             else:
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":2620
 *                 tx = (pF[0]-ax)/(bx-ax)
 *             else:
 *                 tx = INFINITY             # <<<<<<<<<<<<<<
 * 
 *             if ay>by:
 */
    __Pyx_TraceLine(2620,0,__PYX_ERR(0, 2620, __pyx_L1_error))
    /*else*/ {
      __pyx_v_tx = NPY_INFINITY;
    }
    __pyx_L6:;

    /* "discretize/_extensions/tree_ext.pyx":2622
 *                 tx = INFINITY
 * 
 *             if ay>by:             # <<<<<<<<<<<<<<
 *                 ty = (p0[1]-ay)/(by-ay)
 *             elif ay<by:
 */
    __Pyx_TraceLine(2622,0,__PYX_ERR(0, 2622, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_ay > __pyx_v_by) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2623
 * 
 *             if ay>by:
 *                 ty = (p0[1]-ay)/(by-ay)             # <<<<<<<<<<<<<<
 *             elif ay<by:
 *                 ty = (pF[1]-ay)/(by-ay)
 */
      __Pyx_TraceLine(2623,0,__PYX_ERR(0, 2623, __pyx_L1_error))
      __pyx_v_ty = (((__pyx_v_p0[1]) - __pyx_v_ay) / (__pyx_v_by - __pyx_v_ay));

      /* "discretize/_extensions/tree_ext.pyx":2622
 *                 tx = INFINITY
 * 
 *             if ay>by:             # <<<<<<<<<<<<<<
 *                 ty = (p0[1]-ay)/(by-ay)
 *             elif ay<by:
 */
      goto __pyx_L7;
    }

    /* "discretize/_extensions/tree_ext.pyx":2624
 *             if ay>by:
 *                 ty = (p0[1]-ay)/(by-ay)
 *             elif ay<by:             # <<<<<<<<<<<<<<
 *                 ty = (pF[1]-ay)/(by-ay)
 *             else:
 */
    __Pyx_TraceLine(2624,0,__PYX_ERR(0, 2624, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_ay < __pyx_v_by) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2625
 *                 ty = (p0[1]-ay)/(by-ay)
 *             elif ay<by:
 *                 ty = (pF[1]-ay)/(by-ay)             # <<<<<<<<<<<<<<
 *             else:
 *                 ty = INFINITY
 */
      __Pyx_TraceLine(2625,0,__PYX_ERR(0, 2625, __pyx_L1_error))
      __pyx_v_ty = (((__pyx_v_pF[1]) - __pyx_v_ay) / (__pyx_v_by - __pyx_v_ay));

      /* "discretize/_extensions/tree_ext.pyx":2624
 *             if ay>by:
 *                 ty = (p0[1]-ay)/(by-ay)
 *             elif ay<by:             # <<<<<<<<<<<<<<
 *                 ty = (pF[1]-ay)/(by-ay)
 *             else:
 */
      goto __pyx_L7;
    }

    /* "discretize/_extensions/tree_ext.pyx":2627
 *                 ty = (pF[1]-ay)/(by-ay)
 *             else:
 *                 ty = INFINITY             # <<<<<<<<<<<<<<
 * 
 *             if az>bz:
 */
    __Pyx_TraceLine(2627,0,__PYX_ERR(0, 2627, __pyx_L1_error))
    /*else*/ {
      __pyx_v_ty = NPY_INFINITY;
    }
    __pyx_L7:;

    /* "discretize/_extensions/tree_ext.pyx":2629
 *                 ty = INFINITY
 * 
 *             if az>bz:             # <<<<<<<<<<<<<<
 *                 tz = (p0[2]-az)/(bz-az)
 *             elif az<bz:
 */
    __Pyx_TraceLine(2629,0,__PYX_ERR(0, 2629, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_az > __pyx_v_bz) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2630
 * 
 *             if az>bz:
 *                 tz = (p0[2]-az)/(bz-az)             # <<<<<<<<<<<<<<
 *             elif az<bz:
 *                 tz = (pF[2]-az)/(bz-az)
 */
      __Pyx_TraceLine(2630,0,__PYX_ERR(0, 2630, __pyx_L1_error))
      __pyx_v_tz = (((__pyx_v_p0[2]) - __pyx_v_az) / (__pyx_v_bz - __pyx_v_az));

      /* "discretize/_extensions/tree_ext.pyx":2629
 *                 ty = INFINITY
 * 
 *             if az>bz:             # <<<<<<<<<<<<<<
 *                 tz = (p0[2]-az)/(bz-az)
 *             elif az<bz:
 */
      goto __pyx_L8;
    }

    /* "discretize/_extensions/tree_ext.pyx":2631
 *             if az>bz:
 *                 tz = (p0[2]-az)/(bz-az)
 *             elif az<bz:             # <<<<<<<<<<<<<<
 *                 tz = (pF[2]-az)/(bz-az)
 *             else:
 */
    __Pyx_TraceLine(2631,0,__PYX_ERR(0, 2631, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_az < __pyx_v_bz) != 0);
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2632
 *                 tz = (p0[2]-az)/(bz-az)
 *             elif az<bz:
 *                 tz = (pF[2]-az)/(bz-az)             # <<<<<<<<<<<<<<
 *             else:
 *                 tz = INFINITY
 */
      __Pyx_TraceLine(2632,0,__PYX_ERR(0, 2632, __pyx_L1_error))
      __pyx_v_tz = (((__pyx_v_pF[2]) - __pyx_v_az) / (__pyx_v_bz - __pyx_v_az));

      /* "discretize/_extensions/tree_ext.pyx":2631
 *             if az>bz:
 *                 tz = (p0[2]-az)/(bz-az)
 *             elif az<bz:             # <<<<<<<<<<<<<<
 *                 tz = (pF[2]-az)/(bz-az)
 *             else:
 */
      goto __pyx_L8;
    }

    /* "discretize/_extensions/tree_ext.pyx":2634
 *                 tz = (pF[2]-az)/(bz-az)
 *             else:
 *                 tz = INFINITY             # <<<<<<<<<<<<<<
 * 
 *             t = min(tx,ty,tz)
 */
    __Pyx_TraceLine(2634,0,__PYX_ERR(0, 2634, __pyx_L1_error))
    /*else*/ {
      __pyx_v_tz = NPY_INFINITY;
    }
    __pyx_L8:;

    /* "discretize/_extensions/tree_ext.pyx":2636
 *                 tz = INFINITY
 * 
 *             t = min(tx,ty,tz)             # <<<<<<<<<<<<<<
 * 
 *             #intersection point
 */
    __Pyx_TraceLine(2636,0,__PYX_ERR(0, 2636, __pyx_L1_error))
    __pyx_t_7 = __pyx_v_ty;
    __pyx_t_8 = __pyx_v_tz;
    __pyx_t_9 = __pyx_v_tx;
    if (((__pyx_t_7 < __pyx_t_9) != 0)) {
      __pyx_t_10 = __pyx_t_7;
    } else {
      __pyx_t_10 = __pyx_t_9;
    }
    __pyx_t_9 = __pyx_t_10;
    if (((__pyx_t_8 < __pyx_t_9) != 0)) {
      __pyx_t_10 = __pyx_t_8;
    } else {
      __pyx_t_10 = __pyx_t_9;
    }
    __pyx_v_t = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":2639
 * 
 *             #intersection point
 *             ipx = (bx-ax)*t+ax             # <<<<<<<<<<<<<<
 *             ipy = (by-ay)*t+ay
 *             ipz = (bz-az)*t+az
 */
    __Pyx_TraceLine(2639,0,__PYX_ERR(0, 2639, __pyx_L1_error))
    __pyx_v_ipx = (((__pyx_v_bx - __pyx_v_ax) * __pyx_v_t) + __pyx_v_ax);

    /* "discretize/_extensions/tree_ext.pyx":2640
 *             #intersection point
 *             ipx = (bx-ax)*t+ax
 *             ipy = (by-ay)*t+ay             # <<<<<<<<<<<<<<
 *             ipz = (bz-az)*t+az
 * 
 */
    __Pyx_TraceLine(2640,0,__PYX_ERR(0, 2640, __pyx_L1_error))
    __pyx_v_ipy = (((__pyx_v_by - __pyx_v_ay) * __pyx_v_t) + __pyx_v_ay);

    /* "discretize/_extensions/tree_ext.pyx":2641
 *             ipx = (bx-ax)*t+ax
 *             ipy = (by-ay)*t+ay
 *             ipz = (bz-az)*t+az             # <<<<<<<<<<<<<<
 * 
 *             next_cell = cur_cell
 */
    __Pyx_TraceLine(2641,0,__PYX_ERR(0, 2641, __pyx_L1_error))
    __pyx_v_ipz = (((__pyx_v_bz - __pyx_v_az) * __pyx_v_t) + __pyx_v_az);

    /* "discretize/_extensions/tree_ext.pyx":2643
 *             ipz = (bz-az)*t+az
 * 
 *             next_cell = cur_cell             # <<<<<<<<<<<<<<
 *             if tx<=ty and tx<=tz:
 *                 # step in x direction
 */
    __Pyx_TraceLine(2643,0,__PYX_ERR(0, 2643, __pyx_L1_error))
    __pyx_v_next_cell = __pyx_v_cur_cell;

    /* "discretize/_extensions/tree_ext.pyx":2644
 * 
 *             next_cell = cur_cell
 *             if tx<=ty and tx<=tz:             # <<<<<<<<<<<<<<
 *                 # step in x direction
 *                 if ax>bx: # go -x
 */
    __Pyx_TraceLine(2644,0,__PYX_ERR(0, 2644, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_tx <= __pyx_v_ty) != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_5 = __pyx_t_11;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_11 = ((__pyx_v_tx <= __pyx_v_tz) != 0);
    __pyx_t_5 = __pyx_t_11;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2646
 *             if tx<=ty and tx<=tz:
 *                 # step in x direction
 *                 if ax>bx: # go -x             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[0]
 *                 else: # go +x
 */
      __Pyx_TraceLine(2646,0,__PYX_ERR(0, 2646, __pyx_L1_error))
      __pyx_t_5 = ((__pyx_v_ax > __pyx_v_bx) != 0);
      if (__pyx_t_5) {

        /* "discretize/_extensions/tree_ext.pyx":2647
 *                 # step in x direction
 *                 if ax>bx: # go -x
 *                     next_cell = next_cell.neighbors[0]             # <<<<<<<<<<<<<<
 *                 else: # go +x
 *                     next_cell = next_cell.neighbors[1]
 */
        __Pyx_TraceLine(2647,0,__PYX_ERR(0, 2647, __pyx_L1_error))
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[0]);

        /* "discretize/_extensions/tree_ext.pyx":2646
 *             if tx<=ty and tx<=tz:
 *                 # step in x direction
 *                 if ax>bx: # go -x             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[0]
 *                 else: # go +x
 */
        goto __pyx_L12;
      }

      /* "discretize/_extensions/tree_ext.pyx":2649
 *                     next_cell = next_cell.neighbors[0]
 *                 else: # go +x
 *                     next_cell = next_cell.neighbors[1]             # <<<<<<<<<<<<<<
 *             if ty<=tx and ty<=tz:
 *                 # step in y direction
 */
      __Pyx_TraceLine(2649,0,__PYX_ERR(0, 2649, __pyx_L1_error))
      /*else*/ {
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[1]);
      }
      __pyx_L12:;

      /* "discretize/_extensions/tree_ext.pyx":2644
 * 
 *             next_cell = cur_cell
 *             if tx<=ty and tx<=tz:             # <<<<<<<<<<<<<<
 *                 # step in x direction
 *                 if ax>bx: # go -x
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2650
 *                 else: # go +x
 *                     next_cell = next_cell.neighbors[1]
 *             if ty<=tx and ty<=tz:             # <<<<<<<<<<<<<<
 *                 # step in y direction
 *                 if ay>by: # go -y
 */
    __Pyx_TraceLine(2650,0,__PYX_ERR(0, 2650, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_ty <= __pyx_v_tx) != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_5 = __pyx_t_11;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_11 = ((__pyx_v_ty <= __pyx_v_tz) != 0);
    __pyx_t_5 = __pyx_t_11;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2652
 *             if ty<=tx and ty<=tz:
 *                 # step in y direction
 *                 if ay>by: # go -y             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[2]
 *                 else: # go +y
 */
      __Pyx_TraceLine(2652,0,__PYX_ERR(0, 2652, __pyx_L1_error))
      __pyx_t_5 = ((__pyx_v_ay > __pyx_v_by) != 0);
      if (__pyx_t_5) {

        /* "discretize/_extensions/tree_ext.pyx":2653
 *                 # step in y direction
 *                 if ay>by: # go -y
 *                     next_cell = next_cell.neighbors[2]             # <<<<<<<<<<<<<<
 *                 else: # go +y
 *                     next_cell = next_cell.neighbors[3]
 */
        __Pyx_TraceLine(2653,0,__PYX_ERR(0, 2653, __pyx_L1_error))
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[2]);

        /* "discretize/_extensions/tree_ext.pyx":2652
 *             if ty<=tx and ty<=tz:
 *                 # step in y direction
 *                 if ay>by: # go -y             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[2]
 *                 else: # go +y
 */
        goto __pyx_L16;
      }

      /* "discretize/_extensions/tree_ext.pyx":2655
 *                     next_cell = next_cell.neighbors[2]
 *                 else: # go +y
 *                     next_cell = next_cell.neighbors[3]             # <<<<<<<<<<<<<<
 *             if dim==3 and tz<=tx and tz<=ty:
 *                 # step in z direction
 */
      __Pyx_TraceLine(2655,0,__PYX_ERR(0, 2655, __pyx_L1_error))
      /*else*/ {
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[3]);
      }
      __pyx_L16:;

      /* "discretize/_extensions/tree_ext.pyx":2650
 *                 else: # go +x
 *                     next_cell = next_cell.neighbors[1]
 *             if ty<=tx and ty<=tz:             # <<<<<<<<<<<<<<
 *                 # step in y direction
 *                 if ay>by: # go -y
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2656
 *                 else: # go +y
 *                     next_cell = next_cell.neighbors[3]
 *             if dim==3 and tz<=tx and tz<=ty:             # <<<<<<<<<<<<<<
 *                 # step in z direction
 *                 if az>bz: # go -z
 */
    __Pyx_TraceLine(2656,0,__PYX_ERR(0, 2656, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_5 = __pyx_t_11;
      goto __pyx_L18_bool_binop_done;
    }
    __pyx_t_11 = ((__pyx_v_tz <= __pyx_v_tx) != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_5 = __pyx_t_11;
      goto __pyx_L18_bool_binop_done;
    }
    __pyx_t_11 = ((__pyx_v_tz <= __pyx_v_ty) != 0);
    __pyx_t_5 = __pyx_t_11;
    __pyx_L18_bool_binop_done:;
    if (__pyx_t_5) {

      /* "discretize/_extensions/tree_ext.pyx":2658
 *             if dim==3 and tz<=tx and tz<=ty:
 *                 # step in z direction
 *                 if az>bz: # go -z             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[4]
 *                 else: # go +z
 */
      __Pyx_TraceLine(2658,0,__PYX_ERR(0, 2658, __pyx_L1_error))
      __pyx_t_5 = ((__pyx_v_az > __pyx_v_bz) != 0);
      if (__pyx_t_5) {

        /* "discretize/_extensions/tree_ext.pyx":2659
 *                 # step in z direction
 *                 if az>bz: # go -z
 *                     next_cell = next_cell.neighbors[4]             # <<<<<<<<<<<<<<
 *                 else: # go +z
 *                     next_cell = next_cell.neighbors[5]
 */
        __Pyx_TraceLine(2659,0,__PYX_ERR(0, 2659, __pyx_L1_error))
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[4]);

        /* "discretize/_extensions/tree_ext.pyx":2658
 *             if dim==3 and tz<=tx and tz<=ty:
 *                 # step in z direction
 *                 if az>bz: # go -z             # <<<<<<<<<<<<<<
 *                     next_cell = next_cell.neighbors[4]
 *                 else: # go +z
 */
        goto __pyx_L21;
      }

      /* "discretize/_extensions/tree_ext.pyx":2661
 *                     next_cell = next_cell.neighbors[4]
 *                 else: # go +z
 *                     next_cell = next_cell.neighbors[5]             # <<<<<<<<<<<<<<
 * 
 *             # check if next_cell is not a leaf
 */
      __Pyx_TraceLine(2661,0,__PYX_ERR(0, 2661, __pyx_L1_error))
      /*else*/ {
        __pyx_v_next_cell = (__pyx_v_next_cell->neighbors[5]);
      }
      __pyx_L21:;

      /* "discretize/_extensions/tree_ext.pyx":2656
 *                 else: # go +y
 *                     next_cell = next_cell.neighbors[3]
 *             if dim==3 and tz<=tx and tz<=ty:             # <<<<<<<<<<<<<<
 *                 # step in z direction
 *                 if az>bz: # go -z
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2665
 *             # check if next_cell is not a leaf
 *             # (if so need to traverse down the children and find the closest leaf cell)
 *             while not next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 # should be able to use cp to check which cell to go to
 *                 cp = next_cell.children[0].points[last_point].location
 */
    __Pyx_TraceLine(2665,0,__PYX_ERR(0, 2665, __pyx_L1_error))
    while (1) {
      __pyx_t_5 = ((!(__pyx_v_next_cell->is_leaf() != 0)) != 0);
      if (!__pyx_t_5) break;

      /* "discretize/_extensions/tree_ext.pyx":2667
 *             while not next_cell.is_leaf():
 *                 # should be able to use cp to check which cell to go to
 *                 cp = next_cell.children[0].points[last_point].location             # <<<<<<<<<<<<<<
 *                 # this basically finds the child cell closest to the intersection point
 *                 ix = ipx>cp[0] or (ipx==cp[0] and ax<bx)
 */
      __Pyx_TraceLine(2667,0,__PYX_ERR(0, 2667, __pyx_L1_error))
      __pyx_t_6 = ((__pyx_v_next_cell->children[0])->points[__pyx_v_last_point])->location;
      __pyx_v_cp = __pyx_t_6;

      /* "discretize/_extensions/tree_ext.pyx":2669
 *                 cp = next_cell.children[0].points[last_point].location
 *                 # this basically finds the child cell closest to the intersection point
 *                 ix = ipx>cp[0] or (ipx==cp[0] and ax<bx)             # <<<<<<<<<<<<<<
 *                 iy = ipy>cp[1] or (ipy==cp[1] and ay<by)
 *                 iz = dim==3 and (ipz>cp[2] or  (ipz==cp[2] and az<bz))
 */
      __Pyx_TraceLine(2669,0,__PYX_ERR(0, 2669, __pyx_L1_error))
      __pyx_t_5 = (__pyx_v_ipx > (__pyx_v_cp[0]));
      if (!__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L24_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ipx == (__pyx_v_cp[0]));
      if (__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L24_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ax < __pyx_v_bx);
      __pyx_t_2 = __pyx_t_5;
      __pyx_L24_bool_binop_done:;
      __pyx_v_ix = __pyx_t_2;

      /* "discretize/_extensions/tree_ext.pyx":2670
 *                 # this basically finds the child cell closest to the intersection point
 *                 ix = ipx>cp[0] or (ipx==cp[0] and ax<bx)
 *                 iy = ipy>cp[1] or (ipy==cp[1] and ay<by)             # <<<<<<<<<<<<<<
 *                 iz = dim==3 and (ipz>cp[2] or  (ipz==cp[2] and az<bz))
 *                 next_cell = next_cell.children[ix + 2*iy + 4*iz]
 */
      __Pyx_TraceLine(2670,0,__PYX_ERR(0, 2670, __pyx_L1_error))
      __pyx_t_5 = (__pyx_v_ipy > (__pyx_v_cp[1]));
      if (!__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L27_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ipy == (__pyx_v_cp[1]));
      if (__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L27_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ay < __pyx_v_by);
      __pyx_t_2 = __pyx_t_5;
      __pyx_L27_bool_binop_done:;
      __pyx_v_iy = __pyx_t_2;

      /* "discretize/_extensions/tree_ext.pyx":2671
 *                 ix = ipx>cp[0] or (ipx==cp[0] and ax<bx)
 *                 iy = ipy>cp[1] or (ipy==cp[1] and ay<by)
 *                 iz = dim==3 and (ipz>cp[2] or  (ipz==cp[2] and az<bz))             # <<<<<<<<<<<<<<
 *                 next_cell = next_cell.children[ix + 2*iy + 4*iz]
 * 
 */
      __Pyx_TraceLine(2671,0,__PYX_ERR(0, 2671, __pyx_L1_error))
      __pyx_t_5 = (__pyx_v_dim == 3);
      if (__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ipz > (__pyx_v_cp[2]));
      if (!__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_ipz == (__pyx_v_cp[2]));
      if (__pyx_t_5) {
      } else {
        __pyx_t_2 = __pyx_t_5;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_az < __pyx_v_bz);
      __pyx_t_2 = __pyx_t_5;
      __pyx_L30_bool_binop_done:;
      __pyx_v_iz = __pyx_t_2;

      /* "discretize/_extensions/tree_ext.pyx":2672
 *                 iy = ipy>cp[1] or (ipy==cp[1] and ay<by)
 *                 iz = dim==3 and (ipz>cp[2] or  (ipz==cp[2] and az<bz))
 *                 next_cell = next_cell.children[ix + 2*iy + 4*iz]             # <<<<<<<<<<<<<<
 * 
 *             #this now should have stepped appropriately across diagonals and such
 */
      __Pyx_TraceLine(2672,0,__PYX_ERR(0, 2672, __pyx_L1_error))
      __pyx_v_next_cell = (__pyx_v_next_cell->children[((__pyx_v_ix + (2 * __pyx_v_iy)) + (4 * __pyx_v_iz))]);
    }

    /* "discretize/_extensions/tree_ext.pyx":2676
 *             #this now should have stepped appropriately across diagonals and such
 * 
 *             cur_cell = next_cell             # <<<<<<<<<<<<<<
 *             cell_indexes.push_back(cur_cell.index)
 *             if cur_cell.index == -1:
 */
    __Pyx_TraceLine(2676,0,__PYX_ERR(0, 2676, __pyx_L1_error))
    __pyx_v_cur_cell = __pyx_v_next_cell;

    /* "discretize/_extensions/tree_ext.pyx":2677
 * 
 *             cur_cell = next_cell
 *             cell_indexes.push_back(cur_cell.index)             # <<<<<<<<<<<<<<
 *             if cur_cell.index == -1:
 *                 raise Exception('Path not found')
 */
    __Pyx_TraceLine(2677,0,__PYX_ERR(0, 2677, __pyx_L1_error))
    try {
      __pyx_v_cell_indexes.push_back(__pyx_v_cur_cell->index);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(0, 2677, __pyx_L1_error)
    }

    /* "discretize/_extensions/tree_ext.pyx":2678
 *             cur_cell = next_cell
 *             cell_indexes.push_back(cur_cell.index)
 *             if cur_cell.index == -1:             # <<<<<<<<<<<<<<
 *                 raise Exception('Path not found')
 *         return cell_indexes
 */
    __Pyx_TraceLine(2678,0,__PYX_ERR(0, 2678, __pyx_L1_error))
    __pyx_t_5 = ((__pyx_v_cur_cell->index == -1LL) != 0);
    if (unlikely(__pyx_t_5)) {

      /* "discretize/_extensions/tree_ext.pyx":2679
 *             cell_indexes.push_back(cur_cell.index)
 *             if cur_cell.index == -1:
 *                 raise Exception('Path not found')             # <<<<<<<<<<<<<<
 *         return cell_indexes
 * 
 */
      __Pyx_TraceLine(2679,0,__PYX_ERR(0, 2679, __pyx_L1_error))
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2679, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 2679, __pyx_L1_error)

      /* "discretize/_extensions/tree_ext.pyx":2678
 *             cur_cell = next_cell
 *             cell_indexes.push_back(cur_cell.index)
 *             if cur_cell.index == -1:             # <<<<<<<<<<<<<<
 *                 raise Exception('Path not found')
 *         return cell_indexes
 */
    }
  }

  /* "discretize/_extensions/tree_ext.pyx":2680
 *             if cur_cell.index == -1:
 *                 raise Exception('Path not found')
 *         return cell_indexes             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2680,0,__PYX_ERR(0, 2680, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_convert_vector_to_py_PY_LONG_LONG(__pyx_v_cell_indexes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2680, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2567
 * 
 *     @cython.cdivision(True)
 *     def get_cells_along_line(self, x0, x1):             # <<<<<<<<<<<<<<
 *         """Find the cells along a line segment defined by two points.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.get_cells_along_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2683
 * 
 *     @property
 *     def face_divergence(self):             # <<<<<<<<<<<<<<
 *         r"""Face divergence operator (faces to cell-centres).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_D = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2683, 0, __PYX_ERR(0, 2683, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2729
 *         represents the outward normal vector of face *k* for cell *i*.
 *         """
 *         if self._face_divergence is not None:             # <<<<<<<<<<<<<<
 *             return self._face_divergence
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(2729,0,__PYX_ERR(0, 2729, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_face_divergence != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2730
 *         """
 *         if self._face_divergence is not None:
 *             return self._face_divergence             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             D = self._face_divergence_2D() # Because it uses edges instead of faces
 */
    __Pyx_TraceLine(2730,0,__PYX_ERR(0, 2730, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_face_divergence);
    __pyx_r = __pyx_v_self->_face_divergence;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2729
 *         represents the outward normal vector of face *k* for cell *i*.
 *         """
 *         if self._face_divergence is not None:             # <<<<<<<<<<<<<<
 *             return self._face_divergence
 *         if self._dim == 2:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2731
 *         if self._face_divergence is not None:
 *             return self._face_divergence
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             D = self._face_divergence_2D() # Because it uses edges instead of faces
 *         else:
 */
  __Pyx_TraceLine(2731,0,__PYX_ERR(0, 2731, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2732
 *             return self._face_divergence
 *         if self._dim == 2:
 *             D = self._face_divergence_2D() # Because it uses edges instead of faces             # <<<<<<<<<<<<<<
 *         else:
 *             D = self._face_divergence_3D()
 */
    __Pyx_TraceLine(2732,0,__PYX_ERR(0, 2732, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_face_divergence_2D); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2732, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2732, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_D = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":2731
 *         if self._face_divergence is not None:
 *             return self._face_divergence
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             D = self._face_divergence_2D() # Because it uses edges instead of faces
 *         else:
 */
    goto __pyx_L4;
  }

  /* "discretize/_extensions/tree_ext.pyx":2734
 *             D = self._face_divergence_2D() # Because it uses edges instead of faces
 *         else:
 *             D = self._face_divergence_3D()             # <<<<<<<<<<<<<<
 *         R = self._deflate_faces()
 *         self._face_divergence = D*R
 */
  __Pyx_TraceLine(2734,0,__PYX_ERR(0, 2734, __pyx_L1_error))
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_face_divergence_3D); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2734, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2734, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_D = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L4:;

  /* "discretize/_extensions/tree_ext.pyx":2735
 *         else:
 *             D = self._face_divergence_3D()
 *         R = self._deflate_faces()             # <<<<<<<<<<<<<<
 *         self._face_divergence = D*R
 *         return self._face_divergence
 */
  __Pyx_TraceLine(2735,0,__PYX_ERR(0, 2735, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2735, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2735, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_R = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2736
 *             D = self._face_divergence_3D()
 *         R = self._deflate_faces()
 *         self._face_divergence = D*R             # <<<<<<<<<<<<<<
 *         return self._face_divergence
 * 
 */
  __Pyx_TraceLine(2736,0,__PYX_ERR(0, 2736, __pyx_L1_error))
  __pyx_t_3 = PyNumber_Multiply(__pyx_v_D, __pyx_v_R); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2736, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->_face_divergence);
  __Pyx_DECREF(__pyx_v_self->_face_divergence);
  __pyx_v_self->_face_divergence = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2737
 *         R = self._deflate_faces()
 *         self._face_divergence = D*R
 *         return self._face_divergence             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
  __Pyx_TraceLine(2737,0,__PYX_ERR(0, 2737, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_face_divergence);
  __pyx_r = __pyx_v_self->_face_divergence;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2683
 * 
 *     @property
 *     def face_divergence(self):             # <<<<<<<<<<<<<<
 *         r"""Face divergence operator (faces to cell-centres).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.face_divergence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_D);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2741
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def _face_divergence_2D(self):             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_cells*4, dtype=np.int64)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_33_face_divergence_2D(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_32_face_divergence_2D[] = "_TreeMesh._face_divergence_2D(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_33_face_divergence_2D(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_face_divergence_2D (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_32_face_divergence_2D(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_32_face_divergence_2D(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_i;
  Edge *__pyx_v_edges[4];
  __pyx_t_5numpy_int64_t __pyx_v_offset;
  double __pyx_v_volume;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_8;
  std::vector<Cell *>  *__pyx_t_9;
  Cell *__pyx_t_10;
  Edge **__pyx_t_11;
  PY_LONG_LONG __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  int_t __pyx_t_15;
  double __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_face_divergence_2D", 0);
  __Pyx_TraceCall("_face_divergence_2D", __pyx_f[0], 2741, 0, __PYX_ERR(0, 2741, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2742
 *     @cython.boundscheck(False)
 *     def _face_divergence_2D(self):
 *         cdef np.int64_t[:] I = np.empty(self.n_cells*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_cells*4, dtype=np.float64)
 */
  __Pyx_TraceLine(2742,0,__PYX_ERR(0, 2742, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2742, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2743
 *     def _face_divergence_2D(self):
 *         cdef np.int64_t[:] I = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_cells*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(self.n_cells*4, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(2743,0,__PYX_ERR(0, 2743, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_int_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2743, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2744
 *         cdef np.int64_t[:] I = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_cells*4, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t i = 0
 */
  __Pyx_TraceLine(2744,0,__PYX_ERR(0, 2744, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_int_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 2744, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2746
 *         cdef np.float64_t[:] V = np.empty(self.n_cells*4, dtype=np.float64)
 * 
 *         cdef np.int64_t i = 0             # <<<<<<<<<<<<<<
 *         cdef Edge *edges[4]
 *         cdef np.int64_t offset = self.tree.edges_y.size()
 */
  __Pyx_TraceLine(2746,0,__PYX_ERR(0, 2746, __pyx_L1_error))
  __pyx_v_i = 0;

  /* "discretize/_extensions/tree_ext.pyx":2748
 *         cdef np.int64_t i = 0
 *         cdef Edge *edges[4]
 *         cdef np.int64_t offset = self.tree.edges_y.size()             # <<<<<<<<<<<<<<
 *         cdef double volume
 * 
 */
  __Pyx_TraceLine(2748,0,__PYX_ERR(0, 2748, __pyx_L1_error))
  __pyx_v_offset = __pyx_v_self->tree->edges_y.size();

  /* "discretize/_extensions/tree_ext.pyx":2751
 *         cdef double volume
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             edges = cell.edges
 *             i = cell.index
 */
  __Pyx_TraceLine(2751,0,__PYX_ERR(0, 2751, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->cells;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_cell = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":2752
 * 
 *         for cell in self.tree.cells:
 *             edges = cell.edges             # <<<<<<<<<<<<<<
 *             i = cell.index
 *             I[i*4 : i*4 + 4] = i
 */
    __Pyx_TraceLine(2752,0,__PYX_ERR(0, 2752, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_cell->edges;
    memcpy(&(__pyx_v_edges[0]), __pyx_t_11, sizeof(__pyx_v_edges[0]) * (4 - 0));

    /* "discretize/_extensions/tree_ext.pyx":2753
 *         for cell in self.tree.cells:
 *             edges = cell.edges
 *             i = cell.index             # <<<<<<<<<<<<<<
 *             I[i*4 : i*4 + 4] = i
 *             J[i*4    ] = edges[0].index + offset #x edge, y face (add offset)
 */
    __Pyx_TraceLine(2753,0,__PYX_ERR(0, 2753, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_cell->index;
    __pyx_v_i = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":2754
 *             edges = cell.edges
 *             i = cell.index
 *             I[i*4 : i*4 + 4] = i             # <<<<<<<<<<<<<<
 *             J[i*4    ] = edges[0].index + offset #x edge, y face (add offset)
 *             J[i*4 + 1] = edges[1].index + offset #x edge, y face (add offset)
 */
    __Pyx_TraceLine(2754,0,__PYX_ERR(0, 2754, __pyx_L1_error))
    __pyx_t_6.data = __pyx_v_I.data;
    __pyx_t_6.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_6, 0);
    __pyx_t_13 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_6,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_13,
    (__pyx_v_i * 4),
    ((__pyx_v_i * 4) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2754, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_i;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_6.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_6.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_6.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2755
 *             i = cell.index
 *             I[i*4 : i*4 + 4] = i
 *             J[i*4    ] = edges[0].index + offset #x edge, y face (add offset)             # <<<<<<<<<<<<<<
 *             J[i*4 + 1] = edges[1].index + offset #x edge, y face (add offset)
 *             J[i*4 + 2] = edges[2].index #y edge, x face
 */
    __Pyx_TraceLine(2755,0,__PYX_ERR(0, 2755, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_i * 4);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = ((__pyx_v_edges[0])->index + __pyx_v_offset);

    /* "discretize/_extensions/tree_ext.pyx":2756
 *             I[i*4 : i*4 + 4] = i
 *             J[i*4    ] = edges[0].index + offset #x edge, y face (add offset)
 *             J[i*4 + 1] = edges[1].index + offset #x edge, y face (add offset)             # <<<<<<<<<<<<<<
 *             J[i*4 + 2] = edges[2].index #y edge, x face
 *             J[i*4 + 3] = edges[3].index #y edge, x face
 */
    __Pyx_TraceLine(2756,0,__PYX_ERR(0, 2756, __pyx_L1_error))
    __pyx_t_14 = ((__pyx_v_i * 4) + 1);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = ((__pyx_v_edges[1])->index + __pyx_v_offset);

    /* "discretize/_extensions/tree_ext.pyx":2757
 *             J[i*4    ] = edges[0].index + offset #x edge, y face (add offset)
 *             J[i*4 + 1] = edges[1].index + offset #x edge, y face (add offset)
 *             J[i*4 + 2] = edges[2].index #y edge, x face             # <<<<<<<<<<<<<<
 *             J[i*4 + 3] = edges[3].index #y edge, x face
 * 
 */
    __Pyx_TraceLine(2757,0,__PYX_ERR(0, 2757, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_edges[2])->index;
    __pyx_t_14 = ((__pyx_v_i * 4) + 2);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":2758
 *             J[i*4 + 1] = edges[1].index + offset #x edge, y face (add offset)
 *             J[i*4 + 2] = edges[2].index #y edge, x face
 *             J[i*4 + 3] = edges[3].index #y edge, x face             # <<<<<<<<<<<<<<
 * 
 *             volume = cell.volume
 */
    __Pyx_TraceLine(2758,0,__PYX_ERR(0, 2758, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_edges[3])->index;
    __pyx_t_14 = ((__pyx_v_i * 4) + 3);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":2760
 *             J[i*4 + 3] = edges[3].index #y edge, x face
 * 
 *             volume = cell.volume             # <<<<<<<<<<<<<<
 *             V[i*4    ] = -edges[0].length/volume
 *             V[i*4 + 1] =  edges[1].length/volume
 */
    __Pyx_TraceLine(2760,0,__PYX_ERR(0, 2760, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_cell->volume;
    __pyx_v_volume = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2761
 * 
 *             volume = cell.volume
 *             V[i*4    ] = -edges[0].length/volume             # <<<<<<<<<<<<<<
 *             V[i*4 + 1] =  edges[1].length/volume
 *             V[i*4 + 2] = -edges[2].length/volume
 */
    __Pyx_TraceLine(2761,0,__PYX_ERR(0, 2761, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_i * 4);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_edges[0])->length) / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2762
 *             volume = cell.volume
 *             V[i*4    ] = -edges[0].length/volume
 *             V[i*4 + 1] =  edges[1].length/volume             # <<<<<<<<<<<<<<
 *             V[i*4 + 2] = -edges[2].length/volume
 *             V[i*4 + 3] =  edges[3].length/volume
 */
    __Pyx_TraceLine(2762,0,__PYX_ERR(0, 2762, __pyx_L1_error))
    __pyx_t_14 = ((__pyx_v_i * 4) + 1);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = ((__pyx_v_edges[1])->length / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2763
 *             V[i*4    ] = -edges[0].length/volume
 *             V[i*4 + 1] =  edges[1].length/volume
 *             V[i*4 + 2] = -edges[2].length/volume             # <<<<<<<<<<<<<<
 *             V[i*4 + 3] =  edges[3].length/volume
 *         return sp.csr_matrix((V, (I, J)))
 */
    __Pyx_TraceLine(2763,0,__PYX_ERR(0, 2763, __pyx_L1_error))
    __pyx_t_14 = ((__pyx_v_i * 4) + 2);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_edges[2])->length) / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2764
 *             V[i*4 + 1] =  edges[1].length/volume
 *             V[i*4 + 2] = -edges[2].length/volume
 *             V[i*4 + 3] =  edges[3].length/volume             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)))
 * 
 */
    __Pyx_TraceLine(2764,0,__PYX_ERR(0, 2764, __pyx_L1_error))
    __pyx_t_14 = ((__pyx_v_i * 4) + 3);
    if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = ((__pyx_v_edges[3])->length / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2751
 *         cdef double volume
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             edges = cell.edges
 *             i = cell.index
 */
    __Pyx_TraceLine(2751,0,__PYX_ERR(0, 2751, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":2765
 *             V[i*4 + 2] = -edges[2].length/volume
 *             V[i*4 + 3] =  edges[3].length/volume
 *         return sp.csr_matrix((V, (I, J)))             # <<<<<<<<<<<<<<
 * 
 *     @cython.cdivision(True)
 */
  __Pyx_TraceLine(2765,0,__PYX_ERR(0, 2765, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_17);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_17);
  __pyx_t_5 = 0;
  __pyx_t_17 = 0;
  __pyx_t_17 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_17)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_17, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2741
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def _face_divergence_2D(self):             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.empty(self.n_cells*4, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_cells*4, dtype=np.int64)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._face_divergence_2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2769
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def _face_divergence_3D(self):             # <<<<<<<<<<<<<<
 *         cdef:
 *             np.int64_t[:] I = np.empty(self.n_cells*6, dtype=np.int64)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_35_face_divergence_3D(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_34_face_divergence_3D[] = "_TreeMesh._face_divergence_3D(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_35_face_divergence_3D(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_face_divergence_3D (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_34_face_divergence_3D(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_34_face_divergence_3D(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_i;
  Face *__pyx_v_faces[6];
  __pyx_t_5numpy_int64_t __pyx_v_offset1;
  __pyx_t_5numpy_int64_t __pyx_v_offset2;
  double __pyx_v_volume;
  double __pyx_v_fx_area;
  double __pyx_v_fy_area;
  double __pyx_v_fz_area;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_8;
  std::vector<Cell *>  *__pyx_t_9;
  Cell *__pyx_t_10;
  Face **__pyx_t_11;
  PY_LONG_LONG __pyx_t_12;
  int __pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  double __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_face_divergence_3D", 0);
  __Pyx_TraceCall("_face_divergence_3D", __pyx_f[0], 2769, 0, __PYX_ERR(0, 2769, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2771
 *     def _face_divergence_3D(self):
 *         cdef:
 *             np.int64_t[:] I = np.empty(self.n_cells*6, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] J = np.empty(self.n_cells*6, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(self.n_cells*6, dtype=np.float64)
 */
  __Pyx_TraceLine(2771,0,__PYX_ERR(0, 2771, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_int_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2772
 *         cdef:
 *             np.int64_t[:] I = np.empty(self.n_cells*6, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(self.n_cells*6, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] V = np.empty(self.n_cells*6, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(2772,0,__PYX_ERR(0, 2772, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_int_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 2772, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2773
 *             np.int64_t[:] I = np.empty(self.n_cells*6, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(self.n_cells*6, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(self.n_cells*6, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             np.int64_t i = 0
 */
  __Pyx_TraceLine(2773,0,__PYX_ERR(0, 2773, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_int_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 2773, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2775
 *             np.float64_t[:] V = np.empty(self.n_cells*6, dtype=np.float64)
 * 
 *             np.int64_t i = 0             # <<<<<<<<<<<<<<
 *             Face *faces[6]
 *             np.int64_t offset1 = self.tree.faces_x.size()
 */
  __Pyx_TraceLine(2775,0,__PYX_ERR(0, 2775, __pyx_L1_error))
  __pyx_v_i = 0;

  /* "discretize/_extensions/tree_ext.pyx":2777
 *             np.int64_t i = 0
 *             Face *faces[6]
 *             np.int64_t offset1 = self.tree.faces_x.size()             # <<<<<<<<<<<<<<
 *             np.int64_t offset2 = offset1 + self.tree.faces_y.size()
 *             double volume, fx_area, fy_area, fz_area
 */
  __Pyx_TraceLine(2777,0,__PYX_ERR(0, 2777, __pyx_L1_error))
  __pyx_v_offset1 = __pyx_v_self->tree->faces_x.size();

  /* "discretize/_extensions/tree_ext.pyx":2778
 *             Face *faces[6]
 *             np.int64_t offset1 = self.tree.faces_x.size()
 *             np.int64_t offset2 = offset1 + self.tree.faces_y.size()             # <<<<<<<<<<<<<<
 *             double volume, fx_area, fy_area, fz_area
 * 
 */
  __Pyx_TraceLine(2778,0,__PYX_ERR(0, 2778, __pyx_L1_error))
  __pyx_v_offset2 = (__pyx_v_offset1 + __pyx_v_self->tree->faces_y.size());

  /* "discretize/_extensions/tree_ext.pyx":2781
 *             double volume, fx_area, fy_area, fz_area
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             faces = cell.faces
 *             i = cell.index
 */
  __Pyx_TraceLine(2781,0,__PYX_ERR(0, 2781, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->cells;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_cell = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":2782
 * 
 *         for cell in self.tree.cells:
 *             faces = cell.faces             # <<<<<<<<<<<<<<
 *             i = cell.index
 *             I[i*6 : i*6 + 6] = i
 */
    __Pyx_TraceLine(2782,0,__PYX_ERR(0, 2782, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_cell->faces;
    memcpy(&(__pyx_v_faces[0]), __pyx_t_11, sizeof(__pyx_v_faces[0]) * (6 - 0));

    /* "discretize/_extensions/tree_ext.pyx":2783
 *         for cell in self.tree.cells:
 *             faces = cell.faces
 *             i = cell.index             # <<<<<<<<<<<<<<
 *             I[i*6 : i*6 + 6] = i
 *             J[i*6    ] = faces[0].index #x1 face
 */
    __Pyx_TraceLine(2783,0,__PYX_ERR(0, 2783, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_cell->index;
    __pyx_v_i = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":2784
 *             faces = cell.faces
 *             i = cell.index
 *             I[i*6 : i*6 + 6] = i             # <<<<<<<<<<<<<<
 *             J[i*6    ] = faces[0].index #x1 face
 *             J[i*6 + 1] = faces[1].index #x2 face
 */
    __Pyx_TraceLine(2784,0,__PYX_ERR(0, 2784, __pyx_L1_error))
    __pyx_t_6.data = __pyx_v_I.data;
    __pyx_t_6.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_6, 0);
    __pyx_t_13 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_6,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_13,
    (__pyx_v_i * 6),
    ((__pyx_v_i * 6) + 6),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2784, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_i;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_6.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_6.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_6.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2785
 *             i = cell.index
 *             I[i*6 : i*6 + 6] = i
 *             J[i*6    ] = faces[0].index #x1 face             # <<<<<<<<<<<<<<
 *             J[i*6 + 1] = faces[1].index #x2 face
 *             J[i*6 + 2] = faces[2].index + offset1 #y face (add offset1)
 */
    __Pyx_TraceLine(2785,0,__PYX_ERR(0, 2785, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_faces[0])->index;
    __pyx_t_15 = (__pyx_v_i * 6);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":2786
 *             I[i*6 : i*6 + 6] = i
 *             J[i*6    ] = faces[0].index #x1 face
 *             J[i*6 + 1] = faces[1].index #x2 face             # <<<<<<<<<<<<<<
 *             J[i*6 + 2] = faces[2].index + offset1 #y face (add offset1)
 *             J[i*6 + 3] = faces[3].index + offset1 #y face (add offset1)
 */
    __Pyx_TraceLine(2786,0,__PYX_ERR(0, 2786, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_faces[1])->index;
    __pyx_t_15 = ((__pyx_v_i * 6) + 1);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":2787
 *             J[i*6    ] = faces[0].index #x1 face
 *             J[i*6 + 1] = faces[1].index #x2 face
 *             J[i*6 + 2] = faces[2].index + offset1 #y face (add offset1)             # <<<<<<<<<<<<<<
 *             J[i*6 + 3] = faces[3].index + offset1 #y face (add offset1)
 *             J[i*6 + 4] = faces[4].index + offset2 #z face (add offset2)
 */
    __Pyx_TraceLine(2787,0,__PYX_ERR(0, 2787, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 2);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = ((__pyx_v_faces[2])->index + __pyx_v_offset1);

    /* "discretize/_extensions/tree_ext.pyx":2788
 *             J[i*6 + 1] = faces[1].index #x2 face
 *             J[i*6 + 2] = faces[2].index + offset1 #y face (add offset1)
 *             J[i*6 + 3] = faces[3].index + offset1 #y face (add offset1)             # <<<<<<<<<<<<<<
 *             J[i*6 + 4] = faces[4].index + offset2 #z face (add offset2)
 *             J[i*6 + 5] = faces[5].index + offset2 #z face (add offset2)
 */
    __Pyx_TraceLine(2788,0,__PYX_ERR(0, 2788, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 3);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = ((__pyx_v_faces[3])->index + __pyx_v_offset1);

    /* "discretize/_extensions/tree_ext.pyx":2789
 *             J[i*6 + 2] = faces[2].index + offset1 #y face (add offset1)
 *             J[i*6 + 3] = faces[3].index + offset1 #y face (add offset1)
 *             J[i*6 + 4] = faces[4].index + offset2 #z face (add offset2)             # <<<<<<<<<<<<<<
 *             J[i*6 + 5] = faces[5].index + offset2 #z face (add offset2)
 * 
 */
    __Pyx_TraceLine(2789,0,__PYX_ERR(0, 2789, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 4);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = ((__pyx_v_faces[4])->index + __pyx_v_offset2);

    /* "discretize/_extensions/tree_ext.pyx":2790
 *             J[i*6 + 3] = faces[3].index + offset1 #y face (add offset1)
 *             J[i*6 + 4] = faces[4].index + offset2 #z face (add offset2)
 *             J[i*6 + 5] = faces[5].index + offset2 #z face (add offset2)             # <<<<<<<<<<<<<<
 * 
 *             volume = cell.volume
 */
    __Pyx_TraceLine(2790,0,__PYX_ERR(0, 2790, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 5);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = ((__pyx_v_faces[5])->index + __pyx_v_offset2);

    /* "discretize/_extensions/tree_ext.pyx":2792
 *             J[i*6 + 5] = faces[5].index + offset2 #z face (add offset2)
 * 
 *             volume = cell.volume             # <<<<<<<<<<<<<<
 *             fx_area = faces[0].area
 *             fy_area = faces[2].area
 */
    __Pyx_TraceLine(2792,0,__PYX_ERR(0, 2792, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_cell->volume;
    __pyx_v_volume = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2793
 * 
 *             volume = cell.volume
 *             fx_area = faces[0].area             # <<<<<<<<<<<<<<
 *             fy_area = faces[2].area
 *             fz_area = faces[4].area
 */
    __Pyx_TraceLine(2793,0,__PYX_ERR(0, 2793, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_faces[0])->area;
    __pyx_v_fx_area = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2794
 *             volume = cell.volume
 *             fx_area = faces[0].area
 *             fy_area = faces[2].area             # <<<<<<<<<<<<<<
 *             fz_area = faces[4].area
 *             V[i*6    ] = -fx_area/volume
 */
    __Pyx_TraceLine(2794,0,__PYX_ERR(0, 2794, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_faces[2])->area;
    __pyx_v_fy_area = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2795
 *             fx_area = faces[0].area
 *             fy_area = faces[2].area
 *             fz_area = faces[4].area             # <<<<<<<<<<<<<<
 *             V[i*6    ] = -fx_area/volume
 *             V[i*6 + 1] =  fx_area/volume
 */
    __Pyx_TraceLine(2795,0,__PYX_ERR(0, 2795, __pyx_L1_error))
    __pyx_t_16 = (__pyx_v_faces[4])->area;
    __pyx_v_fz_area = __pyx_t_16;

    /* "discretize/_extensions/tree_ext.pyx":2796
 *             fy_area = faces[2].area
 *             fz_area = faces[4].area
 *             V[i*6    ] = -fx_area/volume             # <<<<<<<<<<<<<<
 *             V[i*6 + 1] =  fx_area/volume
 *             V[i*6 + 2] = -fy_area/volume
 */
    __Pyx_TraceLine(2796,0,__PYX_ERR(0, 2796, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_i * 6);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((-__pyx_v_fx_area) / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2797
 *             fz_area = faces[4].area
 *             V[i*6    ] = -fx_area/volume
 *             V[i*6 + 1] =  fx_area/volume             # <<<<<<<<<<<<<<
 *             V[i*6 + 2] = -fy_area/volume
 *             V[i*6 + 3] =  fy_area/volume
 */
    __Pyx_TraceLine(2797,0,__PYX_ERR(0, 2797, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 1);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (__pyx_v_fx_area / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2798
 *             V[i*6    ] = -fx_area/volume
 *             V[i*6 + 1] =  fx_area/volume
 *             V[i*6 + 2] = -fy_area/volume             # <<<<<<<<<<<<<<
 *             V[i*6 + 3] =  fy_area/volume
 *             V[i*6 + 4] = -fz_area/volume
 */
    __Pyx_TraceLine(2798,0,__PYX_ERR(0, 2798, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 2);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((-__pyx_v_fy_area) / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2799
 *             V[i*6 + 1] =  fx_area/volume
 *             V[i*6 + 2] = -fy_area/volume
 *             V[i*6 + 3] =  fy_area/volume             # <<<<<<<<<<<<<<
 *             V[i*6 + 4] = -fz_area/volume
 *             V[i*6 + 5] =  fz_area/volume
 */
    __Pyx_TraceLine(2799,0,__PYX_ERR(0, 2799, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 3);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (__pyx_v_fy_area / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2800
 *             V[i*6 + 2] = -fy_area/volume
 *             V[i*6 + 3] =  fy_area/volume
 *             V[i*6 + 4] = -fz_area/volume             # <<<<<<<<<<<<<<
 *             V[i*6 + 5] =  fz_area/volume
 *         return sp.csr_matrix((V, (I, J)))
 */
    __Pyx_TraceLine(2800,0,__PYX_ERR(0, 2800, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 4);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((-__pyx_v_fz_area) / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2801
 *             V[i*6 + 3] =  fy_area/volume
 *             V[i*6 + 4] = -fz_area/volume
 *             V[i*6 + 5] =  fz_area/volume             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)))
 * 
 */
    __Pyx_TraceLine(2801,0,__PYX_ERR(0, 2801, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_i * 6) + 5);
    if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (__pyx_v_fz_area / __pyx_v_volume);

    /* "discretize/_extensions/tree_ext.pyx":2781
 *             double volume, fx_area, fy_area, fz_area
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             faces = cell.faces
 *             i = cell.index
 */
    __Pyx_TraceLine(2781,0,__PYX_ERR(0, 2781, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":2802
 *             V[i*6 + 4] = -fz_area/volume
 *             V[i*6 + 5] =  fz_area/volume
 *         return sp.csr_matrix((V, (I, J)))             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2802,0,__PYX_ERR(0, 2802, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_17);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_17);
  __pyx_t_5 = 0;
  __pyx_t_17 = 0;
  __pyx_t_17 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_17)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_17, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2769
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def _face_divergence_3D(self):             # <<<<<<<<<<<<<<
 *         cdef:
 *             np.int64_t[:] I = np.empty(self.n_cells*6, dtype=np.int64)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._face_divergence_3D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2807
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def edge_curl(self):             # <<<<<<<<<<<<<<
 *         r"""Edge curl operator (edges to faces)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int_t __pyx_v_dim;
  int_t __pyx_v_n_faces;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  int_t __pyx_v_ii;
  int_t __pyx_v_face_offset_y;
  int_t __pyx_v_face_offset_z;
  int_t __pyx_v_edge_offset_y;
  int_t __pyx_v_edge_offset_z;
  double __pyx_v_area;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_v_C = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_11 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_12;
  face_map_t *__pyx_t_13;
  std::pair<int_t,Face *>  __pyx_t_14;
  Face *__pyx_t_15;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  double __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2807, 0, __PYX_ERR(0, 2807, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2856
 *         and \vec{\ell}_k is the path along edge *k*.
 *         """
 *         if self._edge_curl is not None:             # <<<<<<<<<<<<<<
 *             return self._edge_curl
 *         cdef:
 */
  __Pyx_TraceLine(2856,0,__PYX_ERR(0, 2856, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_edge_curl != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2857
 *         """
 *         if self._edge_curl is not None:
 *             return self._edge_curl             # <<<<<<<<<<<<<<
 *         cdef:
 *             int_t dim = self._dim
 */
    __Pyx_TraceLine(2857,0,__PYX_ERR(0, 2857, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_edge_curl);
    __pyx_r = __pyx_v_self->_edge_curl;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2856
 *         and \vec{\ell}_k is the path along edge *k*.
 *         """
 *         if self._edge_curl is not None:             # <<<<<<<<<<<<<<
 *             return self._edge_curl
 *         cdef:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2859
 *             return self._edge_curl
 *         cdef:
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             int_t n_faces = self.n_faces if dim==3 else self.n_cells
 *             np.int64_t[:] I = np.empty(4*n_faces, dtype=np.int64)
 */
  __Pyx_TraceLine(2859,0,__PYX_ERR(0, 2859, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2860
 *         cdef:
 *             int_t dim = self._dim
 *             int_t n_faces = self.n_faces if dim==3 else self.n_cells             # <<<<<<<<<<<<<<
 *             np.int64_t[:] I = np.empty(4*n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*n_faces, dtype=np.int64)
 */
  __Pyx_TraceLine(2860,0,__PYX_ERR(0, 2860, __pyx_L1_error))
  if (((__pyx_v_dim == 3) != 0)) {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_As_int_t(__pyx_t_4); if (unlikely((__pyx_t_5 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2860, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_As_int_t(__pyx_t_4); if (unlikely((__pyx_t_5 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2860, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __pyx_t_5;
  }
  __pyx_v_n_faces = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2861
 *             int_t dim = self._dim
 *             int_t n_faces = self.n_faces if dim==3 else self.n_cells
 *             np.int64_t[:] I = np.empty(4*n_faces, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] J = np.empty(4*n_faces, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(4*n_faces, dtype=np.float64)
 */
  __Pyx_TraceLine(2861,0,__PYX_ERR(0, 2861, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_long((4 * __pyx_v_n_faces)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_int64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_9) < 0) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_9, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_I = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2862
 *             int_t n_faces = self.n_faces if dim==3 else self.n_cells
 *             np.int64_t[:] I = np.empty(4*n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*n_faces, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] V = np.empty(4*n_faces, dtype=np.float64)
 *             Face *face
 */
  __Pyx_TraceLine(2862,0,__PYX_ERR(0, 2862, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyInt_From_long((4 * __pyx_v_n_faces)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 2862, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_J = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2863
 *             np.int64_t[:] I = np.empty(4*n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*n_faces, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(4*n_faces, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             Face *face
 *             int_t ii
 */
  __Pyx_TraceLine(2863,0,__PYX_ERR(0, 2863, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_empty); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyInt_From_long((4 * __pyx_v_n_faces)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 2863, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_V = __pyx_t_11;
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2866
 *             Face *face
 *             int_t ii
 *             int_t face_offset_y = self.n_faces_x             # <<<<<<<<<<<<<<
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y if dim==3 else 0
 *             int_t edge_offset_y = self.n_total_edges_x
 */
  __Pyx_TraceLine(2866,0,__PYX_ERR(0, 2866, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_3 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2866, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_face_offset_y = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2867
 *             int_t ii
 *             int_t face_offset_y = self.n_faces_x
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y if dim==3 else 0             # <<<<<<<<<<<<<<
 *             int_t edge_offset_y = self.n_total_edges_x
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y
 */
  __Pyx_TraceLine(2867,0,__PYX_ERR(0, 2867, __pyx_L1_error))
  if (((__pyx_v_dim == 3) != 0)) {
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_5 = __Pyx_PyInt_As_int_t(__pyx_t_7); if (unlikely((__pyx_t_5 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2867, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_3 = 0;
  }
  __pyx_v_face_offset_z = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2868
 *             int_t face_offset_y = self.n_faces_x
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y if dim==3 else 0
 *             int_t edge_offset_y = self.n_total_edges_x             # <<<<<<<<<<<<<<
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y
 *             double area
 */
  __Pyx_TraceLine(2868,0,__PYX_ERR(0, 2868, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2868, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_As_int_t(__pyx_t_7); if (unlikely((__pyx_t_3 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2868, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_edge_offset_y = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2869
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y if dim==3 else 0
 *             int_t edge_offset_y = self.n_total_edges_x
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y             # <<<<<<<<<<<<<<
 *             double area
 * 
 */
  __Pyx_TraceLine(2869,0,__PYX_ERR(0, 2869, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2869, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2869, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = PyNumber_Add(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2869, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_3 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_3 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2869, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_edge_offset_z = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2872
 *             double area
 * 
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_x:
 *                 face = it.second
 */
  __Pyx_TraceLine(2872,0,__PYX_ERR(0, 2872, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2873
 * 
 *         if dim == 3:
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging:
 */
    __Pyx_TraceLine(2873,0,__PYX_ERR(0, 2873, __pyx_L1_error))
    __pyx_t_13 = &__pyx_v_self->tree->faces_x;
    __pyx_t_12 = __pyx_t_13->begin();
    for (;;) {
      if (!(__pyx_t_12 != __pyx_t_13->end())) break;
      __pyx_t_14 = *__pyx_t_12;
      ++__pyx_t_12;
      __pyx_v_it = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":2874
 *         if dim == 3:
 *             for it in self.tree.faces_x:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if face.hanging:
 *                     continue
 */
      __Pyx_TraceLine(2874,0,__PYX_ERR(0, 2874, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":2875
 *             for it in self.tree.faces_x:
 *                 face = it.second
 *                 if face.hanging:             # <<<<<<<<<<<<<<
 *                     continue
 *                 ii = face.index
 */
      __Pyx_TraceLine(2875,0,__PYX_ERR(0, 2875, __pyx_L1_error))
      __pyx_t_2 = (__pyx_v_face->hanging != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":2876
 *                 face = it.second
 *                 if face.hanging:
 *                     continue             # <<<<<<<<<<<<<<
 *                 ii = face.index
 *                 I[4*ii : 4*ii + 4] = ii
 */
        __Pyx_TraceLine(2876,0,__PYX_ERR(0, 2876, __pyx_L1_error))
        goto __pyx_L5_continue;

        /* "discretize/_extensions/tree_ext.pyx":2875
 *             for it in self.tree.faces_x:
 *                 face = it.second
 *                 if face.hanging:             # <<<<<<<<<<<<<<
 *                     continue
 *                 ii = face.index
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2877
 *                 if face.hanging:
 *                     continue
 *                 ii = face.index             # <<<<<<<<<<<<<<
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 */
      __Pyx_TraceLine(2877,0,__PYX_ERR(0, 2877, __pyx_L1_error))
      __pyx_t_3 = __pyx_v_face->index;
      __pyx_v_ii = __pyx_t_3;

      /* "discretize/_extensions/tree_ext.pyx":2878
 *                     continue
 *                 ii = face.index
 *                 I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index + edge_offset_y
 */
      __Pyx_TraceLine(2878,0,__PYX_ERR(0, 2878, __pyx_L1_error))
      __pyx_t_10.data = __pyx_v_I.data;
      __pyx_t_10.memview = __pyx_v_I.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
      __pyx_t_16 = -1;
      if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2878, __pyx_L1_error)
}

{
          __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
          {
              Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
              Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
              char *__pyx_temp_pointer_0;
              Py_ssize_t __pyx_temp_idx_0;
              __pyx_temp_pointer_0 = __pyx_t_10.data;
              for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                __pyx_temp_pointer_0 += __pyx_temp_stride_0;
              }
          }
      }
      __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
      __pyx_t_10.memview = NULL;
      __pyx_t_10.data = NULL;

      /* "discretize/_extensions/tree_ext.pyx":2879
 *                 ii = face.index
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z             # <<<<<<<<<<<<<<
 *                 J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 */
      __Pyx_TraceLine(2879,0,__PYX_ERR(0, 2879, __pyx_L1_error))
      __pyx_t_17 = (4 * __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_z);

      /* "discretize/_extensions/tree_ext.pyx":2880
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index + edge_offset_y             # <<<<<<<<<<<<<<
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *                 J[4*ii + 3] = face.edges[3].index + edge_offset_y
 */
      __Pyx_TraceLine(2880,0,__PYX_ERR(0, 2880, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[1])->index + __pyx_v_edge_offset_y);

      /* "discretize/_extensions/tree_ext.pyx":2881
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z             # <<<<<<<<<<<<<<
 *                 J[4*ii + 3] = face.edges[3].index + edge_offset_y
 * 
 */
      __Pyx_TraceLine(2881,0,__PYX_ERR(0, 2881, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_z);

      /* "discretize/_extensions/tree_ext.pyx":2882
 *                 J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *                 J[4*ii + 3] = face.edges[3].index + edge_offset_y             # <<<<<<<<<<<<<<
 * 
 *                 area = face.area
 */
      __Pyx_TraceLine(2882,0,__PYX_ERR(0, 2882, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[3])->index + __pyx_v_edge_offset_y);

      /* "discretize/_extensions/tree_ext.pyx":2884
 *                 J[4*ii + 3] = face.edges[3].index + edge_offset_y
 * 
 *                 area = face.area             # <<<<<<<<<<<<<<
 *                 V[4*ii    ] = -face.edges[0].length/area
 *                 V[4*ii + 1] = -face.edges[1].length/area
 */
      __Pyx_TraceLine(2884,0,__PYX_ERR(0, 2884, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_face->area;
      __pyx_v_area = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2885
 * 
 *                 area = face.area
 *                 V[4*ii    ] = -face.edges[0].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 1] = -face.edges[1].length/area
 *                 V[4*ii + 2] =  face.edges[2].length/area
 */
      __Pyx_TraceLine(2885,0,__PYX_ERR(0, 2885, __pyx_L1_error))
      __pyx_t_17 = (4 * __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[0])->length) / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2886
 *                 area = face.area
 *                 V[4*ii    ] = -face.edges[0].length/area
 *                 V[4*ii + 1] = -face.edges[1].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 2] =  face.edges[2].length/area
 *                 V[4*ii + 3] =  face.edges[3].length/area
 */
      __Pyx_TraceLine(2886,0,__PYX_ERR(0, 2886, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[1])->length) / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2887
 *                 V[4*ii    ] = -face.edges[0].length/area
 *                 V[4*ii + 1] = -face.edges[1].length/area
 *                 V[4*ii + 2] =  face.edges[2].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 3] =  face.edges[3].length/area
 * 
 */
      __Pyx_TraceLine(2887,0,__PYX_ERR(0, 2887, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[2])->length / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2888
 *                 V[4*ii + 1] = -face.edges[1].length/area
 *                 V[4*ii + 2] =  face.edges[2].length/area
 *                 V[4*ii + 3] =  face.edges[3].length/area             # <<<<<<<<<<<<<<
 * 
 *             for it in self.tree.faces_y:
 */
      __Pyx_TraceLine(2888,0,__PYX_ERR(0, 2888, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[3])->length / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2873
 * 
 *         if dim == 3:
 *             for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging:
 */
      __Pyx_TraceLine(2873,0,__PYX_ERR(0, 2873, __pyx_L1_error))
      __pyx_L5_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2890
 *                 V[4*ii + 3] =  face.edges[3].length/area
 * 
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging:
 */
    __Pyx_TraceLine(2890,0,__PYX_ERR(0, 2890, __pyx_L1_error))
    __pyx_t_13 = &__pyx_v_self->tree->faces_y;
    __pyx_t_12 = __pyx_t_13->begin();
    for (;;) {
      if (!(__pyx_t_12 != __pyx_t_13->end())) break;
      __pyx_t_14 = *__pyx_t_12;
      ++__pyx_t_12;
      __pyx_v_it = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":2891
 * 
 *             for it in self.tree.faces_y:
 *                 face = it.second             # <<<<<<<<<<<<<<
 *                 if face.hanging:
 *                     continue
 */
      __Pyx_TraceLine(2891,0,__PYX_ERR(0, 2891, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_it.second;
      __pyx_v_face = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":2892
 *             for it in self.tree.faces_y:
 *                 face = it.second
 *                 if face.hanging:             # <<<<<<<<<<<<<<
 *                     continue
 *                 ii = face.index + face_offset_y
 */
      __Pyx_TraceLine(2892,0,__PYX_ERR(0, 2892, __pyx_L1_error))
      __pyx_t_2 = (__pyx_v_face->hanging != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":2893
 *                 face = it.second
 *                 if face.hanging:
 *                     continue             # <<<<<<<<<<<<<<
 *                 ii = face.index + face_offset_y
 *                 I[4*ii : 4*ii + 4] = ii
 */
        __Pyx_TraceLine(2893,0,__PYX_ERR(0, 2893, __pyx_L1_error))
        goto __pyx_L8_continue;

        /* "discretize/_extensions/tree_ext.pyx":2892
 *             for it in self.tree.faces_y:
 *                 face = it.second
 *                 if face.hanging:             # <<<<<<<<<<<<<<
 *                     continue
 *                 ii = face.index + face_offset_y
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":2894
 *                 if face.hanging:
 *                     continue
 *                 ii = face.index + face_offset_y             # <<<<<<<<<<<<<<
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 */
      __Pyx_TraceLine(2894,0,__PYX_ERR(0, 2894, __pyx_L1_error))
      __pyx_v_ii = (__pyx_v_face->index + __pyx_v_face_offset_y);

      /* "discretize/_extensions/tree_ext.pyx":2895
 *                     continue
 *                 ii = face.index + face_offset_y
 *                 I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index
 */
      __Pyx_TraceLine(2895,0,__PYX_ERR(0, 2895, __pyx_L1_error))
      __pyx_t_10.data = __pyx_v_I.data;
      __pyx_t_10.memview = __pyx_v_I.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
      __pyx_t_16 = -1;
      if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2895, __pyx_L1_error)
}

{
          __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
          {
              Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
              Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
              char *__pyx_temp_pointer_0;
              Py_ssize_t __pyx_temp_idx_0;
              __pyx_temp_pointer_0 = __pyx_t_10.data;
              for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                __pyx_temp_pointer_0 += __pyx_temp_stride_0;
              }
          }
      }
      __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
      __pyx_t_10.memview = NULL;
      __pyx_t_10.data = NULL;

      /* "discretize/_extensions/tree_ext.pyx":2896
 *                 ii = face.index + face_offset_y
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z             # <<<<<<<<<<<<<<
 *                 J[4*ii + 1] = face.edges[1].index
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 */
      __Pyx_TraceLine(2896,0,__PYX_ERR(0, 2896, __pyx_L1_error))
      __pyx_t_17 = (4 * __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_z);

      /* "discretize/_extensions/tree_ext.pyx":2897
 *                 I[4*ii : 4*ii + 4] = ii
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index             # <<<<<<<<<<<<<<
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *                 J[4*ii + 3] = face.edges[3].index
 */
      __Pyx_TraceLine(2897,0,__PYX_ERR(0, 2897, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_face->edges[1])->index;
      __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

      /* "discretize/_extensions/tree_ext.pyx":2898
 *                 J[4*ii    ] = face.edges[0].index + edge_offset_z
 *                 J[4*ii + 1] = face.edges[1].index
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z             # <<<<<<<<<<<<<<
 *                 J[4*ii + 3] = face.edges[3].index
 * 
 */
      __Pyx_TraceLine(2898,0,__PYX_ERR(0, 2898, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_z);

      /* "discretize/_extensions/tree_ext.pyx":2899
 *                 J[4*ii + 1] = face.edges[1].index
 *                 J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *                 J[4*ii + 3] = face.edges[3].index             # <<<<<<<<<<<<<<
 * 
 *                 area = face.area
 */
      __Pyx_TraceLine(2899,0,__PYX_ERR(0, 2899, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_face->edges[3])->index;
      __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

      /* "discretize/_extensions/tree_ext.pyx":2901
 *                 J[4*ii + 3] = face.edges[3].index
 * 
 *                 area = face.area             # <<<<<<<<<<<<<<
 *                 V[4*ii    ] =  face.edges[0].length/area
 *                 V[4*ii + 1] =  face.edges[1].length/area
 */
      __Pyx_TraceLine(2901,0,__PYX_ERR(0, 2901, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_face->area;
      __pyx_v_area = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":2902
 * 
 *                 area = face.area
 *                 V[4*ii    ] =  face.edges[0].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 1] =  face.edges[1].length/area
 *                 V[4*ii + 2] = -face.edges[2].length/area
 */
      __Pyx_TraceLine(2902,0,__PYX_ERR(0, 2902, __pyx_L1_error))
      __pyx_t_17 = (4 * __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[0])->length / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2903
 *                 area = face.area
 *                 V[4*ii    ] =  face.edges[0].length/area
 *                 V[4*ii + 1] =  face.edges[1].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 2] = -face.edges[2].length/area
 *                 V[4*ii + 3] = -face.edges[3].length/area
 */
      __Pyx_TraceLine(2903,0,__PYX_ERR(0, 2903, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[1])->length / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2904
 *                 V[4*ii    ] =  face.edges[0].length/area
 *                 V[4*ii + 1] =  face.edges[1].length/area
 *                 V[4*ii + 2] = -face.edges[2].length/area             # <<<<<<<<<<<<<<
 *                 V[4*ii + 3] = -face.edges[3].length/area
 * 
 */
      __Pyx_TraceLine(2904,0,__PYX_ERR(0, 2904, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[2])->length) / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2905
 *                 V[4*ii + 1] =  face.edges[1].length/area
 *                 V[4*ii + 2] = -face.edges[2].length/area
 *                 V[4*ii + 3] = -face.edges[3].length/area             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_z:
 */
      __Pyx_TraceLine(2905,0,__PYX_ERR(0, 2905, __pyx_L1_error))
      __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[3])->length) / __pyx_v_area);

      /* "discretize/_extensions/tree_ext.pyx":2890
 *                 V[4*ii + 3] =  face.edges[3].length/area
 * 
 *             for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *                 face = it.second
 *                 if face.hanging:
 */
      __Pyx_TraceLine(2890,0,__PYX_ERR(0, 2890, __pyx_L1_error))
      __pyx_L8_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":2872
 *             double area
 * 
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             for it in self.tree.faces_x:
 *                 face = it.second
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2907
 *                 V[4*ii + 3] = -face.edges[3].length/area
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(2907,0,__PYX_ERR(0, 2907, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->faces_z;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":2908
 * 
 *         for it in self.tree.faces_z:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(2908,0,__PYX_ERR(0, 2908, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":2909
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_z
 */
    __Pyx_TraceLine(2909,0,__PYX_ERR(0, 2909, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":2910
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii
 */
      __Pyx_TraceLine(2910,0,__PYX_ERR(0, 2910, __pyx_L1_error))
      goto __pyx_L11_continue;

      /* "discretize/_extensions/tree_ext.pyx":2909
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_z
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":2911
 *             if face.hanging:
 *                 continue
 *             ii = face.index + face_offset_z             # <<<<<<<<<<<<<<
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 */
    __Pyx_TraceLine(2911,0,__PYX_ERR(0, 2911, __pyx_L1_error))
    __pyx_v_ii = (__pyx_v_face->index + __pyx_v_face_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":2912
 *                 continue
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index
 */
    __Pyx_TraceLine(2912,0,__PYX_ERR(0, 2912, __pyx_L1_error))
    __pyx_t_10.data = __pyx_v_I.data;
    __pyx_t_10.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2912, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_10.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2913
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y             # <<<<<<<<<<<<<<
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 */
    __Pyx_TraceLine(2913,0,__PYX_ERR(0, 2913, __pyx_L1_error))
    __pyx_t_17 = (4 * __pyx_v_ii);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":2914
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index             # <<<<<<<<<<<<<<
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 *             J[4*ii + 3] = face.edges[3].index
 */
    __Pyx_TraceLine(2914,0,__PYX_ERR(0, 2914, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_face->edges[1])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":2915
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y             # <<<<<<<<<<<<<<
 *             J[4*ii + 3] = face.edges[3].index
 * 
 */
    __Pyx_TraceLine(2915,0,__PYX_ERR(0, 2915, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":2916
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 *             J[4*ii + 3] = face.edges[3].index             # <<<<<<<<<<<<<<
 * 
 *             area = face.area
 */
    __Pyx_TraceLine(2916,0,__PYX_ERR(0, 2916, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_face->edges[3])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":2918
 *             J[4*ii + 3] = face.edges[3].index
 * 
 *             area = face.area             # <<<<<<<<<<<<<<
 *             V[4*ii    ] = -face.edges[0].length/area
 *             V[4*ii + 1] = -face.edges[1].length/area
 */
    __Pyx_TraceLine(2918,0,__PYX_ERR(0, 2918, __pyx_L1_error))
    __pyx_t_18 = __pyx_v_face->area;
    __pyx_v_area = __pyx_t_18;

    /* "discretize/_extensions/tree_ext.pyx":2919
 * 
 *             area = face.area
 *             V[4*ii    ] = -face.edges[0].length/area             # <<<<<<<<<<<<<<
 *             V[4*ii + 1] = -face.edges[1].length/area
 *             V[4*ii + 2] =  face.edges[2].length/area
 */
    __Pyx_TraceLine(2919,0,__PYX_ERR(0, 2919, __pyx_L1_error))
    __pyx_t_17 = (4 * __pyx_v_ii);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[0])->length) / __pyx_v_area);

    /* "discretize/_extensions/tree_ext.pyx":2920
 *             area = face.area
 *             V[4*ii    ] = -face.edges[0].length/area
 *             V[4*ii + 1] = -face.edges[1].length/area             # <<<<<<<<<<<<<<
 *             V[4*ii + 2] =  face.edges[2].length/area
 *             V[4*ii + 3] =  face.edges[3].length/area
 */
    __Pyx_TraceLine(2920,0,__PYX_ERR(0, 2920, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((-(__pyx_v_face->edges[1])->length) / __pyx_v_area);

    /* "discretize/_extensions/tree_ext.pyx":2921
 *             V[4*ii    ] = -face.edges[0].length/area
 *             V[4*ii + 1] = -face.edges[1].length/area
 *             V[4*ii + 2] =  face.edges[2].length/area             # <<<<<<<<<<<<<<
 *             V[4*ii + 3] =  face.edges[3].length/area
 * 
 */
    __Pyx_TraceLine(2921,0,__PYX_ERR(0, 2921, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[2])->length / __pyx_v_area);

    /* "discretize/_extensions/tree_ext.pyx":2922
 *             V[4*ii + 1] = -face.edges[1].length/area
 *             V[4*ii + 2] =  face.edges[2].length/area
 *             V[4*ii + 3] =  face.edges[3].length/area             # <<<<<<<<<<<<<<
 * 
 *         C = sp.csr_matrix((V, (I, J)),shape=(n_faces, self.n_total_edges))
 */
    __Pyx_TraceLine(2922,0,__PYX_ERR(0, 2922, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = ((__pyx_v_face->edges[3])->length / __pyx_v_area);

    /* "discretize/_extensions/tree_ext.pyx":2907
 *                 V[4*ii + 3] = -face.edges[3].length/area
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(2907,0,__PYX_ERR(0, 2907, __pyx_L1_error))
    __pyx_L11_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":2924
 *             V[4*ii + 3] =  face.edges[3].length/area
 * 
 *         C = sp.csr_matrix((V, (I, J)),shape=(n_faces, self.n_total_edges))             # <<<<<<<<<<<<<<
 *         R = self._deflate_edges()
 *         self._edge_curl = C*R
 */
  __Pyx_TraceLine(2924,0,__PYX_ERR(0, 2924, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_9);
  __pyx_t_7 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_4);
  __pyx_t_6 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyInt_From_int_t(__pyx_v_n_faces); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_7);
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_shape, __pyx_t_19) < 0) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, __pyx_t_9); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_C = __pyx_t_19;
  __pyx_t_19 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2925
 * 
 *         C = sp.csr_matrix((V, (I, J)),shape=(n_faces, self.n_total_edges))
 *         R = self._deflate_edges()             # <<<<<<<<<<<<<<
 *         self._edge_curl = C*R
 *         return self._edge_curl
 */
  __Pyx_TraceLine(2925,0,__PYX_ERR(0, 2925, __pyx_L1_error))
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_19 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_R = __pyx_t_19;
  __pyx_t_19 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2926
 *         C = sp.csr_matrix((V, (I, J)),shape=(n_faces, self.n_total_edges))
 *         R = self._deflate_edges()
 *         self._edge_curl = C*R             # <<<<<<<<<<<<<<
 *         return self._edge_curl
 * 
 */
  __Pyx_TraceLine(2926,0,__PYX_ERR(0, 2926, __pyx_L1_error))
  __pyx_t_19 = PyNumber_Multiply(__pyx_v_C, __pyx_v_R); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_19);
  __Pyx_GOTREF(__pyx_v_self->_edge_curl);
  __Pyx_DECREF(__pyx_v_self->_edge_curl);
  __pyx_v_self->_edge_curl = __pyx_t_19;
  __pyx_t_19 = 0;

  /* "discretize/_extensions/tree_ext.pyx":2927
 *         R = self._deflate_edges()
 *         self._edge_curl = C*R
 *         return self._edge_curl             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(2927,0,__PYX_ERR(0, 2927, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_edge_curl);
  __pyx_r = __pyx_v_self->_edge_curl;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2807
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def edge_curl(self):             # <<<<<<<<<<<<<<
 *         r"""Edge curl operator (edges to faces)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edge_curl.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_C);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":2932
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def nodal_gradient(self):             # <<<<<<<<<<<<<<
 *         r"""Nodal gradient operator (nodes to edges)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int_t __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  double __pyx_v_length;
  int_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_offset1;
  __pyx_t_5numpy_int64_t __pyx_v_offset2;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_v_G = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_t_11;
  std::map<int_t,Edge *> ::iterator __pyx_t_12;
  edge_map_t *__pyx_t_13;
  std::pair<int_t,Edge *>  __pyx_t_14;
  Edge *__pyx_t_15;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  double __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2932, 0, __PYX_ERR(0, 2932, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":2978
 *         x, y or z edge. See the example below.
 *         """
 *         if self._nodal_gradient is not None:             # <<<<<<<<<<<<<<
 *             return self._nodal_gradient
 *         cdef:
 */
  __Pyx_TraceLine(2978,0,__PYX_ERR(0, 2978, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_nodal_gradient != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":2979
 *         """
 *         if self._nodal_gradient is not None:
 *             return self._nodal_gradient             # <<<<<<<<<<<<<<
 *         cdef:
 *             int_t dim = self._dim
 */
    __Pyx_TraceLine(2979,0,__PYX_ERR(0, 2979, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_nodal_gradient);
    __pyx_r = __pyx_v_self->_nodal_gradient;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":2978
 *         x, y or z edge. See the example below.
 *         """
 *         if self._nodal_gradient is not None:             # <<<<<<<<<<<<<<
 *             return self._nodal_gradient
 *         cdef:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":2981
 *             return self._nodal_gradient
 *         cdef:
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             np.int64_t[:] I = np.empty(2*self.n_edges, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(2*self.n_edges, dtype=np.int64)
 */
  __Pyx_TraceLine(2981,0,__PYX_ERR(0, 2981, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_3;

  /* "discretize/_extensions/tree_ext.pyx":2982
 *         cdef:
 *             int_t dim = self._dim
 *             np.int64_t[:] I = np.empty(2*self.n_edges, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] J = np.empty(2*self.n_edges, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(2*self.n_edges, dtype=np.float64)
 */
  __Pyx_TraceLine(2982,0,__PYX_ERR(0, 2982, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2982, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_I = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2983
 *             int_t dim = self._dim
 *             np.int64_t[:] I = np.empty(2*self.n_edges, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(2*self.n_edges, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] V = np.empty(2*self.n_edges, dtype=np.float64)
 *             Edge *edge
 */
  __Pyx_TraceLine(2983,0,__PYX_ERR(0, 2983, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 2983, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_J = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2984
 *             np.int64_t[:] I = np.empty(2*self.n_edges, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(2*self.n_edges, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(2*self.n_edges, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             Edge *edge
 *             double length
 */
  __Pyx_TraceLine(2984,0,__PYX_ERR(0, 2984, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 2984, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_V = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":2988
 *             double length
 *             int_t ii
 *             np.int64_t offset1 = self.n_edges_x             # <<<<<<<<<<<<<<
 *             np.int64_t offset2 = offset1 + self.n_edges_y
 * 
 */
  __Pyx_TraceLine(2988,0,__PYX_ERR(0, 2988, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2988, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_t_5); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2988, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_offset1 = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":2989
 *             int_t ii
 *             np.int64_t offset1 = self.n_edges_x
 *             np.int64_t offset2 = offset1 + self.n_edges_y             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.edges_x:
 */
  __Pyx_TraceLine(2989,0,__PYX_ERR(0, 2989, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_offset1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2989, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_t_7); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2989, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_offset2 = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":2991
 *             np.int64_t offset2 = offset1 + self.n_edges_y
 * 
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging: continue
 */
  __Pyx_TraceLine(2991,0,__PYX_ERR(0, 2991, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->edges_x;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":2992
 * 
 *         for it in self.tree.edges_x:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             if edge.hanging: continue
 *             ii = edge.index
 */
    __Pyx_TraceLine(2992,0,__PYX_ERR(0, 2992, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":2993
 *         for it in self.tree.edges_x:
 *             edge = it.second
 *             if edge.hanging: continue             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             I[ii*2 : ii*2 + 2] = ii
 */
    __Pyx_TraceLine(2993,0,__PYX_ERR(0, 2993, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_2) {
      goto __pyx_L4_continue;
    }

    /* "discretize/_extensions/tree_ext.pyx":2994
 *             edge = it.second
 *             if edge.hanging: continue
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index
 */
    __Pyx_TraceLine(2994,0,__PYX_ERR(0, 2994, __pyx_L1_error))
    __pyx_t_3 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":2995
 *             if edge.hanging: continue
 *             ii = edge.index
 *             I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *             J[ii*2    ] = edge.points[0].index
 *             J[ii*2 + 1] = edge.points[1].index
 */
    __Pyx_TraceLine(2995,0,__PYX_ERR(0, 2995, __pyx_L1_error))
    __pyx_t_9.data = __pyx_v_I.data;
    __pyx_t_9.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 2995, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_9.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":2996
 *             ii = edge.index
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index             # <<<<<<<<<<<<<<
 *             J[ii*2 + 1] = edge.points[1].index
 * 
 */
    __Pyx_TraceLine(2996,0,__PYX_ERR(0, 2996, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_edge->points[0])->index;
    __pyx_t_17 = (__pyx_v_ii * 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":2997
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index
 *             J[ii*2 + 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *             length = edge.length
 */
    __Pyx_TraceLine(2997,0,__PYX_ERR(0, 2997, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_edge->points[1])->index;
    __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":2999
 *             J[ii*2 + 1] = edge.points[1].index
 * 
 *             length = edge.length             # <<<<<<<<<<<<<<
 *             V[ii*2    ] = -1.0/length
 *             V[ii*2 + 1] =  1.0/length
 */
    __Pyx_TraceLine(2999,0,__PYX_ERR(0, 2999, __pyx_L1_error))
    __pyx_t_18 = __pyx_v_edge->length;
    __pyx_v_length = __pyx_t_18;

    /* "discretize/_extensions/tree_ext.pyx":3000
 * 
 *             length = edge.length
 *             V[ii*2    ] = -1.0/length             # <<<<<<<<<<<<<<
 *             V[ii*2 + 1] =  1.0/length
 * 
 */
    __Pyx_TraceLine(3000,0,__PYX_ERR(0, 3000, __pyx_L1_error))
    __pyx_t_17 = (__pyx_v_ii * 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (-1.0 / __pyx_v_length);

    /* "discretize/_extensions/tree_ext.pyx":3001
 *             length = edge.length
 *             V[ii*2    ] = -1.0/length
 *             V[ii*2 + 1] =  1.0/length             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.edges_y:
 */
    __Pyx_TraceLine(3001,0,__PYX_ERR(0, 3001, __pyx_L1_error))
    __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (1.0 / __pyx_v_length);

    /* "discretize/_extensions/tree_ext.pyx":2991
 *             np.int64_t offset2 = offset1 + self.n_edges_y
 * 
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging: continue
 */
    __Pyx_TraceLine(2991,0,__PYX_ERR(0, 2991, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3003
 *             V[ii*2 + 1] =  1.0/length
 * 
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging: continue
 */
  __Pyx_TraceLine(3003,0,__PYX_ERR(0, 3003, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->edges_y;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":3004
 * 
 *         for it in self.tree.edges_y:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             if edge.hanging: continue
 *             ii = edge.index + offset1
 */
    __Pyx_TraceLine(3004,0,__PYX_ERR(0, 3004, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":3005
 *         for it in self.tree.edges_y:
 *             edge = it.second
 *             if edge.hanging: continue             # <<<<<<<<<<<<<<
 *             ii = edge.index + offset1
 *             I[ii*2 : ii*2 + 2] = ii
 */
    __Pyx_TraceLine(3005,0,__PYX_ERR(0, 3005, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_2) {
      goto __pyx_L7_continue;
    }

    /* "discretize/_extensions/tree_ext.pyx":3006
 *             edge = it.second
 *             if edge.hanging: continue
 *             ii = edge.index + offset1             # <<<<<<<<<<<<<<
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index
 */
    __Pyx_TraceLine(3006,0,__PYX_ERR(0, 3006, __pyx_L1_error))
    __pyx_v_ii = (__pyx_v_edge->index + __pyx_v_offset1);

    /* "discretize/_extensions/tree_ext.pyx":3007
 *             if edge.hanging: continue
 *             ii = edge.index + offset1
 *             I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *             J[ii*2    ] = edge.points[0].index
 *             J[ii*2 + 1] = edge.points[1].index
 */
    __Pyx_TraceLine(3007,0,__PYX_ERR(0, 3007, __pyx_L1_error))
    __pyx_t_9.data = __pyx_v_I.data;
    __pyx_t_9.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3007, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_9.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3008
 *             ii = edge.index + offset1
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index             # <<<<<<<<<<<<<<
 *             J[ii*2 + 1] = edge.points[1].index
 * 
 */
    __Pyx_TraceLine(3008,0,__PYX_ERR(0, 3008, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_edge->points[0])->index;
    __pyx_t_17 = (__pyx_v_ii * 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":3009
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = edge.points[0].index
 *             J[ii*2 + 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *             length = edge.length
 */
    __Pyx_TraceLine(3009,0,__PYX_ERR(0, 3009, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_edge->points[1])->index;
    __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

    /* "discretize/_extensions/tree_ext.pyx":3011
 *             J[ii*2 + 1] = edge.points[1].index
 * 
 *             length = edge.length             # <<<<<<<<<<<<<<
 *             V[ii*2    ] = -1.0/length
 *             V[ii*2 + 1] =  1.0/length
 */
    __Pyx_TraceLine(3011,0,__PYX_ERR(0, 3011, __pyx_L1_error))
    __pyx_t_18 = __pyx_v_edge->length;
    __pyx_v_length = __pyx_t_18;

    /* "discretize/_extensions/tree_ext.pyx":3012
 * 
 *             length = edge.length
 *             V[ii*2    ] = -1.0/length             # <<<<<<<<<<<<<<
 *             V[ii*2 + 1] =  1.0/length
 * 
 */
    __Pyx_TraceLine(3012,0,__PYX_ERR(0, 3012, __pyx_L1_error))
    __pyx_t_17 = (__pyx_v_ii * 2);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (-1.0 / __pyx_v_length);

    /* "discretize/_extensions/tree_ext.pyx":3013
 *             length = edge.length
 *             V[ii*2    ] = -1.0/length
 *             V[ii*2 + 1] =  1.0/length             # <<<<<<<<<<<<<<
 * 
 *         if(dim>2):
 */
    __Pyx_TraceLine(3013,0,__PYX_ERR(0, 3013, __pyx_L1_error))
    __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (1.0 / __pyx_v_length);

    /* "discretize/_extensions/tree_ext.pyx":3003
 *             V[ii*2 + 1] =  1.0/length
 * 
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging: continue
 */
    __Pyx_TraceLine(3003,0,__PYX_ERR(0, 3003, __pyx_L1_error))
    __pyx_L7_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3015
 *             V[ii*2 + 1] =  1.0/length
 * 
 *         if(dim>2):             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 */
  __Pyx_TraceLine(3015,0,__PYX_ERR(0, 3015, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_dim > 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3016
 * 
 *         if(dim>2):
 *             for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
    __Pyx_TraceLine(3016,0,__PYX_ERR(0, 3016, __pyx_L1_error))
    __pyx_t_13 = &__pyx_v_self->tree->edges_z;
    __pyx_t_12 = __pyx_t_13->begin();
    for (;;) {
      if (!(__pyx_t_12 != __pyx_t_13->end())) break;
      __pyx_t_14 = *__pyx_t_12;
      ++__pyx_t_12;
      __pyx_v_it = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":3017
 *         if(dim>2):
 *             for it in self.tree.edges_z:
 *                 edge = it.second             # <<<<<<<<<<<<<<
 *                 if edge.hanging: continue
 *                 ii = edge.index + offset2
 */
      __Pyx_TraceLine(3017,0,__PYX_ERR(0, 3017, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_it.second;
      __pyx_v_edge = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":3018
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 *                 if edge.hanging: continue             # <<<<<<<<<<<<<<
 *                 ii = edge.index + offset2
 *                 I[ii*2 : ii*2 + 2] = ii
 */
      __Pyx_TraceLine(3018,0,__PYX_ERR(0, 3018, __pyx_L1_error))
      __pyx_t_2 = (__pyx_v_edge->hanging != 0);
      if (__pyx_t_2) {
        goto __pyx_L11_continue;
      }

      /* "discretize/_extensions/tree_ext.pyx":3019
 *                 edge = it.second
 *                 if edge.hanging: continue
 *                 ii = edge.index + offset2             # <<<<<<<<<<<<<<
 *                 I[ii*2 : ii*2 + 2] = ii
 *                 J[ii*2    ] = edge.points[0].index
 */
      __Pyx_TraceLine(3019,0,__PYX_ERR(0, 3019, __pyx_L1_error))
      __pyx_v_ii = (__pyx_v_edge->index + __pyx_v_offset2);

      /* "discretize/_extensions/tree_ext.pyx":3020
 *                 if edge.hanging: continue
 *                 ii = edge.index + offset2
 *                 I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*2    ] = edge.points[0].index
 *                 J[ii*2 + 1] = edge.points[1].index
 */
      __Pyx_TraceLine(3020,0,__PYX_ERR(0, 3020, __pyx_L1_error))
      __pyx_t_9.data = __pyx_v_I.data;
      __pyx_t_9.memview = __pyx_v_I.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
      __pyx_t_16 = -1;
      if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3020, __pyx_L1_error)
}

{
          __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
          {
              Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
              Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
              char *__pyx_temp_pointer_0;
              Py_ssize_t __pyx_temp_idx_0;
              __pyx_temp_pointer_0 = __pyx_t_9.data;
              for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                __pyx_temp_pointer_0 += __pyx_temp_stride_0;
              }
          }
      }
      __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
      __pyx_t_9.memview = NULL;
      __pyx_t_9.data = NULL;

      /* "discretize/_extensions/tree_ext.pyx":3021
 *                 ii = edge.index + offset2
 *                 I[ii*2 : ii*2 + 2] = ii
 *                 J[ii*2    ] = edge.points[0].index             # <<<<<<<<<<<<<<
 *                 J[ii*2 + 1] = edge.points[1].index
 * 
 */
      __Pyx_TraceLine(3021,0,__PYX_ERR(0, 3021, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_edge->points[0])->index;
      __pyx_t_17 = (__pyx_v_ii * 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

      /* "discretize/_extensions/tree_ext.pyx":3022
 *                 I[ii*2 : ii*2 + 2] = ii
 *                 J[ii*2    ] = edge.points[0].index
 *                 J[ii*2 + 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *                 length = edge.length
 */
      __Pyx_TraceLine(3022,0,__PYX_ERR(0, 3022, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_edge->points[1])->index;
      __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_3;

      /* "discretize/_extensions/tree_ext.pyx":3024
 *                 J[ii*2 + 1] = edge.points[1].index
 * 
 *                 length = edge.length             # <<<<<<<<<<<<<<
 *                 V[ii*2    ] = -1.0/length
 *                 V[ii*2 + 1] =  1.0/length
 */
      __Pyx_TraceLine(3024,0,__PYX_ERR(0, 3024, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_edge->length;
      __pyx_v_length = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":3025
 * 
 *                 length = edge.length
 *                 V[ii*2    ] = -1.0/length             # <<<<<<<<<<<<<<
 *                 V[ii*2 + 1] =  1.0/length
 * 
 */
      __Pyx_TraceLine(3025,0,__PYX_ERR(0, 3025, __pyx_L1_error))
      __pyx_t_17 = (__pyx_v_ii * 2);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (-1.0 / __pyx_v_length);

      /* "discretize/_extensions/tree_ext.pyx":3026
 *                 length = edge.length
 *                 V[ii*2    ] = -1.0/length
 *                 V[ii*2 + 1] =  1.0/length             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(3026,0,__PYX_ERR(0, 3026, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ii * 2) + 1);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = (1.0 / __pyx_v_length);

      /* "discretize/_extensions/tree_ext.pyx":3016
 * 
 *         if(dim>2):
 *             for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *                 edge = it.second
 *                 if edge.hanging: continue
 */
      __Pyx_TraceLine(3016,0,__PYX_ERR(0, 3016, __pyx_L1_error))
      __pyx_L11_continue:;
    }

    /* "discretize/_extensions/tree_ext.pyx":3015
 *             V[ii*2 + 1] =  1.0/length
 * 
 *         if(dim>2):             # <<<<<<<<<<<<<<
 *             for it in self.tree.edges_z:
 *                 edge = it.second
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3029
 * 
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         G = sp.csr_matrix((V, (I, J)), shape=(self.n_edges, self.n_total_nodes))
 *         self._nodal_gradient = G*Rn
 */
  __Pyx_TraceLine(3029,0,__PYX_ERR(0, 3029, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_Rn = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3030
 * 
 *         Rn = self._deflate_nodes()
 *         G = sp.csr_matrix((V, (I, J)), shape=(self.n_edges, self.n_total_nodes))             # <<<<<<<<<<<<<<
 *         self._nodal_gradient = G*Rn
 *         return self._nodal_gradient
 */
  __Pyx_TraceLine(3030,0,__PYX_ERR(0, 3030, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6);
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_5);
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_shape, __pyx_t_19) < 0) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_G = __pyx_t_19;
  __pyx_t_19 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3031
 *         Rn = self._deflate_nodes()
 *         G = sp.csr_matrix((V, (I, J)), shape=(self.n_edges, self.n_total_nodes))
 *         self._nodal_gradient = G*Rn             # <<<<<<<<<<<<<<
 *         return self._nodal_gradient
 * 
 */
  __Pyx_TraceLine(3031,0,__PYX_ERR(0, 3031, __pyx_L1_error))
  __pyx_t_19 = PyNumber_Multiply(__pyx_v_G, __pyx_v_Rn); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_19);
  __Pyx_GOTREF(__pyx_v_self->_nodal_gradient);
  __Pyx_DECREF(__pyx_v_self->_nodal_gradient);
  __pyx_v_self->_nodal_gradient = __pyx_t_19;
  __pyx_t_19 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3032
 *         G = sp.csr_matrix((V, (I, J)), shape=(self.n_edges, self.n_total_nodes))
 *         self._nodal_gradient = G*Rn
 *         return self._nodal_gradient             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3032,0,__PYX_ERR(0, 3032, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_nodal_gradient);
  __pyx_r = __pyx_v_self->_nodal_gradient;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":2932
 *     @cython.cdivision(True)
 *     @cython.boundscheck(False)
 *     def nodal_gradient(self):             # <<<<<<<<<<<<<<
 *         r"""Nodal gradient operator (nodes to edges)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.nodal_gradient.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XDECREF(__pyx_v_G);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3035
 * 
 *     @property
 *     def nodal_laplacian(self):             # <<<<<<<<<<<<<<
 *         """Not implemented on the TreeMesh."""
 *         raise NotImplementedError('Nodal Laplacian has not been implemented for TreeMesh')
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian___get__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3035, 0, __PYX_ERR(0, 3035, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3037
 *     def nodal_laplacian(self):
 *         """Not implemented on the TreeMesh."""
 *         raise NotImplementedError('Nodal Laplacian has not been implemented for TreeMesh')             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3037,0,__PYX_ERR(0, 3037, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3037, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 3037, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":3035
 * 
 *     @property
 *     def nodal_laplacian(self):             # <<<<<<<<<<<<<<
 *         """Not implemented on the TreeMesh."""
 *         raise NotImplementedError('Nodal Laplacian has not been implemented for TreeMesh')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.nodal_laplacian.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3040
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_x(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) x faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_37average_cell_to_total_face_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_36average_cell_to_total_face_x[] = "_TreeMesh.average_cell_to_total_face_x(self)\nAverage matrix for cell center to total (including hanging) x faces.\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_total_faces_x, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from faces to cell centers\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_37average_cell_to_total_face_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("average_cell_to_total_face_x (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_36average_cell_to_total_face_x(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_36average_cell_to_total_face_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_8;
  std::vector<Cell *> ::iterator __pyx_t_9;
  std::vector<Cell *>  *__pyx_t_10;
  Cell *__pyx_t_11;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PY_LONG_LONG __pyx_t_14;
  long __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("average_cell_to_total_face_x", 0);
  __Pyx_TraceCall("average_cell_to_total_face_x", __pyx_f[0], 3040, 0, __PYX_ERR(0, 3040, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3053
 *             The scalar averaging operator from faces to cell centers
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 */
  __Pyx_TraceLine(3053,0,__PYX_ERR(0, 3053, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3053, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3054
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(3054,0,__PYX_ERR(0, 3054, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3054, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3055
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3055,0,__PYX_ERR(0, 3055, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3055, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3056
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3056,0,__PYX_ERR(0, 3056, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_8;

  /* "discretize/_extensions/tree_ext.pyx":3059
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 */
  __Pyx_TraceLine(3059,0,__PYX_ERR(0, 3059, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->cells;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_cell = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3060
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]             # <<<<<<<<<<<<<<
 *             if next_cell == NULL:
 *                 continue
 */
    __Pyx_TraceLine(3060,0,__PYX_ERR(0, 3060, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[1]);

    /* "discretize/_extensions/tree_ext.pyx":3061
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim == 2:
 */
    __Pyx_TraceLine(3061,0,__PYX_ERR(0, 3061, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":3062
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if dim == 2:
 *                 if next_cell.is_leaf():
 */
      __Pyx_TraceLine(3062,0,__PYX_ERR(0, 3062, __pyx_L1_error))
      goto __pyx_L3_continue;

      /* "discretize/_extensions/tree_ext.pyx":3061
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim == 2:
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3063
 *             if next_cell == NULL:
 *                 continue
 *             if dim == 2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 */
    __Pyx_TraceLine(3063,0,__PYX_ERR(0, 3063, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_dim == 2) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":3064
 *                 continue
 *             if dim == 2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3064,0,__PYX_ERR(0, 3064, __pyx_L1_error))
      __pyx_t_12 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":3065
 *             if dim == 2:
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3065,0,__PYX_ERR(0, 3065, __pyx_L1_error))
        __pyx_t_8 = (__pyx_v_cell->edges[3])->index;
        __pyx_v_ind = __pyx_t_8;

        /* "discretize/_extensions/tree_ext.pyx":3066
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3066,0,__PYX_ERR(0, 3066, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3067
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3067,0,__PYX_ERR(0, 3067, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3068
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 */
        __Pyx_TraceLine(3068,0,__PYX_ERR(0, 3068, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_cell->index;
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3069
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5
 */
        __Pyx_TraceLine(3069,0,__PYX_ERR(0, 3069, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_next_cell->index;
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3070
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = 0.5
 *                 else:
 */
        __Pyx_TraceLine(3070,0,__PYX_ERR(0, 3070, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3071
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction
 */
        __Pyx_TraceLine(3071,0,__PYX_ERR(0, 3071, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3064
 *                 continue
 *             if dim == 2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":3073
 *                     V[2*ind + 1] = 0.5
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3073,0,__PYX_ERR(0, 3073, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_15 = 0; __pyx_t_15 < 2; __pyx_t_15+=1) {
          __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3073, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3074
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction
 *                         ind = next_cell.children[2*i].edges[2].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3074,0,__PYX_ERR(0, 3074, __pyx_L1_error))
          __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3074, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3074, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_8 = ((__pyx_v_next_cell->children[__pyx_t_16])->edges[2])->index;
          __pyx_v_ind = __pyx_t_8;

          /* "discretize/_extensions/tree_ext.pyx":3075
 *                     for i in range(2): # two neighbors in +x direction
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3075,0,__PYX_ERR(0, 3075, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3076
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 */
          __Pyx_TraceLine(3076,0,__PYX_ERR(0, 3076, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3077
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5
 */
          __Pyx_TraceLine(3077,0,__PYX_ERR(0, 3077, __pyx_L1_error))
          __pyx_t_14 = __pyx_v_cell->index;
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3078
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5
 */
          __Pyx_TraceLine(3078,0,__PYX_ERR(0, 3078, __pyx_L1_error))
          __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3078, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3078, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_14 = (__pyx_v_next_cell->children[__pyx_t_16])->index;
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3079
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = 0.5
 *             else:
 */
          __Pyx_TraceLine(3079,0,__PYX_ERR(0, 3079, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

          /* "discretize/_extensions/tree_ext.pyx":3080
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *             else:
 *                 if cell.neighbors[1].is_leaf():
 */
          __Pyx_TraceLine(3080,0,__PYX_ERR(0, 3080, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;
        }
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":3063
 *             if next_cell == NULL:
 *                 continue
 *             if dim == 2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":3082
 *                         V[2*ind + 1] = 0.5
 *             else:
 *                 if cell.neighbors[1].is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3082,0,__PYX_ERR(0, 3082, __pyx_L1_error))
    /*else*/ {
      __pyx_t_12 = ((__pyx_v_cell->neighbors[1])->is_leaf() != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":3083
 *             else:
 *                 if cell.neighbors[1].is_leaf():
 *                     ind = cell.faces[1].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3083,0,__PYX_ERR(0, 3083, __pyx_L1_error))
        __pyx_t_8 = (__pyx_v_cell->faces[1])->index;
        __pyx_v_ind = __pyx_t_8;

        /* "discretize/_extensions/tree_ext.pyx":3084
 *                 if cell.neighbors[1].is_leaf():
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3084,0,__PYX_ERR(0, 3084, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3085
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3085,0,__PYX_ERR(0, 3085, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3086
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 */
        __Pyx_TraceLine(3086,0,__PYX_ERR(0, 3086, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_cell->index;
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3087
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5
 */
        __Pyx_TraceLine(3087,0,__PYX_ERR(0, 3087, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_next_cell->index;
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3088
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = 0.5
 *                 else:
 */
        __Pyx_TraceLine(3088,0,__PYX_ERR(0, 3088, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3089
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction
 */
        __Pyx_TraceLine(3089,0,__PYX_ERR(0, 3089, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3082
 *                         V[2*ind + 1] = 0.5
 *             else:
 *                 if cell.neighbors[1].is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L10;
      }

      /* "discretize/_extensions/tree_ext.pyx":3091
 *                     V[2*ind + 1] = 0.5
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[2*i].faces[0].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3091,0,__PYX_ERR(0, 3091, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
          __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3091, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3092
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction
 *                         ind = next_cell.children[2*i].faces[0].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3092,0,__PYX_ERR(0, 3092, __pyx_L1_error))
          __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3092, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3092, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_8 = ((__pyx_v_next_cell->children[__pyx_t_16])->faces[0])->index;
          __pyx_v_ind = __pyx_t_8;

          /* "discretize/_extensions/tree_ext.pyx":3093
 *                     for i in range(4): # four neighbors in +x direction
 *                         ind = next_cell.children[2*i].faces[0].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3093,0,__PYX_ERR(0, 3093, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3094
 *                         ind = next_cell.children[2*i].faces[0].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 */
          __Pyx_TraceLine(3094,0,__PYX_ERR(0, 3094, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3095
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5
 */
          __Pyx_TraceLine(3095,0,__PYX_ERR(0, 3095, __pyx_L1_error))
          __pyx_t_14 = __pyx_v_cell->index;
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3096
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5
 */
          __Pyx_TraceLine(3096,0,__PYX_ERR(0, 3096, __pyx_L1_error))
          __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3096, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3096, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_14 = (__pyx_v_next_cell->children[__pyx_t_16])->index;
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3097
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = 0.5
 * 
 */
          __Pyx_TraceLine(3097,0,__PYX_ERR(0, 3097, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

          /* "discretize/_extensions/tree_ext.pyx":3098
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_x, self.n_cells))
 */
          __Pyx_TraceLine(3098,0,__PYX_ERR(0, 3098, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;
        }
      }
      __pyx_L10:;
    }
    __pyx_L6:;

    /* "discretize/_extensions/tree_ext.pyx":3059
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(3059,0,__PYX_ERR(0, 3059, __pyx_L1_error))
    __pyx_L3_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3100
 *                         V[2*ind + 1] = 0.5
 * 
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_x, self.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3100,0,__PYX_ERR(0, 3100, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_17) < 0) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
  __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_17;
  __pyx_t_17 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3040
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_x(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) x faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_total_face_x", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3103
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_y(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) y faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_39average_cell_to_total_face_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_38average_cell_to_total_face_y[] = "_TreeMesh.average_cell_to_total_face_y(self)\nAverage matrix for cell center to total (including hanging) y faces.\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_total_faces_y, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from faces to cell centers\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_39average_cell_to_total_face_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("average_cell_to_total_face_y (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_38average_cell_to_total_face_y(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_38average_cell_to_total_face_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_8;
  std::vector<Cell *> ::iterator __pyx_t_9;
  std::vector<Cell *>  *__pyx_t_10;
  Cell *__pyx_t_11;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PY_LONG_LONG __pyx_t_14;
  long __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("average_cell_to_total_face_y", 0);
  __Pyx_TraceCall("average_cell_to_total_face_y", __pyx_f[0], 3103, 0, __PYX_ERR(0, 3103, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3116
 *             The scalar averaging operator from faces to cell centers
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 */
  __Pyx_TraceLine(3116,0,__PYX_ERR(0, 3116, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3117
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(3117,0,__PYX_ERR(0, 3117, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3118
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3118,0,__PYX_ERR(0, 3118, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3118, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3119
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3119,0,__PYX_ERR(0, 3119, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_8;

  /* "discretize/_extensions/tree_ext.pyx":3122
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             if next_cell==NULL:
 */
  __Pyx_TraceLine(3122,0,__PYX_ERR(0, 3122, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->cells;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_cell = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3123
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]             # <<<<<<<<<<<<<<
 *             if next_cell==NULL:
 *                 continue
 */
    __Pyx_TraceLine(3123,0,__PYX_ERR(0, 3123, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[3]);

    /* "discretize/_extensions/tree_ext.pyx":3124
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim==2:
 */
    __Pyx_TraceLine(3124,0,__PYX_ERR(0, 3124, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":3125
 *             next_cell = cell.neighbors[3]
 *             if next_cell==NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if dim==2:
 *                 if next_cell.is_leaf():
 */
      __Pyx_TraceLine(3125,0,__PYX_ERR(0, 3125, __pyx_L1_error))
      goto __pyx_L3_continue;

      /* "discretize/_extensions/tree_ext.pyx":3124
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim==2:
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3126
 *             if next_cell==NULL:
 *                 continue
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 */
    __Pyx_TraceLine(3126,0,__PYX_ERR(0, 3126, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_dim == 2) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":3127
 *                 continue
 *             if dim==2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3127,0,__PYX_ERR(0, 3127, __pyx_L1_error))
      __pyx_t_12 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":3128
 *             if dim==2:
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3128,0,__PYX_ERR(0, 3128, __pyx_L1_error))
        __pyx_t_8 = (__pyx_v_cell->edges[1])->index;
        __pyx_v_ind = __pyx_t_8;

        /* "discretize/_extensions/tree_ext.pyx":3129
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3129,0,__PYX_ERR(0, 3129, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3130
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3130,0,__PYX_ERR(0, 3130, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3131
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 */
        __Pyx_TraceLine(3131,0,__PYX_ERR(0, 3131, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_cell->index;
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3132
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5
 */
        __Pyx_TraceLine(3132,0,__PYX_ERR(0, 3132, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_next_cell->index;
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3133
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = 0.5
 *                 else:
 */
        __Pyx_TraceLine(3133,0,__PYX_ERR(0, 3133, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3134
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction
 */
        __Pyx_TraceLine(3134,0,__PYX_ERR(0, 3134, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3127
 *                 continue
 *             if dim==2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":3136
 *                     V[2*ind + 1] = 0.5
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3136,0,__PYX_ERR(0, 3136, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_15 = 0; __pyx_t_15 < 2; __pyx_t_15+=1) {
          __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3136, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3137
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction
 *                         ind = next_cell.children[i].edges[0].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3137,0,__PYX_ERR(0, 3137, __pyx_L1_error))
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3137, __pyx_L1_error)
          __pyx_t_8 = ((__pyx_v_next_cell->children[__pyx_t_16])->edges[0])->index;
          __pyx_v_ind = __pyx_t_8;

          /* "discretize/_extensions/tree_ext.pyx":3138
 *                     for i in range(2): # two neighbors in +y direction
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3138,0,__PYX_ERR(0, 3138, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3139
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index
 */
          __Pyx_TraceLine(3139,0,__PYX_ERR(0, 3139, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3140
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = 0.5
 */
          __Pyx_TraceLine(3140,0,__PYX_ERR(0, 3140, __pyx_L1_error))
          __pyx_t_14 = __pyx_v_cell->index;
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3141
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5
 */
          __Pyx_TraceLine(3141,0,__PYX_ERR(0, 3141, __pyx_L1_error))
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3141, __pyx_L1_error)
          __pyx_t_14 = (__pyx_v_next_cell->children[__pyx_t_16])->index;
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3142
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = 0.5
 *             else:
 */
          __Pyx_TraceLine(3142,0,__PYX_ERR(0, 3142, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

          /* "discretize/_extensions/tree_ext.pyx":3143
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *             else:
 *                 if next_cell.is_leaf():
 */
          __Pyx_TraceLine(3143,0,__PYX_ERR(0, 3143, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;
        }
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":3126
 *             if next_cell==NULL:
 *                 continue
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":3145
 *                         V[2*ind + 1] = 0.5
 *             else:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3145,0,__PYX_ERR(0, 3145, __pyx_L1_error))
    /*else*/ {
      __pyx_t_12 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":3146
 *             else:
 *                 if next_cell.is_leaf():
 *                     ind = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3146,0,__PYX_ERR(0, 3146, __pyx_L1_error))
        __pyx_t_8 = (__pyx_v_cell->faces[3])->index;
        __pyx_v_ind = __pyx_t_8;

        /* "discretize/_extensions/tree_ext.pyx":3147
 *                 if next_cell.is_leaf():
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3147,0,__PYX_ERR(0, 3147, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3148
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3148,0,__PYX_ERR(0, 3148, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3149
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 */
        __Pyx_TraceLine(3149,0,__PYX_ERR(0, 3149, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_cell->index;
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3150
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5
 */
        __Pyx_TraceLine(3150,0,__PYX_ERR(0, 3150, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_next_cell->index;
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3151
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = 0.5
 *                 else:
 */
        __Pyx_TraceLine(3151,0,__PYX_ERR(0, 3151, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3152
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction
 */
        __Pyx_TraceLine(3152,0,__PYX_ERR(0, 3152, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3145
 *                         V[2*ind + 1] = 0.5
 *             else:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L10;
      }

      /* "discretize/_extensions/tree_ext.pyx":3154
 *                     V[2*ind + 1] = 0.5
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3154,0,__PYX_ERR(0, 3154, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
          __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3154, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3155
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3155,0,__PYX_ERR(0, 3155, __pyx_L1_error))
          __pyx_t_2 = __Pyx_PyInt_RshiftObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3155, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3155, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3155, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3155, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3155, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_8 = ((__pyx_v_next_cell->children[__pyx_t_16])->faces[2])->index;
          __pyx_v_ind = __pyx_t_8;

          /* "discretize/_extensions/tree_ext.pyx":3156
 *                     for i in range(4): # four neighbors in +y direction
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3156,0,__PYX_ERR(0, 3156, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3157
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 */
          __Pyx_TraceLine(3157,0,__PYX_ERR(0, 3157, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3158
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = 0.5
 */
          __Pyx_TraceLine(3158,0,__PYX_ERR(0, 3158, __pyx_L1_error))
          __pyx_t_14 = __pyx_v_cell->index;
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3159
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5
 */
          __Pyx_TraceLine(3159,0,__PYX_ERR(0, 3159, __pyx_L1_error))
          __pyx_t_4 = __Pyx_PyInt_RshiftObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3159, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_2 = PyNumber_Multiply(__pyx_t_4, __pyx_int_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3159, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3159, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3159, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3159, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_14 = (__pyx_v_next_cell->children[__pyx_t_16])->index;
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

          /* "discretize/_extensions/tree_ext.pyx":3160
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = 0.5
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))
 */
          __Pyx_TraceLine(3160,0,__PYX_ERR(0, 3160, __pyx_L1_error))
          __pyx_t_13 = (2 * __pyx_v_ind);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

          /* "discretize/_extensions/tree_ext.pyx":3161
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))
 * 
 */
          __Pyx_TraceLine(3161,0,__PYX_ERR(0, 3161, __pyx_L1_error))
          __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;
        }
      }
      __pyx_L10:;
    }
    __pyx_L6:;

    /* "discretize/_extensions/tree_ext.pyx":3122
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             if next_cell==NULL:
 */
    __Pyx_TraceLine(3122,0,__PYX_ERR(0, 3122, __pyx_L1_error))
    __pyx_L3_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3162
 *                         V[2*ind    ] = 0.5
 *                         V[2*ind + 1] = 0.5
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3162,0,__PYX_ERR(0, 3162, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_2);
  __pyx_t_5 = 0;
  __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_17) < 0) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
  __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_17;
  __pyx_t_17 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3103
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_y(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) y faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_total_face_y", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3165
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_z(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) z faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_41average_cell_to_total_face_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_40average_cell_to_total_face_z[] = "_TreeMesh.average_cell_to_total_face_z(self)\nAverage matrix for cell center to total (including hanging) z faces.\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_total_faces_z, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from faces to cell centers\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_41average_cell_to_total_face_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("average_cell_to_total_face_z (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_40average_cell_to_total_face_z(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_40average_cell_to_total_face_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_8;
  std::vector<Cell *>  *__pyx_t_9;
  Cell *__pyx_t_10;
  int __pyx_t_11;
  int_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PY_LONG_LONG __pyx_t_14;
  long __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("average_cell_to_total_face_z", 0);
  __Pyx_TraceCall("average_cell_to_total_face_z", __pyx_f[0], 3165, 0, __PYX_ERR(0, 3165, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3178
 *             The scalar averaging operator from faces to cell centers
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 */
  __Pyx_TraceLine(3178,0,__PYX_ERR(0, 3178, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3179
 *         """
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3179,0,__PYX_ERR(0, 3179, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3179, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3180
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3180,0,__PYX_ERR(0, 3180, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3183
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 */
  __Pyx_TraceLine(3183,0,__PYX_ERR(0, 3183, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->cells;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_cell = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":3184
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]             # <<<<<<<<<<<<<<
 *             if next_cell==NULL:
 *                 continue
 */
    __Pyx_TraceLine(3184,0,__PYX_ERR(0, 3184, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[5]);

    /* "discretize/_extensions/tree_ext.pyx":3185
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if next_cell.is_leaf():
 */
    __Pyx_TraceLine(3185,0,__PYX_ERR(0, 3185, __pyx_L1_error))
    __pyx_t_11 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_11) {

      /* "discretize/_extensions/tree_ext.pyx":3186
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index
 */
      __Pyx_TraceLine(3186,0,__PYX_ERR(0, 3186, __pyx_L1_error))
      goto __pyx_L3_continue;

      /* "discretize/_extensions/tree_ext.pyx":3185
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if next_cell.is_leaf():
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3187
 *             if next_cell==NULL:
 *                 continue
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3187,0,__PYX_ERR(0, 3187, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_next_cell->is_leaf() != 0);
    if (__pyx_t_11) {

      /* "discretize/_extensions/tree_ext.pyx":3188
 *                 continue
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index             # <<<<<<<<<<<<<<
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind
 */
      __Pyx_TraceLine(3188,0,__PYX_ERR(0, 3188, __pyx_L1_error))
      __pyx_t_12 = (__pyx_v_cell->faces[5])->index;
      __pyx_v_ind = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3189
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index
 */
      __Pyx_TraceLine(3189,0,__PYX_ERR(0, 3189, __pyx_L1_error))
      __pyx_t_13 = (2 * __pyx_v_ind);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3190
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index
 */
      __Pyx_TraceLine(3190,0,__PYX_ERR(0, 3190, __pyx_L1_error))
      __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3191
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = 0.5
 */
      __Pyx_TraceLine(3191,0,__PYX_ERR(0, 3191, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_cell->index;
      __pyx_t_13 = (2 * __pyx_v_ind);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":3192
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind    ] = 0.5
 *                 V[2*ind + 1] = 0.5
 */
      __Pyx_TraceLine(3192,0,__PYX_ERR(0, 3192, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_next_cell->index;
      __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":3193
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                 V[2*ind + 1] = 0.5
 *             else:
 */
      __Pyx_TraceLine(3193,0,__PYX_ERR(0, 3193, __pyx_L1_error))
      __pyx_t_13 = (2 * __pyx_v_ind);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

      /* "discretize/_extensions/tree_ext.pyx":3194
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = 0.5
 *                 V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 *             else:
 *                 for i in range(4): # four neighbors in +z direction
 */
      __Pyx_TraceLine(3194,0,__PYX_ERR(0, 3194, __pyx_L1_error))
      __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

      /* "discretize/_extensions/tree_ext.pyx":3187
 *             if next_cell==NULL:
 *                 continue
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":3196
 *                 V[2*ind + 1] = 0.5
 *             else:
 *                 for i in range(4): # four neighbors in +z direction             # <<<<<<<<<<<<<<
 *                     ind = next_cell.children[i].faces[4].index
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3196,0,__PYX_ERR(0, 3196, __pyx_L1_error))
    /*else*/ {
      for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
        __pyx_v_i = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3197
 *             else:
 *                 for i in range(4): # four neighbors in +z direction
 *                     ind = next_cell.children[i].faces[4].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3197,0,__PYX_ERR(0, 3197, __pyx_L1_error))
        __pyx_t_12 = ((__pyx_v_next_cell->children[__pyx_v_i])->faces[4])->index;
        __pyx_v_ind = __pyx_t_12;

        /* "discretize/_extensions/tree_ext.pyx":3198
 *                 for i in range(4): # four neighbors in +z direction
 *                     ind = next_cell.children[i].faces[4].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3198,0,__PYX_ERR(0, 3198, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3199
 *                     ind = next_cell.children[i].faces[4].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index
 */
        __Pyx_TraceLine(3199,0,__PYX_ERR(0, 3199, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3200
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = 0.5
 */
        __Pyx_TraceLine(3200,0,__PYX_ERR(0, 3200, __pyx_L1_error))
        __pyx_t_14 = __pyx_v_cell->index;
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3201
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5
 */
        __Pyx_TraceLine(3201,0,__PYX_ERR(0, 3201, __pyx_L1_error))
        __pyx_t_14 = (__pyx_v_next_cell->children[__pyx_v_i])->index;
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

        /* "discretize/_extensions/tree_ext.pyx":3202
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = 0.5             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = 0.5
 * 
 */
        __Pyx_TraceLine(3202,0,__PYX_ERR(0, 3202, __pyx_L1_error))
        __pyx_t_13 = (2 * __pyx_v_ind);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

        /* "discretize/_extensions/tree_ext.pyx":3203
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = 0.5
 *                     V[2*ind + 1] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_z, self.n_cells))
 */
        __Pyx_TraceLine(3203,0,__PYX_ERR(0, 3203, __pyx_L1_error))
        __pyx_t_13 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;
      }
    }
    __pyx_L6:;

    /* "discretize/_extensions/tree_ext.pyx":3183
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 */
    __Pyx_TraceLine(3183,0,__PYX_ERR(0, 3183, __pyx_L1_error))
    __pyx_L3_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3205
 *                     V[2*ind + 1] = 0.5
 * 
 *         return sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_z, self.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3205,0,__PYX_ERR(0, 3205, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_16) < 0) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_16;
  __pyx_t_16 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3165
 * 
 *     @cython.boundscheck(False)
 *     def average_cell_to_total_face_z(self):             # <<<<<<<<<<<<<<
 *         """Average matrix for cell center to total (including hanging) z faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_total_face_z", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3209
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_x(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along x-direction to total (including hanging) x faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_10;
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  long __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3209, 0, __PYX_ERR(0, 3209, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3230
 *             The stencil for the x-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_x', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
  __Pyx_TraceLine(3230,0,__PYX_ERR(0, 3230, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_u_stencil_cell_gradient_x, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":3231
 *         """
 *         if getattr(self, '_stencil_cell_gradient_x', None) is not None:
 *             return self._stencil_cell_gradient_x             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
    __Pyx_TraceLine(3231,0,__PYX_ERR(0, 3231, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3230
 *             The stencil for the x-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_x', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3232
 *         if getattr(self, '_stencil_cell_gradient_x', None) is not None:
 *             return self._stencil_cell_gradient_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 */
  __Pyx_TraceLine(3232,0,__PYX_ERR(0, 3232, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3232, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3233
 *             return self._stencil_cell_gradient_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(3233,0,__PYX_ERR(0, 3233, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3233, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3234
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3234,0,__PYX_ERR(0, 3234, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3235
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3235,0,__PYX_ERR(0, 3235, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":3238
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 */
  __Pyx_TraceLine(3238,0,__PYX_ERR(0, 3238, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3239
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]             # <<<<<<<<<<<<<<
 *             if next_cell == NULL:
 *                 continue
 */
    __Pyx_TraceLine(3239,0,__PYX_ERR(0, 3239, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[1]);

    /* "discretize/_extensions/tree_ext.pyx":3240
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim == 2:
 */
    __Pyx_TraceLine(3240,0,__PYX_ERR(0, 3240, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3241
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if dim == 2:
 *                 if next_cell.is_leaf():
 */
      __Pyx_TraceLine(3241,0,__PYX_ERR(0, 3241, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":3240
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim == 2:
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3242
 *             if next_cell == NULL:
 *                 continue
 *             if dim == 2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 */
    __Pyx_TraceLine(3242,0,__PYX_ERR(0, 3242, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_dim == 2) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3243
 *                 continue
 *             if dim == 2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3243,0,__PYX_ERR(0, 3243, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":3244
 *             if dim == 2:
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3244,0,__PYX_ERR(0, 3244, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[3])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":3245
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3245,0,__PYX_ERR(0, 3245, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3246
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3246,0,__PYX_ERR(0, 3246, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3247
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 */
        __Pyx_TraceLine(3247,0,__PYX_ERR(0, 3247, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3248
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0
 */
        __Pyx_TraceLine(3248,0,__PYX_ERR(0, 3248, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3249
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] =  1.0
 *                 else:
 */
        __Pyx_TraceLine(3249,0,__PYX_ERR(0, 3249, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

        /* "discretize/_extensions/tree_ext.pyx":3250
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction
 */
        __Pyx_TraceLine(3250,0,__PYX_ERR(0, 3250, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":3243
 *                 continue
 *             if dim == 2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L8;
      }

      /* "discretize/_extensions/tree_ext.pyx":3252
 *                     V[2*ind + 1] =  1.0
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3252,0,__PYX_ERR(0, 3252, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_16 = 0; __pyx_t_16 < 2; __pyx_t_16+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3252, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3253
 *                 else:
 *                     for i in range(2): # two neighbors in +x direction
 *                         ind = next_cell.children[2*i].edges[2].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3253,0,__PYX_ERR(0, 3253, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3253, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3253, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_10 = ((__pyx_v_next_cell->children[__pyx_t_17])->edges[2])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":3254
 *                     for i in range(2): # two neighbors in +x direction
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3254,0,__PYX_ERR(0, 3254, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3255
 *                         ind = next_cell.children[2*i].edges[2].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 */
          __Pyx_TraceLine(3255,0,__PYX_ERR(0, 3255, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3256
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0
 */
          __Pyx_TraceLine(3256,0,__PYX_ERR(0, 3256, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3257
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0
 */
          __Pyx_TraceLine(3257,0,__PYX_ERR(0, 3257, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3257, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3257, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_15 = (__pyx_v_next_cell->children[__pyx_t_17])->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3258
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] =  1.0
 *             else:
 */
          __Pyx_TraceLine(3258,0,__PYX_ERR(0, 3258, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

          /* "discretize/_extensions/tree_ext.pyx":3259
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *             else:
 *                 if cell.neighbors[1].is_leaf():
 */
          __Pyx_TraceLine(3259,0,__PYX_ERR(0, 3259, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;
        }
      }
      __pyx_L8:;

      /* "discretize/_extensions/tree_ext.pyx":3242
 *             if next_cell == NULL:
 *                 continue
 *             if dim == 2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[3].index
 */
      goto __pyx_L7;
    }

    /* "discretize/_extensions/tree_ext.pyx":3261
 *                         V[2*ind + 1] =  1.0
 *             else:
 *                 if cell.neighbors[1].is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3261,0,__PYX_ERR(0, 3261, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = ((__pyx_v_cell->neighbors[1])->is_leaf() != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":3262
 *             else:
 *                 if cell.neighbors[1].is_leaf():
 *                     ind = cell.faces[1].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3262,0,__PYX_ERR(0, 3262, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->faces[1])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":3263
 *                 if cell.neighbors[1].is_leaf():
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3263,0,__PYX_ERR(0, 3263, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3264
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3264,0,__PYX_ERR(0, 3264, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3265
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 */
        __Pyx_TraceLine(3265,0,__PYX_ERR(0, 3265, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3266
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0
 */
        __Pyx_TraceLine(3266,0,__PYX_ERR(0, 3266, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3267
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] =  1.0
 *                 else:
 */
        __Pyx_TraceLine(3267,0,__PYX_ERR(0, 3267, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

        /* "discretize/_extensions/tree_ext.pyx":3268
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction
 */
        __Pyx_TraceLine(3268,0,__PYX_ERR(0, 3268, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":3261
 *                         V[2*ind + 1] =  1.0
 *             else:
 *                 if cell.neighbors[1].is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[1].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L11;
      }

      /* "discretize/_extensions/tree_ext.pyx":3270
 *                     V[2*ind + 1] =  1.0
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[2*i].faces[0].index #0 2 4 6
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3270,0,__PYX_ERR(0, 3270, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_16 = 0; __pyx_t_16 < 4; __pyx_t_16+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3270, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3271
 *                 else:
 *                     for i in range(4): # four neighbors in +x direction
 *                         ind = next_cell.children[2*i].faces[0].index #0 2 4 6             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3271,0,__PYX_ERR(0, 3271, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3271, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3271, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_10 = ((__pyx_v_next_cell->children[__pyx_t_17])->faces[0])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":3272
 *                     for i in range(4): # four neighbors in +x direction
 *                         ind = next_cell.children[2*i].faces[0].index #0 2 4 6
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3272,0,__PYX_ERR(0, 3272, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3273
 *                         ind = next_cell.children[2*i].faces[0].index #0 2 4 6
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 */
          __Pyx_TraceLine(3273,0,__PYX_ERR(0, 3273, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3274
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0
 */
          __Pyx_TraceLine(3274,0,__PYX_ERR(0, 3274, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3275
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0
 */
          __Pyx_TraceLine(3275,0,__PYX_ERR(0, 3275, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3275, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3275, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_15 = (__pyx_v_next_cell->children[__pyx_t_17])->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3276
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] =  1.0
 * 
 */
          __Pyx_TraceLine(3276,0,__PYX_ERR(0, 3276, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

          /* "discretize/_extensions/tree_ext.pyx":3277
 *                         J[2*ind + 1] = next_cell.children[2*i].index
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 * 
 *         self._stencil_cell_gradient_x = (
 */
          __Pyx_TraceLine(3277,0,__PYX_ERR(0, 3277, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;
        }
      }
      __pyx_L11:;
    }
    __pyx_L7:;

    /* "discretize/_extensions/tree_ext.pyx":3238
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(3238,0,__PYX_ERR(0, 3238, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3280
 * 
 *         self._stencil_cell_gradient_x = (
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_x, self.n_cells))             # <<<<<<<<<<<<<<
 *         )
 *         return self._stencil_cell_gradient_x
 */
  __Pyx_TraceLine(3280,0,__PYX_ERR(0, 3280, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __pyx_t_6 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3279
 *                         V[2*ind + 1] =  1.0
 * 
 *         self._stencil_cell_gradient_x = (             # <<<<<<<<<<<<<<
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_x, self.n_cells))
 *         )
 */
  __Pyx_TraceLine(3279,0,__PYX_ERR(0, 3279, __pyx_L1_error))
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_x, __pyx_t_18) < 0) __PYX_ERR(0, 3279, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3282
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_x, self.n_cells))
 *         )
 *         return self._stencil_cell_gradient_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3282,0,__PYX_ERR(0, 3282, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_18 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_x); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __pyx_r = __pyx_t_18;
  __pyx_t_18 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3209
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_x(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along x-direction to total (including hanging) x faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.stencil_cell_gradient_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3286
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_y(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along y-direction to total (including hanging) y faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_10;
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  long __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3286, 0, __PYX_ERR(0, 3286, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3307
 *             The stencil for the y-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_y', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_y
 * 
 */
  __Pyx_TraceLine(3307,0,__PYX_ERR(0, 3307, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_u_stencil_cell_gradient_y, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":3308
 *         """
 *         if getattr(self, '_stencil_cell_gradient_y', None) is not None:
 *             return self._stencil_cell_gradient_y             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 */
    __Pyx_TraceLine(3308,0,__PYX_ERR(0, 3308, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3307
 *             The stencil for the y-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_y', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_y
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3310
 *             return self._stencil_cell_gradient_y
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 */
  __Pyx_TraceLine(3310,0,__PYX_ERR(0, 3310, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3310, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3311
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(3311,0,__PYX_ERR(0, 3311, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3311, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3312
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3312,0,__PYX_ERR(0, 3312, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3312, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3313
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3313,0,__PYX_ERR(0, 3313, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":3316
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             if next_cell == NULL:
 */
  __Pyx_TraceLine(3316,0,__PYX_ERR(0, 3316, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3317
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]             # <<<<<<<<<<<<<<
 *             if next_cell == NULL:
 *                 continue
 */
    __Pyx_TraceLine(3317,0,__PYX_ERR(0, 3317, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[3]);

    /* "discretize/_extensions/tree_ext.pyx":3318
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim==2:
 */
    __Pyx_TraceLine(3318,0,__PYX_ERR(0, 3318, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3319
 *             next_cell = cell.neighbors[3]
 *             if next_cell == NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if dim==2:
 *                 if next_cell.is_leaf():
 */
      __Pyx_TraceLine(3319,0,__PYX_ERR(0, 3319, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":3318
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if dim==2:
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3320
 *             if next_cell == NULL:
 *                 continue
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 */
    __Pyx_TraceLine(3320,0,__PYX_ERR(0, 3320, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_dim == 2) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3321
 *                 continue
 *             if dim==2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3321,0,__PYX_ERR(0, 3321, __pyx_L1_error))
      __pyx_t_3 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":3322
 *             if dim==2:
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3322,0,__PYX_ERR(0, 3322, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[1])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":3323
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3323,0,__PYX_ERR(0, 3323, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3324
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3324,0,__PYX_ERR(0, 3324, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3325
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 */
        __Pyx_TraceLine(3325,0,__PYX_ERR(0, 3325, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3326
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0
 */
        __Pyx_TraceLine(3326,0,__PYX_ERR(0, 3326, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3327
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] =  1.0
 *                 else:
 */
        __Pyx_TraceLine(3327,0,__PYX_ERR(0, 3327, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

        /* "discretize/_extensions/tree_ext.pyx":3328
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction
 */
        __Pyx_TraceLine(3328,0,__PYX_ERR(0, 3328, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":3321
 *                 continue
 *             if dim==2:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L8;
      }

      /* "discretize/_extensions/tree_ext.pyx":3330
 *                     V[2*ind + 1] =  1.0
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3330,0,__PYX_ERR(0, 3330, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_16 = 0; __pyx_t_16 < 2; __pyx_t_16+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3330, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3331
 *                 else:
 *                     for i in range(2): # two neighbors in +y direction
 *                         ind = next_cell.children[i].edges[0].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3331,0,__PYX_ERR(0, 3331, __pyx_L1_error))
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3331, __pyx_L1_error)
          __pyx_t_10 = ((__pyx_v_next_cell->children[__pyx_t_17])->edges[0])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":3332
 *                     for i in range(2): # two neighbors in +y direction
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3332,0,__PYX_ERR(0, 3332, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3333
 *                         ind = next_cell.children[i].edges[0].index
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index
 */
          __Pyx_TraceLine(3333,0,__PYX_ERR(0, 3333, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3334
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = -1.0
 */
          __Pyx_TraceLine(3334,0,__PYX_ERR(0, 3334, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3335
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0
 */
          __Pyx_TraceLine(3335,0,__PYX_ERR(0, 3335, __pyx_L1_error))
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3335, __pyx_L1_error)
          __pyx_t_15 = (__pyx_v_next_cell->children[__pyx_t_17])->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3336
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] =  1.0
 *             else:
 */
          __Pyx_TraceLine(3336,0,__PYX_ERR(0, 3336, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

          /* "discretize/_extensions/tree_ext.pyx":3337
 *                         J[2*ind + 1] = next_cell.children[i].index
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *             else:
 *                 if next_cell.is_leaf():
 */
          __Pyx_TraceLine(3337,0,__PYX_ERR(0, 3337, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;
        }
      }
      __pyx_L8:;

      /* "discretize/_extensions/tree_ext.pyx":3320
 *             if next_cell == NULL:
 *                 continue
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 if next_cell.is_leaf():
 *                     ind = cell.edges[1].index
 */
      goto __pyx_L7;
    }

    /* "discretize/_extensions/tree_ext.pyx":3339
 *                         V[2*ind + 1] =  1.0
 *             else:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3339,0,__PYX_ERR(0, 3339, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = (__pyx_v_next_cell->is_leaf() != 0);
      if (__pyx_t_3) {

        /* "discretize/_extensions/tree_ext.pyx":3340
 *             else:
 *                 if next_cell.is_leaf():
 *                     ind = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3340,0,__PYX_ERR(0, 3340, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->faces[3])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":3341
 *                 if next_cell.is_leaf():
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3341,0,__PYX_ERR(0, 3341, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3342
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 */
        __Pyx_TraceLine(3342,0,__PYX_ERR(0, 3342, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3343
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 */
        __Pyx_TraceLine(3343,0,__PYX_ERR(0, 3343, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3344
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0
 */
        __Pyx_TraceLine(3344,0,__PYX_ERR(0, 3344, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3345
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] =  1.0
 *                 else:
 */
        __Pyx_TraceLine(3345,0,__PYX_ERR(0, 3345, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

        /* "discretize/_extensions/tree_ext.pyx":3346
 *                     J[2*ind + 1] = next_cell.index
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction
 */
        __Pyx_TraceLine(3346,0,__PYX_ERR(0, 3346, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":3339
 *                         V[2*ind + 1] =  1.0
 *             else:
 *                 if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                     ind = cell.faces[3].index
 *                     I[2*ind    ] = ind
 */
        goto __pyx_L11;
      }

      /* "discretize/_extensions/tree_ext.pyx":3348
 *                     V[2*ind + 1] =  1.0
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction             # <<<<<<<<<<<<<<
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index #0, 1, 4, 5
 *                         I[2*ind    ] = ind
 */
      __Pyx_TraceLine(3348,0,__PYX_ERR(0, 3348, __pyx_L1_error))
      /*else*/ {
        for (__pyx_t_16 = 0; __pyx_t_16 < 4; __pyx_t_16+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3348, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":3349
 *                 else:
 *                     for i in range(4): # four neighbors in +y direction
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index #0, 1, 4, 5             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 */
          __Pyx_TraceLine(3349,0,__PYX_ERR(0, 3349, __pyx_L1_error))
          __pyx_t_4 = __Pyx_PyInt_RshiftObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3349, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_7 = PyNumber_Multiply(__pyx_t_4, __pyx_int_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3349, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3349, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_6 = PyNumber_Add(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3349, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3349, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_10 = ((__pyx_v_next_cell->children[__pyx_t_17])->faces[2])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":3350
 *                     for i in range(4): # four neighbors in +y direction
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index #0, 1, 4, 5
 *                         I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(3350,0,__PYX_ERR(0, 3350, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3351
 *                         ind = next_cell.children[(i>>1)*4 + i%2].faces[2].index #0, 1, 4, 5
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 */
          __Pyx_TraceLine(3351,0,__PYX_ERR(0, 3351, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

          /* "discretize/_extensions/tree_ext.pyx":3352
 *                         I[2*ind    ] = ind
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = -1.0
 */
          __Pyx_TraceLine(3352,0,__PYX_ERR(0, 3352, __pyx_L1_error))
          __pyx_t_15 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3353
 *                         I[2*ind + 1] = ind
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] = 1.0
 */
          __Pyx_TraceLine(3353,0,__PYX_ERR(0, 3353, __pyx_L1_error))
          __pyx_t_6 = __Pyx_PyInt_RshiftObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3353, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_4 = PyNumber_Multiply(__pyx_t_6, __pyx_int_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3353, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3353, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PyNumber_Add(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3353, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_t_7); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3353, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_15 = (__pyx_v_next_cell->children[__pyx_t_17])->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

          /* "discretize/_extensions/tree_ext.pyx":3354
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = 1.0
 * 
 */
          __Pyx_TraceLine(3354,0,__PYX_ERR(0, 3354, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

          /* "discretize/_extensions/tree_ext.pyx":3355
 *                         J[2*ind + 1] = next_cell.children[(i>>1)*4 + i%2].index
 *                         V[2*ind    ] = -1.0
 *                         V[2*ind + 1] = 1.0             # <<<<<<<<<<<<<<
 * 
 *         self._stencil_cell_gradient_y = (
 */
          __Pyx_TraceLine(3355,0,__PYX_ERR(0, 3355, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;
        }
      }
      __pyx_L11:;
    }
    __pyx_L7:;

    /* "discretize/_extensions/tree_ext.pyx":3316
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(3316,0,__PYX_ERR(0, 3316, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3358
 * 
 *         self._stencil_cell_gradient_y = (
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))             # <<<<<<<<<<<<<<
 *         )
 *         return self._stencil_cell_gradient_y
 */
  __Pyx_TraceLine(3358,0,__PYX_ERR(0, 3358, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_4);
  __pyx_t_7 = 0;
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3357
 *                         V[2*ind + 1] = 1.0
 * 
 *         self._stencil_cell_gradient_y = (             # <<<<<<<<<<<<<<
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))
 *         )
 */
  __Pyx_TraceLine(3357,0,__PYX_ERR(0, 3357, __pyx_L1_error))
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_y, __pyx_t_18) < 0) __PYX_ERR(0, 3357, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3360
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_y, self.n_cells))
 *         )
 *         return self._stencil_cell_gradient_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3360,0,__PYX_ERR(0, 3360, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_18 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_y); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3360, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __pyx_r = __pyx_t_18;
  __pyx_t_18 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3286
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_y(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along y-direction to total (including hanging) y faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.stencil_cell_gradient_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3364
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_z(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along z-direction to total (including hanging) z faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_ind;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_next_cell;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  int_t __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  long __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3364, 0, __PYX_ERR(0, 3364, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3385
 *             The stencil for the z-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_z', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_z
 * 
 */
  __Pyx_TraceLine(3385,0,__PYX_ERR(0, 3385, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_u_stencil_cell_gradient_z, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":3386
 *         """
 *         if getattr(self, '_stencil_cell_gradient_z', None) is not None:
 *             return self._stencil_cell_gradient_z             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 */
    __Pyx_TraceLine(3386,0,__PYX_ERR(0, 3386, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3385
 *             The stencil for the z-component of the cell gradient
 *         """
 *         if getattr(self, '_stencil_cell_gradient_z', None) is not None:             # <<<<<<<<<<<<<<
 *             return self._stencil_cell_gradient_z
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3388
 *             return self._stencil_cell_gradient_z
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 */
  __Pyx_TraceLine(3388,0,__PYX_ERR(0, 3388, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3389
 * 
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 *         cdef int_t ind
 */
  __Pyx_TraceLine(3389,0,__PYX_ERR(0, 3389, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3389, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3390
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int_t ind
 * 
 */
  __Pyx_TraceLine(3390,0,__PYX_ERR(0, 3390, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3390, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3393
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 */
  __Pyx_TraceLine(3393,0,__PYX_ERR(0, 3393, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3394
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]             # <<<<<<<<<<<<<<
 *             if next_cell==NULL:
 *                 continue
 */
    __Pyx_TraceLine(3394,0,__PYX_ERR(0, 3394, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[5]);

    /* "discretize/_extensions/tree_ext.pyx":3395
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if next_cell.is_leaf():
 */
    __Pyx_TraceLine(3395,0,__PYX_ERR(0, 3395, __pyx_L1_error))
    __pyx_t_3 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3396
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 *                 continue             # <<<<<<<<<<<<<<
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index
 */
      __Pyx_TraceLine(3396,0,__PYX_ERR(0, 3396, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":3395
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:             # <<<<<<<<<<<<<<
 *                 continue
 *             if next_cell.is_leaf():
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3397
 *             if next_cell==NULL:
 *                 continue
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3397,0,__PYX_ERR(0, 3397, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_next_cell->is_leaf() != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":3398
 *                 continue
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index             # <<<<<<<<<<<<<<
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind
 */
      __Pyx_TraceLine(3398,0,__PYX_ERR(0, 3398, __pyx_L1_error))
      __pyx_t_13 = (__pyx_v_cell->faces[5])->index;
      __pyx_v_ind = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":3399
 *             if next_cell.is_leaf():
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index
 */
      __Pyx_TraceLine(3399,0,__PYX_ERR(0, 3399, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3400
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index
 */
      __Pyx_TraceLine(3400,0,__PYX_ERR(0, 3400, __pyx_L1_error))
      __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3401
 *                 I[2*ind    ] = ind
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = -1.0
 */
      __Pyx_TraceLine(3401,0,__PYX_ERR(0, 3401, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":3402
 *                 I[2*ind + 1] = ind
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind    ] = -1.0
 *                 V[2*ind + 1] =  1.0
 */
      __Pyx_TraceLine(3402,0,__PYX_ERR(0, 3402, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_next_cell->index;
      __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":3403
 *                 J[2*ind    ] = cell.index
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                 V[2*ind + 1] =  1.0
 *             else:
 */
      __Pyx_TraceLine(3403,0,__PYX_ERR(0, 3403, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

      /* "discretize/_extensions/tree_ext.pyx":3404
 *                 J[2*ind + 1] = next_cell.index
 *                 V[2*ind    ] = -1.0
 *                 V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 *             else:
 *                 for i in range(4): # four neighbors in +z direction
 */
      __Pyx_TraceLine(3404,0,__PYX_ERR(0, 3404, __pyx_L1_error))
      __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":3397
 *             if next_cell==NULL:
 *                 continue
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index
 *                 I[2*ind    ] = ind
 */
      goto __pyx_L7;
    }

    /* "discretize/_extensions/tree_ext.pyx":3406
 *                 V[2*ind + 1] =  1.0
 *             else:
 *                 for i in range(4): # four neighbors in +z direction             # <<<<<<<<<<<<<<
 *                     ind = next_cell.children[i].faces[4].index #0, 1, 2, 3
 *                     I[2*ind    ] = ind
 */
    __Pyx_TraceLine(3406,0,__PYX_ERR(0, 3406, __pyx_L1_error))
    /*else*/ {
      for (__pyx_t_16 = 0; __pyx_t_16 < 4; __pyx_t_16+=1) {
        __pyx_v_i = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":3407
 *             else:
 *                 for i in range(4): # four neighbors in +z direction
 *                     ind = next_cell.children[i].faces[4].index #0, 1, 2, 3             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 */
        __Pyx_TraceLine(3407,0,__PYX_ERR(0, 3407, __pyx_L1_error))
        __pyx_t_13 = ((__pyx_v_next_cell->children[__pyx_v_i])->faces[4])->index;
        __pyx_v_ind = __pyx_t_13;

        /* "discretize/_extensions/tree_ext.pyx":3408
 *                 for i in range(4): # four neighbors in +z direction
 *                     ind = next_cell.children[i].faces[4].index #0, 1, 2, 3
 *                     I[2*ind    ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(3408,0,__PYX_ERR(0, 3408, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3409
 *                     ind = next_cell.children[i].faces[4].index #0, 1, 2, 3
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index
 */
        __Pyx_TraceLine(3409,0,__PYX_ERR(0, 3409, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":3410
 *                     I[2*ind    ] = ind
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = -1.0
 */
        __Pyx_TraceLine(3410,0,__PYX_ERR(0, 3410, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3411
 *                     I[2*ind + 1] = ind
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0
 */
        __Pyx_TraceLine(3411,0,__PYX_ERR(0, 3411, __pyx_L1_error))
        __pyx_t_15 = (__pyx_v_next_cell->children[__pyx_v_i])->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

        /* "discretize/_extensions/tree_ext.pyx":3412
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = -1.0             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] =  1.0
 * 
 */
        __Pyx_TraceLine(3412,0,__PYX_ERR(0, 3412, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = -1.0;

        /* "discretize/_extensions/tree_ext.pyx":3413
 *                     J[2*ind + 1] = next_cell.children[i].index
 *                     V[2*ind    ] = -1.0
 *                     V[2*ind + 1] =  1.0             # <<<<<<<<<<<<<<
 * 
 *         self._stencil_cell_gradient_z = (
 */
        __Pyx_TraceLine(3413,0,__PYX_ERR(0, 3413, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;
      }
    }
    __pyx_L7:;

    /* "discretize/_extensions/tree_ext.pyx":3393
 *         cdef int_t ind
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             if next_cell==NULL:
 */
    __Pyx_TraceLine(3393,0,__PYX_ERR(0, 3393, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3416
 * 
 *         self._stencil_cell_gradient_z = (
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_z, self.n_cells))             # <<<<<<<<<<<<<<
 *         )
 *         return self._stencil_cell_gradient_z
 */
  __Pyx_TraceLine(3416,0,__PYX_ERR(0, 3416, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __pyx_t_6 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_17) < 0) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
  __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3415
 *                     V[2*ind + 1] =  1.0
 * 
 *         self._stencil_cell_gradient_z = (             # <<<<<<<<<<<<<<
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_z, self.n_cells))
 *         )
 */
  __Pyx_TraceLine(3415,0,__PYX_ERR(0, 3415, __pyx_L1_error))
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_z, __pyx_t_17) < 0) __PYX_ERR(0, 3415, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3418
 *             sp.csr_matrix((V, (I,J)), shape=(self.n_total_faces_z, self.n_cells))
 *         )
 *         return self._stencil_cell_gradient_z             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3418,0,__PYX_ERR(0, 3418, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_17 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stencil_cell_gradient_z); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __pyx_r = __pyx_t_17;
  __pyx_t_17 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3364
 *     @property
 *     @cython.boundscheck(False)
 *     def stencil_cell_gradient_z(self):             # <<<<<<<<<<<<<<
 *         r"""Differencing operator along z-direction to total (including hanging) z faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.stencil_cell_gradient_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3421
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_x(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_43_deflate_edges_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_42_deflate_edges_x[] = "_TreeMesh._deflate_edges_x(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_43_deflate_edges_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_edges_x (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_42_deflate_edges_x(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_42_deflate_edges_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_v_Rh = NULL;
  PyObject *__pyx_v_last_ind = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_8;
  edge_map_t *__pyx_t_9;
  std::pair<int_t,Edge *>  __pyx_t_10;
  Edge *__pyx_t_11;
  int_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_edges_x", 0);
  __Pyx_TraceCall("_deflate_edges_x", __pyx_f[0], 3421, 0, __PYX_ERR(0, 3421, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3424
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_x, dtype=np.float64)
 */
  __Pyx_TraceLine(3424,0,__PYX_ERR(0, 3424, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3424, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3425
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_x, dtype=np.float64)
 *         cdef Edge *edge
 */
  __Pyx_TraceLine(3425,0,__PYX_ERR(0, 3425, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3425, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3426
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_x, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Edge *edge
 *         cdef np.int64_t ii
 */
  __Pyx_TraceLine(3426,0,__PYX_ERR(0, 3426, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3426, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3430
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
  __Pyx_TraceLine(3430,0,__PYX_ERR(0, 3430, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->edges_x;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_it = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":3431
 *         #x edges:
 *         for it in self.tree.edges_x:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             I[2*ii    ] = ii
 */
    __Pyx_TraceLine(3431,0,__PYX_ERR(0, 3431, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3432
 *         for it in self.tree.edges_x:
 *             edge = it.second
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 */
    __Pyx_TraceLine(3432,0,__PYX_ERR(0, 3432, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3433
 *             edge = it.second
 *             ii = edge.index
 *             I[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 */
    __Pyx_TraceLine(3433,0,__PYX_ERR(0, 3433, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3434
 *             ii = edge.index
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 */
    __Pyx_TraceLine(3434,0,__PYX_ERR(0, 3434, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3435
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
    __Pyx_TraceLine(3435,0,__PYX_ERR(0, 3435, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3436
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 */
      __Pyx_TraceLine(3436,0,__PYX_ERR(0, 3436, __pyx_L1_error))
      __pyx_t_12 = (__pyx_v_edge->parents[0])->index;
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3437
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[2*ii    ] = ii
 */
      __Pyx_TraceLine(3437,0,__PYX_ERR(0, 3437, __pyx_L1_error))
      __pyx_t_12 = (__pyx_v_edge->parents[1])->index;
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3435
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3439
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 *                 J[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 */
    __Pyx_TraceLine(3439,0,__PYX_ERR(0, 3439, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":3440
 *             else:
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 */
      __Pyx_TraceLine(3440,0,__PYX_ERR(0, 3440, __pyx_L1_error))
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3441
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5             # <<<<<<<<<<<<<<
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_x, self.n_total_edges_x))
 */
    __Pyx_TraceLine(3441,0,__PYX_ERR(0, 3441, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3442
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5             # <<<<<<<<<<<<<<
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_x, self.n_total_edges_x))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 */
    __Pyx_TraceLine(3442,0,__PYX_ERR(0, 3442, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3430
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
    __Pyx_TraceLine(3430,0,__PYX_ERR(0, 3430, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3443
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_x, self.n_total_edges_x))             # <<<<<<<<<<<<<<
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 */
  __Pyx_TraceLine(3443,0,__PYX_ERR(0, 3443, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_15) < 0) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_Rh = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3445
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_x, self.n_total_edges_x))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)             # <<<<<<<<<<<<<<
 *         while(last_ind > self.n_edges_x):
 *             Rh = Rh*Rh
 */
  __Pyx_TraceLine(3445,0,__PYX_ERR(0, 3445, __pyx_L1_error))
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_15, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3445, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_14) {
    __Pyx_INCREF(__pyx_t_15);
    __pyx_t_5 = __pyx_t_15;
  } else {
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = __pyx_t_1;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __pyx_t_5;
  __Pyx_INCREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_last_ind = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3446
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 *         while(last_ind > self.n_edges_x):             # <<<<<<<<<<<<<<
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 */
  __Pyx_TraceLine(3446,0,__PYX_ERR(0, 3446, __pyx_L1_error))
  while (1) {
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3446, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_last_ind, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3446, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3446, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!__pyx_t_14) break;

    /* "discretize/_extensions/tree_ext.pyx":3447
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 *         while(last_ind > self.n_edges_x):
 *             Rh = Rh*Rh             # <<<<<<<<<<<<<<
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 *         Rh = Rh[:, : last_ind]
 */
    __Pyx_TraceLine(3447,0,__PYX_ERR(0, 3447, __pyx_L1_error))
    __pyx_t_5 = PyNumber_Multiply(__pyx_v_Rh, __pyx_v_Rh); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3447, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3448
 *         while(last_ind > self.n_edges_x):
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)             # <<<<<<<<<<<<<<
 *         Rh = Rh[:, : last_ind]
 *         return Rh
 */
    __Pyx_TraceLine(3448,0,__PYX_ERR(0, 3448, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(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, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_0);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_15 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_15, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_4, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3448, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_14) {
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_4 = __pyx_t_5;
    } else {
      __Pyx_INCREF(__pyx_t_15);
      __pyx_t_4 = __pyx_t_15;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __pyx_t_4;
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_last_ind, __pyx_t_5);
    __pyx_t_5 = 0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3449
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 *         Rh = Rh[:, : last_ind]             # <<<<<<<<<<<<<<
 *         return Rh
 * 
 */
  __Pyx_TraceLine(3449,0,__PYX_ERR(0, 3449, __pyx_L1_error))
  __pyx_t_5 = PySlice_New(Py_None, __pyx_v_last_ind, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_slice__20);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_Rh, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3450
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_x)
 *         Rh = Rh[:, : last_ind]
 *         return Rh             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3450,0,__PYX_ERR(0, 3450, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Rh);
  __pyx_r = __pyx_v_Rh;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3421
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_x(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_edges_x", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rh);
  __Pyx_XDECREF(__pyx_v_last_ind);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3453
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_y(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_45_deflate_edges_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_44_deflate_edges_y[] = "_TreeMesh._deflate_edges_y(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_45_deflate_edges_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_edges_y (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_44_deflate_edges_y(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_44_deflate_edges_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  CYTHON_UNUSED int_t __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_v_Rh = NULL;
  PyObject *__pyx_v_last_ind = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_9;
  edge_map_t *__pyx_t_10;
  std::pair<int_t,Edge *>  __pyx_t_11;
  Edge *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_edges_y", 0);
  __Pyx_TraceCall("_deflate_edges_y", __pyx_f[0], 3453, 0, __PYX_ERR(0, 3453, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3456
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef int_t dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 */
  __Pyx_TraceLine(3456,0,__PYX_ERR(0, 3456, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":3457
 *         #J is input index (without hanging)
 *         cdef int_t dim = self._dim
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_y, dtype=np.float64)
 */
  __Pyx_TraceLine(3457,0,__PYX_ERR(0, 3457, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3457, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_I = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3458
 *         cdef int_t dim = self._dim
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_y, dtype=np.float64)
 *         cdef Edge *edge
 */
  __Pyx_TraceLine(3458,0,__PYX_ERR(0, 3458, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3458, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_J = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3459
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_y, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Edge *edge
 *         cdef np.int64_t ii
 */
  __Pyx_TraceLine(3459,0,__PYX_ERR(0, 3459, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3459, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_V = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3463
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
  __Pyx_TraceLine(3463,0,__PYX_ERR(0, 3463, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->edges_y;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_it = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3464
 *         #x edges:
 *         for it in self.tree.edges_y:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             I[2*ii    ] = ii
 */
    __Pyx_TraceLine(3464,0,__PYX_ERR(0, 3464, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3465
 *         for it in self.tree.edges_y:
 *             edge = it.second
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 */
    __Pyx_TraceLine(3465,0,__PYX_ERR(0, 3465, __pyx_L1_error))
    __pyx_t_1 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_1;

    /* "discretize/_extensions/tree_ext.pyx":3466
 *             edge = it.second
 *             ii = edge.index
 *             I[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 */
    __Pyx_TraceLine(3466,0,__PYX_ERR(0, 3466, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3467
 *             ii = edge.index
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 */
    __Pyx_TraceLine(3467,0,__PYX_ERR(0, 3467, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3468
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
    __Pyx_TraceLine(3468,0,__PYX_ERR(0, 3468, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3469
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 */
      __Pyx_TraceLine(3469,0,__PYX_ERR(0, 3469, __pyx_L1_error))
      __pyx_t_1 = (__pyx_v_edge->parents[0])->index;
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":3470
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[2*ii    ] = ii
 */
      __Pyx_TraceLine(3470,0,__PYX_ERR(0, 3470, __pyx_L1_error))
      __pyx_t_1 = (__pyx_v_edge->parents[1])->index;
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":3468
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3472
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 *                 J[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 */
    __Pyx_TraceLine(3472,0,__PYX_ERR(0, 3472, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":3473
 *             else:
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 */
      __Pyx_TraceLine(3473,0,__PYX_ERR(0, 3473, __pyx_L1_error))
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3474
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5             # <<<<<<<<<<<<<<
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_y, self.n_total_edges_y))
 */
    __Pyx_TraceLine(3474,0,__PYX_ERR(0, 3474, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3475
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5             # <<<<<<<<<<<<<<
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_y, self.n_total_edges_y))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 */
    __Pyx_TraceLine(3475,0,__PYX_ERR(0, 3475, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3463
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
    __Pyx_TraceLine(3463,0,__PYX_ERR(0, 3463, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3476
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_y, self.n_total_edges_y))             # <<<<<<<<<<<<<<
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 */
  __Pyx_TraceLine(3476,0,__PYX_ERR(0, 3476, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __pyx_t_5 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_15) < 0) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_Rh = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3478
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_y, self.n_total_edges_y))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)             # <<<<<<<<<<<<<<
 *         while(last_ind > self.n_edges_y):
 *             Rh = Rh*Rh
 */
  __Pyx_TraceLine(3478,0,__PYX_ERR(0, 3478, __pyx_L1_error))
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_int_0);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_6, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_15, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3478, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_14) {
    __Pyx_INCREF(__pyx_t_15);
    __pyx_t_6 = __pyx_t_15;
  } else {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = __pyx_t_2;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __pyx_t_6;
  __Pyx_INCREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_last_ind = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3479
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 *         while(last_ind > self.n_edges_y):             # <<<<<<<<<<<<<<
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 */
  __Pyx_TraceLine(3479,0,__PYX_ERR(0, 3479, __pyx_L1_error))
  while (1) {
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3479, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_6 = PyObject_RichCompare(__pyx_v_last_ind, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3479, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3479, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_14) break;

    /* "discretize/_extensions/tree_ext.pyx":3480
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 *         while(last_ind > self.n_edges_y):
 *             Rh = Rh*Rh             # <<<<<<<<<<<<<<
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 *         Rh = Rh[:, : last_ind]
 */
    __Pyx_TraceLine(3480,0,__PYX_ERR(0, 3480, __pyx_L1_error))
    __pyx_t_6 = PyNumber_Multiply(__pyx_v_Rh, __pyx_v_Rh); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3480, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3481
 *         while(last_ind > self.n_edges_y):
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)             # <<<<<<<<<<<<<<
 *         Rh = Rh[:, : last_ind]
 *         return Rh
 */
    __Pyx_TraceLine(3481,0,__PYX_ERR(0, 3481, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_15 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_15, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3481, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_14) {
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_5 = __pyx_t_6;
    } else {
      __Pyx_INCREF(__pyx_t_15);
      __pyx_t_5 = __pyx_t_15;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __pyx_t_5;
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_last_ind, __pyx_t_6);
    __pyx_t_6 = 0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3482
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 *         Rh = Rh[:, : last_ind]             # <<<<<<<<<<<<<<
 *         return Rh
 * 
 */
  __Pyx_TraceLine(3482,0,__PYX_ERR(0, 3482, __pyx_L1_error))
  __pyx_t_6 = PySlice_New(Py_None, __pyx_v_last_ind, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice__20);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_Rh, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3483
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_y)
 *         Rh = Rh[:, : last_ind]
 *         return Rh             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3483,0,__PYX_ERR(0, 3483, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Rh);
  __pyx_r = __pyx_v_Rh;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3453
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_y(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_edges_y", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rh);
  __Pyx_XDECREF(__pyx_v_last_ind);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3486
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_z(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_47_deflate_edges_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_46_deflate_edges_z[] = "_TreeMesh._deflate_edges_z(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_47_deflate_edges_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_edges_z (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_46_deflate_edges_z(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_46_deflate_edges_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  CYTHON_UNUSED int_t __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Edge *__pyx_v_edge;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Edge *>  __pyx_v_it;
  PyObject *__pyx_v_Rh = NULL;
  PyObject *__pyx_v_last_ind = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_9;
  edge_map_t *__pyx_t_10;
  std::pair<int_t,Edge *>  __pyx_t_11;
  Edge *__pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_edges_z", 0);
  __Pyx_TraceCall("_deflate_edges_z", __pyx_f[0], 3486, 0, __PYX_ERR(0, 3486, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3489
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef int_t dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 */
  __Pyx_TraceLine(3489,0,__PYX_ERR(0, 3489, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":3490
 *         #J is input index (without hanging)
 *         cdef int_t dim = self._dim
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_z, dtype=np.float64)
 */
  __Pyx_TraceLine(3490,0,__PYX_ERR(0, 3490, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_I = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3491
 *         cdef int_t dim = self._dim
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_z, dtype=np.float64)
 *         cdef Edge *edge
 */
  __Pyx_TraceLine(3491,0,__PYX_ERR(0, 3491, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3491, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_J = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3492
 *         cdef np.int64_t[:] I = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(2*self.n_total_edges_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(2*self.n_total_edges_z, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Edge *edge
 *         cdef np.int64_t ii
 */
  __Pyx_TraceLine(3492,0,__PYX_ERR(0, 3492, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_V = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3496
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
  __Pyx_TraceLine(3496,0,__PYX_ERR(0, 3496, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->edges_z;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_it = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3497
 *         #x edges:
 *         for it in self.tree.edges_z:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             I[2*ii    ] = ii
 */
    __Pyx_TraceLine(3497,0,__PYX_ERR(0, 3497, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3498
 *         for it in self.tree.edges_z:
 *             edge = it.second
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 */
    __Pyx_TraceLine(3498,0,__PYX_ERR(0, 3498, __pyx_L1_error))
    __pyx_t_1 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_1;

    /* "discretize/_extensions/tree_ext.pyx":3499
 *             edge = it.second
 *             ii = edge.index
 *             I[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 */
    __Pyx_TraceLine(3499,0,__PYX_ERR(0, 3499, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3500
 *             ii = edge.index
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 */
    __Pyx_TraceLine(3500,0,__PYX_ERR(0, 3500, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3501
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
    __Pyx_TraceLine(3501,0,__PYX_ERR(0, 3501, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3502
 *             I[2*ii + 1] = ii
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 */
      __Pyx_TraceLine(3502,0,__PYX_ERR(0, 3502, __pyx_L1_error))
      __pyx_t_1 = (__pyx_v_edge->parents[0])->index;
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":3503
 *             if edge.hanging:
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[2*ii    ] = ii
 */
      __Pyx_TraceLine(3503,0,__PYX_ERR(0, 3503, __pyx_L1_error))
      __pyx_t_1 = (__pyx_v_edge->parents[1])->index;
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":3501
 *             I[2*ii    ] = ii
 *             I[2*ii + 1] = ii
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 J[2*ii    ] = edge.parents[0].index
 *                 J[2*ii + 1] = edge.parents[1].index
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3505
 *                 J[2*ii + 1] = edge.parents[1].index
 *             else:
 *                 J[2*ii    ] = ii             # <<<<<<<<<<<<<<
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 */
    __Pyx_TraceLine(3505,0,__PYX_ERR(0, 3505, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = (2 * __pyx_v_ii);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":3506
 *             else:
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii             # <<<<<<<<<<<<<<
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 */
      __Pyx_TraceLine(3506,0,__PYX_ERR(0, 3506, __pyx_L1_error))
      __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3507
 *                 J[2*ii    ] = ii
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5             # <<<<<<<<<<<<<<
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_z, self.n_total_edges_z))
 */
    __Pyx_TraceLine(3507,0,__PYX_ERR(0, 3507, __pyx_L1_error))
    __pyx_t_13 = (2 * __pyx_v_ii);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3508
 *                 J[2*ii + 1] = ii
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5             # <<<<<<<<<<<<<<
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_z, self.n_total_edges_z))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 */
    __Pyx_TraceLine(3508,0,__PYX_ERR(0, 3508, __pyx_L1_error))
    __pyx_t_13 = ((2 * __pyx_v_ii) + 1);
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 0.5;

    /* "discretize/_extensions/tree_ext.pyx":3496
 *         cdef np.int64_t ii
 *         #x edges:
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             ii = edge.index
 */
    __Pyx_TraceLine(3496,0,__PYX_ERR(0, 3496, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3509
 *             V[2*ii    ] = 0.5
 *             V[2*ii + 1] = 0.5
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_z, self.n_total_edges_z))             # <<<<<<<<<<<<<<
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 */
  __Pyx_TraceLine(3509,0,__PYX_ERR(0, 3509, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __pyx_t_5 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_15) < 0) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_Rh = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3511
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_edges_z, self.n_total_edges_z))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)             # <<<<<<<<<<<<<<
 *         while(last_ind > self.n_edges_z):
 *             Rh = Rh*Rh
 */
  __Pyx_TraceLine(3511,0,__PYX_ERR(0, 3511, __pyx_L1_error))
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_int_0);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_6, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_15, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_14) {
    __Pyx_INCREF(__pyx_t_15);
    __pyx_t_6 = __pyx_t_15;
  } else {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = __pyx_t_2;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __pyx_t_6;
  __Pyx_INCREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_last_ind = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3512
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 *         while(last_ind > self.n_edges_z):             # <<<<<<<<<<<<<<
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 */
  __Pyx_TraceLine(3512,0,__PYX_ERR(0, 3512, __pyx_L1_error))
  while (1) {
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_6 = PyObject_RichCompare(__pyx_v_last_ind, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3512, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3512, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!__pyx_t_14) break;

    /* "discretize/_extensions/tree_ext.pyx":3513
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 *         while(last_ind > self.n_edges_z):
 *             Rh = Rh*Rh             # <<<<<<<<<<<<<<
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 *         Rh = Rh[:, : last_ind]
 */
    __Pyx_TraceLine(3513,0,__PYX_ERR(0, 3513, __pyx_L1_error))
    __pyx_t_6 = PyNumber_Multiply(__pyx_v_Rh, __pyx_v_Rh); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3513, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3514
 *         while(last_ind > self.n_edges_z):
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)             # <<<<<<<<<<<<<<
 *         Rh = Rh[:, : last_ind]
 *         return Rh
 */
    __Pyx_TraceLine(3514,0,__PYX_ERR(0, 3514, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_15 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_15, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_15, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 3514, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_14) {
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_5 = __pyx_t_6;
    } else {
      __Pyx_INCREF(__pyx_t_15);
      __pyx_t_5 = __pyx_t_15;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __pyx_t_5;
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_last_ind, __pyx_t_6);
    __pyx_t_6 = 0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3515
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 *         Rh = Rh[:, : last_ind]             # <<<<<<<<<<<<<<
 *         return Rh
 * 
 */
  __Pyx_TraceLine(3515,0,__PYX_ERR(0, 3515, __pyx_L1_error))
  __pyx_t_6 = PySlice_New(Py_None, __pyx_v_last_ind, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice__20);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_Rh, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3516
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_edges_z)
 *         Rh = Rh[:, : last_ind]
 *         return Rh             # <<<<<<<<<<<<<<
 * 
 *     def _deflate_edges(self):
 */
  __Pyx_TraceLine(3516,0,__PYX_ERR(0, 3516, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Rh);
  __pyx_r = __pyx_v_Rh;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3486
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_edges_z(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_edges_z", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rh);
  __Pyx_XDECREF(__pyx_v_last_ind);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3518
 *         return Rh
 * 
 *     def _deflate_edges(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix to remove hanging edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_49_deflate_edges(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_48_deflate_edges[] = "_TreeMesh._deflate_edges(self)\nReturn a matrix to remove hanging edges.\n\n        A hanging edge can either have 1 or 2 parents.\n        If a hanging edge has a single parent, it's value is the same as the parent\n        If a hanging edge has 2 parents, it's an average of the two parents\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_49_deflate_edges(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_edges (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_48_deflate_edges(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_48_deflate_edges(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_Rx = NULL;
  PyObject *__pyx_v_Ry = NULL;
  PyObject *__pyx_v_Rz = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_edges", 0);
  __Pyx_TraceCall("_deflate_edges", __pyx_f[0], 3518, 0, __PYX_ERR(0, 3518, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3525
 *         If a hanging edge has 2 parents, it's an average of the two parents
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 */
  __Pyx_TraceLine(3525,0,__PYX_ERR(0, 3525, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":3526
 *         """
 *         if self._dim == 2:
 *             Rx = self._deflate_edges_x()             # <<<<<<<<<<<<<<
 *             Ry = self._deflate_edges_y()
 *             return sp.block_diag((Rx, Ry))
 */
    __Pyx_TraceLine(3526,0,__PYX_ERR(0, 3526, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_Rx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3527
 *         if self._dim == 2:
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()             # <<<<<<<<<<<<<<
 *             return sp.block_diag((Rx, Ry))
 *         else:
 */
    __Pyx_TraceLine(3527,0,__PYX_ERR(0, 3527, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3527, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3527, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_Ry = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3528
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 *             return sp.block_diag((Rx, Ry))             # <<<<<<<<<<<<<<
 *         else:
 *             Rx = self._deflate_edges_x()
 */
    __Pyx_TraceLine(3528,0,__PYX_ERR(0, 3528, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_Rx);
    __Pyx_GIVEREF(__pyx_v_Rx);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_Rx);
    __Pyx_INCREF(__pyx_v_Ry);
    __Pyx_GIVEREF(__pyx_v_Ry);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_Ry);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3525
 *         If a hanging edge has 2 parents, it's an average of the two parents
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3530
 *             return sp.block_diag((Rx, Ry))
 *         else:
 *             Rx = self._deflate_edges_x()             # <<<<<<<<<<<<<<
 *             Ry = self._deflate_edges_y()
 *             Rz = self._deflate_edges_z()
 */
  __Pyx_TraceLine(3530,0,__PYX_ERR(0, 3530, __pyx_L1_error))
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Rx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3531
 *         else:
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()             # <<<<<<<<<<<<<<
 *             Rz = self._deflate_edges_z()
 *             return sp.block_diag((Rx, Ry, Rz))
 */
    __Pyx_TraceLine(3531,0,__PYX_ERR(0, 3531, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Ry = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3532
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 *             Rz = self._deflate_edges_z()             # <<<<<<<<<<<<<<
 *             return sp.block_diag((Rx, Ry, Rz))
 * 
 */
    __Pyx_TraceLine(3532,0,__PYX_ERR(0, 3532, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Rz = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3533
 *             Ry = self._deflate_edges_y()
 *             Rz = self._deflate_edges_z()
 *             return sp.block_diag((Rx, Ry, Rz))             # <<<<<<<<<<<<<<
 * 
 *     def _deflate_faces(self):
 */
    __Pyx_TraceLine(3533,0,__PYX_ERR(0, 3533, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_Rx);
    __Pyx_GIVEREF(__pyx_v_Rx);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_Rx);
    __Pyx_INCREF(__pyx_v_Ry);
    __Pyx_GIVEREF(__pyx_v_Ry);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_Ry);
    __Pyx_INCREF(__pyx_v_Rz);
    __Pyx_GIVEREF(__pyx_v_Rz);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_Rz);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3518
 *         return Rh
 * 
 *     def _deflate_edges(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix to remove hanging edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_edges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Rx);
  __Pyx_XDECREF(__pyx_v_Ry);
  __Pyx_XDECREF(__pyx_v_Rz);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3535
 *             return sp.block_diag((Rx, Ry, Rz))
 * 
 *     def _deflate_faces(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix that removes hanging faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_51_deflate_faces(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_50_deflate_faces[] = "_TreeMesh._deflate_faces(self)\nReturn a matrix that removes hanging faces.\n\n        The operation assigns the hanging face the value of its parent.\n        A hanging face will only ever have 1 parent.\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_51_deflate_faces(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_faces (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_50_deflate_faces(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_50_deflate_faces(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_Rx = NULL;
  PyObject *__pyx_v_Ry = NULL;
  PyObject *__pyx_v_Rz = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_faces", 0);
  __Pyx_TraceCall("_deflate_faces", __pyx_f[0], 3535, 0, __PYX_ERR(0, 3535, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3541
 *         A hanging face will only ever have 1 parent.
 *         """
 *         if(self._dim == 2):             # <<<<<<<<<<<<<<
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 */
  __Pyx_TraceLine(3541,0,__PYX_ERR(0, 3541, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":3542
 *         """
 *         if(self._dim == 2):
 *             Rx = self._deflate_edges_x()             # <<<<<<<<<<<<<<
 *             Ry = self._deflate_edges_y()
 *             return sp.block_diag((Ry, Rx))
 */
    __Pyx_TraceLine(3542,0,__PYX_ERR(0, 3542, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_Rx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3543
 *         if(self._dim == 2):
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()             # <<<<<<<<<<<<<<
 *             return sp.block_diag((Ry, Rx))
 *         else:
 */
    __Pyx_TraceLine(3543,0,__PYX_ERR(0, 3543, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_Ry = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3544
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 *             return sp.block_diag((Ry, Rx))             # <<<<<<<<<<<<<<
 *         else:
 *             Rx = self._deflate_faces_x()
 */
    __Pyx_TraceLine(3544,0,__PYX_ERR(0, 3544, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3544, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3544, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3544, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_Ry);
    __Pyx_GIVEREF(__pyx_v_Ry);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_Ry);
    __Pyx_INCREF(__pyx_v_Rx);
    __Pyx_GIVEREF(__pyx_v_Rx);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_Rx);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3544, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3541
 *         A hanging face will only ever have 1 parent.
 *         """
 *         if(self._dim == 2):             # <<<<<<<<<<<<<<
 *             Rx = self._deflate_edges_x()
 *             Ry = self._deflate_edges_y()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3546
 *             return sp.block_diag((Ry, Rx))
 *         else:
 *             Rx = self._deflate_faces_x()             # <<<<<<<<<<<<<<
 *             Ry = self._deflate_faces_y()
 *             Rz = self._deflate_faces_z()
 */
  __Pyx_TraceLine(3546,0,__PYX_ERR(0, 3546, __pyx_L1_error))
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3546, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3546, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Rx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3547
 *         else:
 *             Rx = self._deflate_faces_x()
 *             Ry = self._deflate_faces_y()             # <<<<<<<<<<<<<<
 *             Rz = self._deflate_faces_z()
 *             return sp.block_diag((Rx, Ry, Rz))
 */
    __Pyx_TraceLine(3547,0,__PYX_ERR(0, 3547, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3547, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3547, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Ry = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3548
 *             Rx = self._deflate_faces_x()
 *             Ry = self._deflate_faces_y()
 *             Rz = self._deflate_faces_z()             # <<<<<<<<<<<<<<
 *             return sp.block_diag((Rx, Ry, Rz))
 * 
 */
    __Pyx_TraceLine(3548,0,__PYX_ERR(0, 3548, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3548, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3548, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_Rz = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3549
 *             Ry = self._deflate_faces_y()
 *             Rz = self._deflate_faces_z()
 *             return sp.block_diag((Rx, Ry, Rz))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
    __Pyx_TraceLine(3549,0,__PYX_ERR(0, 3549, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_Rx);
    __Pyx_GIVEREF(__pyx_v_Rx);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_Rx);
    __Pyx_INCREF(__pyx_v_Ry);
    __Pyx_GIVEREF(__pyx_v_Ry);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_Ry);
    __Pyx_INCREF(__pyx_v_Rz);
    __Pyx_GIVEREF(__pyx_v_Rz);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_Rz);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3535
 *             return sp.block_diag((Rx, Ry, Rz))
 * 
 *     def _deflate_faces(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix that removes hanging faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_faces", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Rx);
  __Pyx_XDECREF(__pyx_v_Ry);
  __Pyx_XDECREF(__pyx_v_Rz);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3552
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_x(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_53_deflate_faces_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_52_deflate_faces_x[] = "_TreeMesh._deflate_faces_x(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_53_deflate_faces_x(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_faces_x (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_52_deflate_faces_x(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_52_deflate_faces_x(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_8;
  face_map_t *__pyx_t_9;
  std::pair<int_t,Face *>  __pyx_t_10;
  Face *__pyx_t_11;
  int_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_faces_x", 0);
  __Pyx_TraceCall("_deflate_faces_x", __pyx_f[0], 3552, 0, __PYX_ERR(0, 3552, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3555
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_x, dtype=np.float64)
 */
  __Pyx_TraceLine(3555,0,__PYX_ERR(0, 3555, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3555, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3556
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_x, dtype=np.float64)
 *         cdef Face *face
 */
  __Pyx_TraceLine(3556,0,__PYX_ERR(0, 3556, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3556, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3557
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_x, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Face *face
 *         cdef np.int64_t ii;
 */
  __Pyx_TraceLine(3557,0,__PYX_ERR(0, 3557, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3557, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3561
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
  __Pyx_TraceLine(3561,0,__PYX_ERR(0, 3561, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->faces_x;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_it = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":3562
 * 
 *         for it in self.tree.faces_x:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             I[ii] = ii
 */
    __Pyx_TraceLine(3562,0,__PYX_ERR(0, 3562, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3563
 *         for it in self.tree.faces_x:
 *             face = it.second
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             I[ii] = ii
 *             if face.hanging:
 */
    __Pyx_TraceLine(3563,0,__PYX_ERR(0, 3563, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3564
 *             face = it.second
 *             ii = face.index
 *             I[ii] = ii             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 J[ii] = face.parent.index
 */
    __Pyx_TraceLine(3564,0,__PYX_ERR(0, 3564, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3565
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
    __Pyx_TraceLine(3565,0,__PYX_ERR(0, 3565, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3566
 *             I[ii] = ii
 *             if face.hanging:
 *                 J[ii] = face.parent.index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[ii] = ii
 */
      __Pyx_TraceLine(3566,0,__PYX_ERR(0, 3566, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_face->parent->index;
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3565
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3568
 *                 J[ii] = face.parent.index
 *             else:
 *                 J[ii] = ii             # <<<<<<<<<<<<<<
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))
 */
    __Pyx_TraceLine(3568,0,__PYX_ERR(0, 3568, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3569
 *             else:
 *                 J[ii] = ii
 *             V[ii] = 1.0             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)))
 * 
 */
    __Pyx_TraceLine(3569,0,__PYX_ERR(0, 3569, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 1.0;

    /* "discretize/_extensions/tree_ext.pyx":3561
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
    __Pyx_TraceLine(3561,0,__PYX_ERR(0, 3561, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3570
 *                 J[ii] = ii
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3570,0,__PYX_ERR(0, 3570, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_1);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_15, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3552
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_x(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_faces_x", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3573
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_y(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_55_deflate_faces_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_54_deflate_faces_y[] = "_TreeMesh._deflate_faces_y(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_55_deflate_faces_y(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_faces_y (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_54_deflate_faces_y(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_54_deflate_faces_y(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_8;
  face_map_t *__pyx_t_9;
  std::pair<int_t,Face *>  __pyx_t_10;
  Face *__pyx_t_11;
  int_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_faces_y", 0);
  __Pyx_TraceCall("_deflate_faces_y", __pyx_f[0], 3573, 0, __PYX_ERR(0, 3573, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3576
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_y, dtype=np.float64)
 */
  __Pyx_TraceLine(3576,0,__PYX_ERR(0, 3576, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3577
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_y, dtype=np.float64)
 *         cdef Face *face
 */
  __Pyx_TraceLine(3577,0,__PYX_ERR(0, 3577, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3577, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3578
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_y, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Face *face
 *         cdef np.int64_t ii;
 */
  __Pyx_TraceLine(3578,0,__PYX_ERR(0, 3578, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3578, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3582
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
  __Pyx_TraceLine(3582,0,__PYX_ERR(0, 3582, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->faces_y;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_it = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":3583
 * 
 *         for it in self.tree.faces_y:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             I[ii] = ii
 */
    __Pyx_TraceLine(3583,0,__PYX_ERR(0, 3583, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3584
 *         for it in self.tree.faces_y:
 *             face = it.second
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             I[ii] = ii
 *             if face.hanging:
 */
    __Pyx_TraceLine(3584,0,__PYX_ERR(0, 3584, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3585
 *             face = it.second
 *             ii = face.index
 *             I[ii] = ii             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 J[ii] = face.parent.index
 */
    __Pyx_TraceLine(3585,0,__PYX_ERR(0, 3585, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3586
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
    __Pyx_TraceLine(3586,0,__PYX_ERR(0, 3586, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3587
 *             I[ii] = ii
 *             if face.hanging:
 *                 J[ii] = face.parent.index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[ii] = ii
 */
      __Pyx_TraceLine(3587,0,__PYX_ERR(0, 3587, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_face->parent->index;
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3586
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3589
 *                 J[ii] = face.parent.index
 *             else:
 *                 J[ii] = ii             # <<<<<<<<<<<<<<
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))
 */
    __Pyx_TraceLine(3589,0,__PYX_ERR(0, 3589, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3590
 *             else:
 *                 J[ii] = ii
 *             V[ii] = 1.0             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)))
 * 
 */
    __Pyx_TraceLine(3590,0,__PYX_ERR(0, 3590, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 1.0;

    /* "discretize/_extensions/tree_ext.pyx":3582
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
    __Pyx_TraceLine(3582,0,__PYX_ERR(0, 3582, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3591
 *                 J[ii] = ii
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3591,0,__PYX_ERR(0, 3591, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_1);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_15, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3573
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_y(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_faces_y", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3594
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_z(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_57_deflate_faces_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_56_deflate_faces_z[] = "_TreeMesh._deflate_faces_z(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_57_deflate_faces_z(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_faces_z (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_56_deflate_faces_z(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_56_deflate_faces_z(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_8;
  face_map_t *__pyx_t_9;
  std::pair<int_t,Face *>  __pyx_t_10;
  Face *__pyx_t_11;
  int_t __pyx_t_12;
  __pyx_t_5numpy_int64_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_faces_z", 0);
  __Pyx_TraceCall("_deflate_faces_z", __pyx_f[0], 3594, 0, __PYX_ERR(0, 3594, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3597
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_z, dtype=np.float64)
 */
  __Pyx_TraceLine(3597,0,__PYX_ERR(0, 3597, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3597, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3598
 *         #J is input index (without hanging)
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_z, dtype=np.float64)
 *         cdef Face *face
 */
  __Pyx_TraceLine(3598,0,__PYX_ERR(0, 3598, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3598, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3599
 *         cdef np.int64_t[:] I = np.empty(self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(self.n_total_faces_z, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef Face *face
 *         cdef np.int64_t ii;
 */
  __Pyx_TraceLine(3599,0,__PYX_ERR(0, 3599, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3599, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3603
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
  __Pyx_TraceLine(3603,0,__PYX_ERR(0, 3603, __pyx_L1_error))
  __pyx_t_9 = &__pyx_v_self->tree->faces_z;
  __pyx_t_8 = __pyx_t_9->begin();
  for (;;) {
    if (!(__pyx_t_8 != __pyx_t_9->end())) break;
    __pyx_t_10 = *__pyx_t_8;
    ++__pyx_t_8;
    __pyx_v_it = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":3604
 * 
 *         for it in self.tree.faces_z:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             I[ii] = ii
 */
    __Pyx_TraceLine(3604,0,__PYX_ERR(0, 3604, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3605
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             I[ii] = ii
 *             if face.hanging:
 */
    __Pyx_TraceLine(3605,0,__PYX_ERR(0, 3605, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3606
 *             face = it.second
 *             ii = face.index
 *             I[ii] = ii             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 J[ii] = face.parent.index
 */
    __Pyx_TraceLine(3606,0,__PYX_ERR(0, 3606, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_I.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_13 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

    /* "discretize/_extensions/tree_ext.pyx":3607
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
    __Pyx_TraceLine(3607,0,__PYX_ERR(0, 3607, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":3608
 *             I[ii] = ii
 *             if face.hanging:
 *                 J[ii] = face.parent.index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[ii] = ii
 */
      __Pyx_TraceLine(3608,0,__PYX_ERR(0, 3608, __pyx_L1_error))
      __pyx_t_12 = __pyx_v_face->parent->index;
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":3607
 *             ii = face.index
 *             I[ii] = ii
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 J[ii] = face.parent.index
 *             else:
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3610
 *                 J[ii] = face.parent.index
 *             else:
 *                 J[ii] = ii             # <<<<<<<<<<<<<<
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))
 */
    __Pyx_TraceLine(3610,0,__PYX_ERR(0, 3610, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = __pyx_v_ii;
      if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_13 * __pyx_v_J.strides[0]) )) = __pyx_v_ii;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3611
 *             else:
 *                 J[ii] = ii
 *             V[ii] = 1.0             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)))
 * 
 */
    __Pyx_TraceLine(3611,0,__PYX_ERR(0, 3611, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_ii;
    if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_v_V.shape[0];
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_13 * __pyx_v_V.strides[0]) )) = 1.0;

    /* "discretize/_extensions/tree_ext.pyx":3603
 *         cdef np.int64_t ii;
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             ii = face.index
 */
    __Pyx_TraceLine(3603,0,__PYX_ERR(0, 3603, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3612
 *                 J[ii] = ii
 *             V[ii] = 1.0
 *         return sp.csr_matrix((V, (I, J)))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(3612,0,__PYX_ERR(0, 3612, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_1);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_15, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3594
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_faces_z(self):             # <<<<<<<<<<<<<<
 *         #I is output index (with hanging)
 *         #J is input index (without hanging)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_faces_z", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3615
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_nodes(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix that removes hanging faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_59_deflate_nodes(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_58_deflate_nodes[] = "_TreeMesh._deflate_nodes(self)\nReturn a matrix that removes hanging faces.\n\n        A hanging node will have 2 parents in 2D or 2 or 4 parents in 3D.\n        This matrix assigns the hanging node the average value of its parents.\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_59_deflate_nodes(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_deflate_nodes (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_58_deflate_nodes(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_58_deflate_nodes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Node *__pyx_v_node;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  CYTHON_UNUSED __pyx_t_5numpy_int64_t __pyx_v_offset;
  std::pair<int_t,Node *>  __pyx_v_it;
  PyObject *__pyx_v_Rh = NULL;
  PyObject *__pyx_v_last_ind = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_t_8;
  std::map<int_t,Node *> ::iterator __pyx_t_9;
  node_map_t *__pyx_t_10;
  std::pair<int_t,Node *>  __pyx_t_11;
  Node *__pyx_t_12;
  int_t __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_deflate_nodes", 0);
  __Pyx_TraceCall("_deflate_nodes", __pyx_f[0], 3615, 0, __PYX_ERR(0, 3615, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3621
 *         This matrix assigns the hanging node the average value of its parents.
 *         """
 *         cdef np.int64_t[:] I = np.empty(4*self.n_total_nodes, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.empty(4*self.n_total_nodes, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(4*self.n_total_nodes, dtype=np.float64)
 */
  __Pyx_TraceLine(3621,0,__PYX_ERR(0, 3621, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3621, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3622
 *         """
 *         cdef np.int64_t[:] I = np.empty(4*self.n_total_nodes, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(4*self.n_total_nodes, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.empty(4*self.n_total_nodes, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(3622,0,__PYX_ERR(0, 3622, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Multiply(__pyx_int_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 3622, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_J = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3623
 *         cdef np.int64_t[:] I = np.empty(4*self.n_total_nodes, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.empty(4*self.n_total_nodes, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.empty(4*self.n_total_nodes, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         # I is output index
 */
  __Pyx_TraceLine(3623,0,__PYX_ERR(0, 3623, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_4, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 3623, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3629
 *         cdef Node *node
 *         cdef np.int64_t ii, i, offset
 *         offset = self.n_nodes             # <<<<<<<<<<<<<<
 *         cdef double[4] weights
 * 
 */
  __Pyx_TraceLine(3629,0,__PYX_ERR(0, 3629, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3629, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyInt_As_npy_int64(__pyx_t_2); if (unlikely((__pyx_t_8 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3629, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_offset = __pyx_t_8;

  /* "discretize/_extensions/tree_ext.pyx":3632
 *         cdef double[4] weights
 * 
 *         for it in self.tree.nodes:             # <<<<<<<<<<<<<<
 *             node = it.second
 *             ii = node.index
 */
  __Pyx_TraceLine(3632,0,__PYX_ERR(0, 3632, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->nodes;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_it = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":3633
 * 
 *         for it in self.tree.nodes:
 *             node = it.second             # <<<<<<<<<<<<<<
 *             ii = node.index
 *             I[4*ii:4*ii + 4] = ii
 */
    __Pyx_TraceLine(3633,0,__PYX_ERR(0, 3633, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_it.second;
    __pyx_v_node = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3634
 *         for it in self.tree.nodes:
 *             node = it.second
 *             ii = node.index             # <<<<<<<<<<<<<<
 *             I[4*ii:4*ii + 4] = ii
 *             if node.hanging:
 */
    __Pyx_TraceLine(3634,0,__PYX_ERR(0, 3634, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_node->index;
    __pyx_v_ii = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3635
 *             node = it.second
 *             ii = node.index
 *             I[4*ii:4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             if node.hanging:
 *                 J[4*ii    ] = node.parents[0].index
 */
    __Pyx_TraceLine(3635,0,__PYX_ERR(0, 3635, __pyx_L1_error))
    __pyx_t_6.data = __pyx_v_I.data;
    __pyx_t_6.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_6, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_6,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3635, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_6.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_6.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_6.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3636
 *             ii = node.index
 *             I[4*ii:4*ii + 4] = ii
 *             if node.hanging:             # <<<<<<<<<<<<<<
 *                 J[4*ii    ] = node.parents[0].index
 *                 J[4*ii + 1] = node.parents[1].index
 */
    __Pyx_TraceLine(3636,0,__PYX_ERR(0, 3636, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_node->hanging != 0);
    if (__pyx_t_15) {

      /* "discretize/_extensions/tree_ext.pyx":3637
 *             I[4*ii:4*ii + 4] = ii
 *             if node.hanging:
 *                 J[4*ii    ] = node.parents[0].index             # <<<<<<<<<<<<<<
 *                 J[4*ii + 1] = node.parents[1].index
 *                 J[4*ii + 2] = node.parents[2].index
 */
      __Pyx_TraceLine(3637,0,__PYX_ERR(0, 3637, __pyx_L1_error))
      __pyx_t_13 = (__pyx_v_node->parents[0])->index;
      __pyx_t_8 = (4 * __pyx_v_ii);
      if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_8 * __pyx_v_J.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":3638
 *             if node.hanging:
 *                 J[4*ii    ] = node.parents[0].index
 *                 J[4*ii + 1] = node.parents[1].index             # <<<<<<<<<<<<<<
 *                 J[4*ii + 2] = node.parents[2].index
 *                 J[4*ii + 3] = node.parents[3].index
 */
      __Pyx_TraceLine(3638,0,__PYX_ERR(0, 3638, __pyx_L1_error))
      __pyx_t_13 = (__pyx_v_node->parents[1])->index;
      __pyx_t_8 = ((4 * __pyx_v_ii) + 1);
      if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_8 * __pyx_v_J.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":3639
 *                 J[4*ii    ] = node.parents[0].index
 *                 J[4*ii + 1] = node.parents[1].index
 *                 J[4*ii + 2] = node.parents[2].index             # <<<<<<<<<<<<<<
 *                 J[4*ii + 3] = node.parents[3].index
 *             else:
 */
      __Pyx_TraceLine(3639,0,__PYX_ERR(0, 3639, __pyx_L1_error))
      __pyx_t_13 = (__pyx_v_node->parents[2])->index;
      __pyx_t_8 = ((4 * __pyx_v_ii) + 2);
      if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_8 * __pyx_v_J.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":3640
 *                 J[4*ii + 1] = node.parents[1].index
 *                 J[4*ii + 2] = node.parents[2].index
 *                 J[4*ii + 3] = node.parents[3].index             # <<<<<<<<<<<<<<
 *             else:
 *                 J[4*ii : 4*ii + 4] = ii
 */
      __Pyx_TraceLine(3640,0,__PYX_ERR(0, 3640, __pyx_L1_error))
      __pyx_t_13 = (__pyx_v_node->parents[3])->index;
      __pyx_t_8 = ((4 * __pyx_v_ii) + 3);
      if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_8 * __pyx_v_J.strides[0]) )) = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":3636
 *             ii = node.index
 *             I[4*ii:4*ii + 4] = ii
 *             if node.hanging:             # <<<<<<<<<<<<<<
 *                 J[4*ii    ] = node.parents[0].index
 *                 J[4*ii + 1] = node.parents[1].index
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":3642
 *                 J[4*ii + 3] = node.parents[3].index
 *             else:
 *                 J[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             V[4*ii : 4*ii + 4] = 0.25;
 * 
 */
    __Pyx_TraceLine(3642,0,__PYX_ERR(0, 3642, __pyx_L1_error))
    /*else*/ {
      __pyx_t_6.data = __pyx_v_J.data;
      __pyx_t_6.memview = __pyx_v_J.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_6, 0);
      __pyx_t_14 = -1;
      if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_6,
    __pyx_v_J.shape[0], __pyx_v_J.strides[0], __pyx_v_J.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3642, __pyx_L1_error)
}

{
          __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
          {
              Py_ssize_t __pyx_temp_extent_0 = __pyx_t_6.shape[0];
              Py_ssize_t __pyx_temp_stride_0 = __pyx_t_6.strides[0];
              char *__pyx_temp_pointer_0;
              Py_ssize_t __pyx_temp_idx_0;
              __pyx_temp_pointer_0 = __pyx_t_6.data;
              for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                __pyx_temp_pointer_0 += __pyx_temp_stride_0;
              }
          }
      }
      __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
      __pyx_t_6.memview = NULL;
      __pyx_t_6.data = NULL;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":3643
 *             else:
 *                 J[4*ii : 4*ii + 4] = ii
 *             V[4*ii : 4*ii + 4] = 0.25;             # <<<<<<<<<<<<<<
 * 
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_nodes, self.n_total_nodes))
 */
    __Pyx_TraceLine(3643,0,__PYX_ERR(0, 3643, __pyx_L1_error))
    __pyx_t_7.data = __pyx_v_V.data;
    __pyx_t_7.memview = __pyx_v_V.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_7, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_7,
    __pyx_v_V.shape[0], __pyx_v_V.strides[0], __pyx_v_V.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3643, __pyx_L1_error)
}

{
        __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.25;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_7.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_7.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_7.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3632
 *         cdef double[4] weights
 * 
 *         for it in self.tree.nodes:             # <<<<<<<<<<<<<<
 *             node = it.second
 *             ii = node.index
 */
    __Pyx_TraceLine(3632,0,__PYX_ERR(0, 3632, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3645
 *             V[4*ii : 4*ii + 4] = 0.25;
 * 
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_nodes, self.n_total_nodes))             # <<<<<<<<<<<<<<
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 */
  __Pyx_TraceLine(3645,0,__PYX_ERR(0, 3645, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_16) < 0) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_Rh = __pyx_t_16;
  __pyx_t_16 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3647
 *         Rh = sp.csr_matrix((V, (I, J)), shape=(self.n_total_nodes, self.n_total_nodes))
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)             # <<<<<<<<<<<<<<
 *         while(last_ind > self.n_nodes):
 *             Rh = Rh*Rh
 */
  __Pyx_TraceLine(3647,0,__PYX_ERR(0, 3647, __pyx_L1_error))
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_16, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 3647, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_15) {
    __Pyx_INCREF(__pyx_t_16);
    __pyx_t_5 = __pyx_t_16;
  } else {
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = __pyx_t_1;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = __pyx_t_5;
  __Pyx_INCREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_last_ind = __pyx_t_16;
  __pyx_t_16 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3648
 *         # Test if it needs to be deflated again, (if any parents were also hanging)
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 *         while(last_ind > self.n_nodes):             # <<<<<<<<<<<<<<
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 */
  __Pyx_TraceLine(3648,0,__PYX_ERR(0, 3648, __pyx_L1_error))
  while (1) {
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3648, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_last_ind, __pyx_t_16, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3648, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 3648, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!__pyx_t_15) break;

    /* "discretize/_extensions/tree_ext.pyx":3649
 *         last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 *         while(last_ind > self.n_nodes):
 *             Rh = Rh*Rh             # <<<<<<<<<<<<<<
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 *         Rh = Rh[:, : last_ind]
 */
    __Pyx_TraceLine(3649,0,__PYX_ERR(0, 3649, __pyx_L1_error))
    __pyx_t_5 = PyNumber_Multiply(__pyx_v_Rh, __pyx_v_Rh); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3649, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3650
 *         while(last_ind > self.n_nodes):
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)             # <<<<<<<<<<<<<<
 *         Rh = Rh[:, : last_ind]
 *         return Rh
 */
    __Pyx_TraceLine(3650,0,__PYX_ERR(0, 3650, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_Rh, __pyx_n_s_getnnz); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(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, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_int_0);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_16 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_16, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_4, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_16, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 3650, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_15) {
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_4 = __pyx_t_5;
    } else {
      __Pyx_INCREF(__pyx_t_16);
      __pyx_t_4 = __pyx_t_16;
    }
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __pyx_t_4;
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_last_ind, __pyx_t_5);
    __pyx_t_5 = 0;
  }

  /* "discretize/_extensions/tree_ext.pyx":3651
 *             Rh = Rh*Rh
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 *         Rh = Rh[:, : last_ind]             # <<<<<<<<<<<<<<
 *         return Rh
 * 
 */
  __Pyx_TraceLine(3651,0,__PYX_ERR(0, 3651, __pyx_L1_error))
  __pyx_t_5 = PySlice_New(Py_None, __pyx_v_last_ind, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_slice__20);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_Rh, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3651, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF_SET(__pyx_v_Rh, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3652
 *             last_ind = max(np.nonzero(Rh.getnnz(0)>0)[0][-1], self.n_nodes)
 *         Rh = Rh[:, : last_ind]
 *         return Rh             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3652,0,__PYX_ERR(0, 3652, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Rh);
  __pyx_r = __pyx_v_Rh;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3615
 * 
 *     @cython.boundscheck(False)
 *     def _deflate_nodes(self):             # <<<<<<<<<<<<<<
 *         """Return a matrix that removes hanging faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._deflate_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rh);
  __Pyx_XDECREF(__pyx_v_last_ind);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3656
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_x_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from x-edges to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_n_epc;
  double __pyx_v_scale;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rex = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int_t __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3656, 0, __PYX_ERR(0, 3656, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3687
 *             phi_c = Axc @ phi_x
 *         """
 *         if self._average_edge_x_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_x_to_cell
 *         cdef np.int64_t[:] I,J
 */
  __Pyx_TraceLine(3687,0,__PYX_ERR(0, 3687, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_edge_x_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3688
 *         """
 *         if self._average_edge_x_to_cell is not None:
 *             return self._average_edge_x_to_cell             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(3688,0,__PYX_ERR(0, 3688, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_edge_x_to_cell);
    __pyx_r = __pyx_v_self->_average_edge_x_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3687
 *             phi_c = Axc @ phi_x
 *         """
 *         if self._average_edge_x_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_x_to_cell
 *         cdef np.int64_t[:] I,J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3694
 *         cdef double scale
 * 
 *         n_epc = 2*(self._dim-1)             # <<<<<<<<<<<<<<
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 */
  __Pyx_TraceLine(3694,0,__PYX_ERR(0, 3694, __pyx_L1_error))
  __pyx_v_n_epc = (2 * (__pyx_v_self->_dim - 1));

  /* "discretize/_extensions/tree_ext.pyx":3695
 * 
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 */
  __Pyx_TraceLine(3695,0,__PYX_ERR(0, 3695, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3695, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3696
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 */
  __Pyx_TraceLine(3696,0,__PYX_ERR(0, 3696, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3696, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3697
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(3697,0,__PYX_ERR(0, 3697, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3697, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3698
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             ind = cell.index
 */
  __Pyx_TraceLine(3698,0,__PYX_ERR(0, 3698, __pyx_L1_error))
  if (unlikely(__pyx_v_n_epc == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 3698, __pyx_L1_error)
  }
  __pyx_v_scale = (1.0 / ((double)__pyx_v_n_epc));

  /* "discretize/_extensions/tree_ext.pyx":3699
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
  __Pyx_TraceLine(3699,0,__PYX_ERR(0, 3699, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3700
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 */
    __Pyx_TraceLine(3700,0,__PYX_ERR(0, 3700, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3701
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             for ii in range(n_epc):             # <<<<<<<<<<<<<<
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii].index
 */
    __Pyx_TraceLine(3701,0,__PYX_ERR(0, 3701, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_n_epc;
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_ii = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":3702
 *             ind = cell.index
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind             # <<<<<<<<<<<<<<
 *                 J[ind*n_epc + ii] = cell.edges[ii].index
 *                 V[ind*n_epc + ii] = scale
 */
      __Pyx_TraceLine(3702,0,__PYX_ERR(0, 3702, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_17 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3703
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii].index             # <<<<<<<<<<<<<<
 *                 V[ind*n_epc + ii] = scale
 * 
 */
      __Pyx_TraceLine(3703,0,__PYX_ERR(0, 3703, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_cell->edges[__pyx_v_ii])->index;
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":3704
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii].index
 *                 V[ind*n_epc + ii] = scale             # <<<<<<<<<<<<<<
 * 
 *         Rex = self._deflate_edges_x()
 */
      __Pyx_TraceLine(3704,0,__PYX_ERR(0, 3704, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = __pyx_v_scale;
    }

    /* "discretize/_extensions/tree_ext.pyx":3699
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
    __Pyx_TraceLine(3699,0,__PYX_ERR(0, 3699, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3706
 *                 V[ind*n_epc + ii] = scale
 * 
 *         Rex = self._deflate_edges_x()             # <<<<<<<<<<<<<<
 *         self._average_edge_x_to_cell = sp.csr_matrix((V, (I, J)))*Rex
 *         return self._average_edge_x_to_cell
 */
  __Pyx_TraceLine(3706,0,__PYX_ERR(0, 3706, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_Rex = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3707
 * 
 *         Rex = self._deflate_edges_x()
 *         self._average_edge_x_to_cell = sp.csr_matrix((V, (I, J)))*Rex             # <<<<<<<<<<<<<<
 *         return self._average_edge_x_to_cell
 * 
 */
  __Pyx_TraceLine(3707,0,__PYX_ERR(0, 3707, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_19);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_19);
  __pyx_t_6 = 0;
  __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_19)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_7 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_19, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_7, __pyx_v_Rex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_x_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_x_to_cell);
  __pyx_v_self->_average_edge_x_to_cell = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3708
 *         Rex = self._deflate_edges_x()
 *         self._average_edge_x_to_cell = sp.csr_matrix((V, (I, J)))*Rex
 *         return self._average_edge_x_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3708,0,__PYX_ERR(0, 3708, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_edge_x_to_cell);
  __pyx_r = __pyx_v_self->_average_edge_x_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3656
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_x_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from x-edges to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_x_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rex);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3712
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_y_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from y-edges to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_n_epc;
  double __pyx_v_scale;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rey = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int_t __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3712, 0, __PYX_ERR(0, 3712, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3743
 *             phi_c = Ayc @ phi_y
 *         """
 *         if self._average_edge_y_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_y_to_cell
 *         cdef np.int64_t[:] I,J
 */
  __Pyx_TraceLine(3743,0,__PYX_ERR(0, 3743, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_edge_y_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3744
 *         """
 *         if self._average_edge_y_to_cell is not None:
 *             return self._average_edge_y_to_cell             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(3744,0,__PYX_ERR(0, 3744, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_edge_y_to_cell);
    __pyx_r = __pyx_v_self->_average_edge_y_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3743
 *             phi_c = Ayc @ phi_y
 *         """
 *         if self._average_edge_y_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_y_to_cell
 *         cdef np.int64_t[:] I,J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3750
 *         cdef double scale
 * 
 *         n_epc = 2*(self._dim-1)             # <<<<<<<<<<<<<<
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 */
  __Pyx_TraceLine(3750,0,__PYX_ERR(0, 3750, __pyx_L1_error))
  __pyx_v_n_epc = (2 * (__pyx_v_self->_dim - 1));

  /* "discretize/_extensions/tree_ext.pyx":3751
 * 
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 */
  __Pyx_TraceLine(3751,0,__PYX_ERR(0, 3751, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3751, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3752
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 */
  __Pyx_TraceLine(3752,0,__PYX_ERR(0, 3752, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3752, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3753
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(3753,0,__PYX_ERR(0, 3753, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3753, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3754
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             ind = cell.index
 */
  __Pyx_TraceLine(3754,0,__PYX_ERR(0, 3754, __pyx_L1_error))
  if (unlikely(__pyx_v_n_epc == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 3754, __pyx_L1_error)
  }
  __pyx_v_scale = (1.0 / ((double)__pyx_v_n_epc));

  /* "discretize/_extensions/tree_ext.pyx":3755
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
  __Pyx_TraceLine(3755,0,__PYX_ERR(0, 3755, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3756
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 */
    __Pyx_TraceLine(3756,0,__PYX_ERR(0, 3756, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3757
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             for ii in range(n_epc):             # <<<<<<<<<<<<<<
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[n_epc + ii].index #y edges
 */
    __Pyx_TraceLine(3757,0,__PYX_ERR(0, 3757, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_n_epc;
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_ii = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":3758
 *             ind = cell.index
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind             # <<<<<<<<<<<<<<
 *                 J[ind*n_epc + ii] = cell.edges[n_epc + ii].index #y edges
 *                 V[ind*n_epc + ii] = scale
 */
      __Pyx_TraceLine(3758,0,__PYX_ERR(0, 3758, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_17 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3759
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[n_epc + ii].index #y edges             # <<<<<<<<<<<<<<
 *                 V[ind*n_epc + ii] = scale
 * 
 */
      __Pyx_TraceLine(3759,0,__PYX_ERR(0, 3759, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_cell->edges[(__pyx_v_n_epc + __pyx_v_ii)])->index;
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":3760
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[n_epc + ii].index #y edges
 *                 V[ind*n_epc + ii] = scale             # <<<<<<<<<<<<<<
 * 
 *         Rey = self._deflate_edges_y()
 */
      __Pyx_TraceLine(3760,0,__PYX_ERR(0, 3760, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = __pyx_v_scale;
    }

    /* "discretize/_extensions/tree_ext.pyx":3755
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
    __Pyx_TraceLine(3755,0,__PYX_ERR(0, 3755, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3762
 *                 V[ind*n_epc + ii] = scale
 * 
 *         Rey = self._deflate_edges_y()             # <<<<<<<<<<<<<<
 *         self._average_edge_y_to_cell = sp.csr_matrix((V, (I, J)))*Rey
 *         return self._average_edge_y_to_cell
 */
  __Pyx_TraceLine(3762,0,__PYX_ERR(0, 3762, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_Rey = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3763
 * 
 *         Rey = self._deflate_edges_y()
 *         self._average_edge_y_to_cell = sp.csr_matrix((V, (I, J)))*Rey             # <<<<<<<<<<<<<<
 *         return self._average_edge_y_to_cell
 * 
 */
  __Pyx_TraceLine(3763,0,__PYX_ERR(0, 3763, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_19);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_19);
  __pyx_t_6 = 0;
  __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_19)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_7 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_19, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_7, __pyx_v_Rey); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_y_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_y_to_cell);
  __pyx_v_self->_average_edge_y_to_cell = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3764
 *         Rey = self._deflate_edges_y()
 *         self._average_edge_y_to_cell = sp.csr_matrix((V, (I, J)))*Rey
 *         return self._average_edge_y_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3764,0,__PYX_ERR(0, 3764, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_edge_y_to_cell);
  __pyx_r = __pyx_v_self->_average_edge_y_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3712
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_y_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from y-edges to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_y_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rey);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3768
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_z_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from z-edges to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ind;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_n_epc;
  double __pyx_v_scale;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rez = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int_t __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3768, 0, __PYX_ERR(0, 3768, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3799
 *             phi_c = Azc @ phi_z
 *         """
 *         if self._average_edge_z_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(3799,0,__PYX_ERR(0, 3799, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_edge_z_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3800
 *         """
 *         if self._average_edge_z_to_cell is not None:
 *             return self._average_edge_z_to_cell             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             raise Exception('There are no z-edges in 2D')
 */
    __Pyx_TraceLine(3800,0,__PYX_ERR(0, 3800, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_edge_z_to_cell);
    __pyx_r = __pyx_v_self->_average_edge_z_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3799
 *             phi_c = Azc @ phi_z
 *         """
 *         if self._average_edge_z_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3801
 *         if self._average_edge_z_to_cell is not None:
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('There are no z-edges in 2D')
 *         cdef np.int64_t[:] I,J
 */
  __Pyx_TraceLine(3801,0,__PYX_ERR(0, 3801, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "discretize/_extensions/tree_ext.pyx":3802
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:
 *             raise Exception('There are no z-edges in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(3802,0,__PYX_ERR(0, 3802, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3802, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 3802, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":3801
 *         if self._average_edge_z_to_cell is not None:
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('There are no z-edges in 2D')
 *         cdef np.int64_t[:] I,J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3808
 *         cdef double scale
 * 
 *         n_epc = 2*(self._dim-1)             # <<<<<<<<<<<<<<
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 */
  __Pyx_TraceLine(3808,0,__PYX_ERR(0, 3808, __pyx_L1_error))
  __pyx_v_n_epc = (2 * (__pyx_v_self->_dim - 1));

  /* "discretize/_extensions/tree_ext.pyx":3809
 * 
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 */
  __Pyx_TraceLine(3809,0,__PYX_ERR(0, 3809, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3809, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3810
 *         n_epc = 2*(self._dim-1)
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 */
  __Pyx_TraceLine(3810,0,__PYX_ERR(0, 3810, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 3810, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3811
 *         I = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(3811,0,__PYX_ERR(0, 3811, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_epc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 3811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3812
 *         J = np.empty(self.n_cells*n_epc, dtype=np.int64)
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             ind = cell.index
 */
  __Pyx_TraceLine(3812,0,__PYX_ERR(0, 3812, __pyx_L1_error))
  if (unlikely(__pyx_v_n_epc == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 3812, __pyx_L1_error)
  }
  __pyx_v_scale = (1.0 / ((double)__pyx_v_n_epc));

  /* "discretize/_extensions/tree_ext.pyx":3813
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
  __Pyx_TraceLine(3813,0,__PYX_ERR(0, 3813, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":3814
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 */
    __Pyx_TraceLine(3814,0,__PYX_ERR(0, 3814, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":3815
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             for ii in range(n_epc):             # <<<<<<<<<<<<<<
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii + 2*n_epc].index
 */
    __Pyx_TraceLine(3815,0,__PYX_ERR(0, 3815, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_n_epc;
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_ii = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":3816
 *             ind = cell.index
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind             # <<<<<<<<<<<<<<
 *                 J[ind*n_epc + ii] = cell.edges[ii + 2*n_epc].index
 *                 V[ind*n_epc + ii] = scale
 */
      __Pyx_TraceLine(3816,0,__PYX_ERR(0, 3816, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_I.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_17 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":3817
 *             for ii in range(n_epc):
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii + 2*n_epc].index             # <<<<<<<<<<<<<<
 *                 V[ind*n_epc + ii] = scale
 * 
 */
      __Pyx_TraceLine(3817,0,__PYX_ERR(0, 3817, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_cell->edges[(__pyx_v_ii + (2 * __pyx_v_n_epc))])->index;
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_18;

      /* "discretize/_extensions/tree_ext.pyx":3818
 *                 I[ind*n_epc + ii] = ind
 *                 J[ind*n_epc + ii] = cell.edges[ii + 2*n_epc].index
 *                 V[ind*n_epc + ii] = scale             # <<<<<<<<<<<<<<
 * 
 *         Rez = self._deflate_edges_z()
 */
      __Pyx_TraceLine(3818,0,__PYX_ERR(0, 3818, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_ind * __pyx_v_n_epc) + __pyx_v_ii);
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = __pyx_v_scale;
    }

    /* "discretize/_extensions/tree_ext.pyx":3813
 *         V = np.empty(self.n_cells*n_epc, dtype=np.float64)
 *         scale = 1.0/n_epc
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             for ii in range(n_epc):
 */
    __Pyx_TraceLine(3813,0,__PYX_ERR(0, 3813, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":3820
 *                 V[ind*n_epc + ii] = scale
 * 
 *         Rez = self._deflate_edges_z()             # <<<<<<<<<<<<<<
 *         self._average_edge_z_to_cell = sp.csr_matrix((V, (I, J)))*Rez
 *         return self._average_edge_z_to_cell
 */
  __Pyx_TraceLine(3820,0,__PYX_ERR(0, 3820, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_Rez = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3821
 * 
 *         Rez = self._deflate_edges_z()
 *         self._average_edge_z_to_cell = sp.csr_matrix((V, (I, J)))*Rez             # <<<<<<<<<<<<<<
 *         return self._average_edge_z_to_cell
 * 
 */
  __Pyx_TraceLine(3821,0,__PYX_ERR(0, 3821, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_3);
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_19);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_19);
  __pyx_t_6 = 0;
  __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_19)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_7 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_19, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_7, __pyx_v_Rez); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3821, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_edge_z_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_edge_z_to_cell);
  __pyx_v_self->_average_edge_z_to_cell = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":3822
 *         Rez = self._deflate_edges_z()
 *         self._average_edge_z_to_cell = sp.csr_matrix((V, (I, J)))*Rez
 *         return self._average_edge_z_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3822,0,__PYX_ERR(0, 3822, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_edge_z_to_cell);
  __pyx_r = __pyx_v_self->_average_edge_z_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3768
 *     @property
 *     @cython.boundscheck(False)
 *     def average_edge_z_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from z-edges to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_z_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rez);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3825
 * 
 *     @property
 *     def average_edge_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3825, 0, __PYX_ERR(0, 3825, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3856
 *             phi_c = Aec @ phi_e
 *         """
 *         if self._average_edge_to_cell is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 */
  __Pyx_TraceLine(3856,0,__PYX_ERR(0, 3856, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_edge_to_cell == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3857
 *         """
 *         if self._average_edge_to_cell is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]
 */
    __Pyx_TraceLine(3857,0,__PYX_ERR(0, 3857, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_x_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_y_to_cell); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_v_stacks = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3858
 *         if self._average_edge_to_cell is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell = 1.0/self._dim * sp.hstack(stacks).tocsr()
 */
    __Pyx_TraceLine(3858,0,__PYX_ERR(0, 3858, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":3859
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]             # <<<<<<<<<<<<<<
 *             self._average_edge_to_cell = 1.0/self._dim * sp.hstack(stacks).tocsr()
 *         return self._average_edge_to_cell
 */
      __Pyx_TraceLine(3859,0,__PYX_ERR(0, 3859, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_z_to_cell); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3859, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":3858
 *         if self._average_edge_to_cell is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell = 1.0/self._dim * sp.hstack(stacks).tocsr()
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3860
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell = 1.0/self._dim * sp.hstack(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_edge_to_cell
 * 
 */
    __Pyx_TraceLine(3860,0,__PYX_ERR(0, 3860, __pyx_L1_error))
    if (unlikely(__pyx_v_self->_dim == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 3860, __pyx_L1_error)
    }
    __pyx_t_5 = PyFloat_FromDouble((1.0 / ((double)__pyx_v_self->_dim))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_hstack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_stacks);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Multiply(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3860, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_self->_average_edge_to_cell);
    __Pyx_DECREF(__pyx_v_self->_average_edge_to_cell);
    __pyx_v_self->_average_edge_to_cell = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3856
 *             phi_c = Aec @ phi_e
 *         """
 *         if self._average_edge_to_cell is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3861
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell = 1.0/self._dim * sp.hstack(stacks).tocsr()
 *         return self._average_edge_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3861,0,__PYX_ERR(0, 3861, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_edge_to_cell);
  __pyx_r = __pyx_v_self->_average_edge_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3825
 * 
 *     @property
 *     def average_edge_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3864
 * 
 *     @property
 *     def average_edge_to_cell_vector(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to cell centers (vector quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3864, 0, __PYX_ERR(0, 3864, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3907
 *         the cell's center.
 *         """
 *         if self._average_edge_to_cell_vector is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 */
  __Pyx_TraceLine(3907,0,__PYX_ERR(0, 3907, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_edge_to_cell_vector == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":3908
 *         """
 *         if self._average_edge_to_cell_vector is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]
 */
    __Pyx_TraceLine(3908,0,__PYX_ERR(0, 3908, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_x_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_y_to_cell); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3908, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_v_stacks = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3909
 *         if self._average_edge_to_cell_vector is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell_vector = sp.block_diag(stacks).tocsr()
 */
    __Pyx_TraceLine(3909,0,__PYX_ERR(0, 3909, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":3910
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]             # <<<<<<<<<<<<<<
 *             self._average_edge_to_cell_vector = sp.block_diag(stacks).tocsr()
 *         return self._average_edge_to_cell_vector
 */
      __Pyx_TraceLine(3910,0,__PYX_ERR(0, 3910, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_z_to_cell); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":3909
 *         if self._average_edge_to_cell_vector is None:
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell_vector = sp.block_diag(stacks).tocsr()
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3911
 *             if self._dim == 3:
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell_vector = sp.block_diag(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_edge_to_cell_vector
 * 
 */
    __Pyx_TraceLine(3911,0,__PYX_ERR(0, 3911, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_stacks);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->_average_edge_to_cell_vector);
    __Pyx_DECREF(__pyx_v_self->_average_edge_to_cell_vector);
    __pyx_v_self->_average_edge_to_cell_vector = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3907
 *         the cell's center.
 *         """
 *         if self._average_edge_to_cell_vector is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_edge_x_to_cell, self.average_edge_y_to_cell]
 *             if self._dim == 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3912
 *                 stacks += [self.average_edge_z_to_cell]
 *             self._average_edge_to_cell_vector = sp.block_diag(stacks).tocsr()
 *         return self._average_edge_to_cell_vector             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(3912,0,__PYX_ERR(0, 3912, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_edge_to_cell_vector);
  __pyx_r = __pyx_v_self->_average_edge_to_cell_vector;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3864
 * 
 *     @property
 *     def average_edge_to_cell_vector(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to cell centers (vector quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_to_cell_vector.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":3915
 * 
 *     @property
 *     def average_edge_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  CYTHON_UNUSED int_t __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face;
  int_t __pyx_v_ii;
  int_t __pyx_v_face_offset_y;
  int_t __pyx_v_face_offset_z;
  int_t __pyx_v_edge_offset_y;
  int_t __pyx_v_edge_offset_z;
  std::pair<int_t,Face *>  __pyx_v_it;
  PyObject *__pyx_v_Av = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int_t __pyx_t_9;
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_11 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_12;
  face_map_t *__pyx_t_13;
  std::pair<int_t,Face *>  __pyx_t_14;
  Face *__pyx_t_15;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3915, 0, __PYX_ERR(0, 3915, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":3944
 *         where :math:`\mathbf{u_f}` is a quantity defined on the respective faces.
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return sp.diags(
 *                 [1, 1],
 */
  __Pyx_TraceLine(3944,0,__PYX_ERR(0, 3944, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3944, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":3945
 *         """
 *         if self.dim == 2:
 *             return sp.diags(             # <<<<<<<<<<<<<<
 *                 [1, 1],
 *                 [-self.n_faces_x, self.n_faces_y],
 */
    __Pyx_TraceLine(3945,0,__PYX_ERR(0, 3945, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_diags); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3946
 *         if self.dim == 2:
 *             return sp.diags(
 *                 [1, 1],             # <<<<<<<<<<<<<<
 *                 [-self.n_faces_x, self.n_faces_y],
 *                 shape=(self.n_faces, self.n_edges)
 */
    __Pyx_TraceLine(3946,0,__PYX_ERR(0, 3946, __pyx_L1_error))
    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3946, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_int_1);
    __Pyx_GIVEREF(__pyx_int_1);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_int_1);
    __Pyx_INCREF(__pyx_int_1);
    __Pyx_GIVEREF(__pyx_int_1);
    PyList_SET_ITEM(__pyx_t_2, 1, __pyx_int_1);

    /* "discretize/_extensions/tree_ext.pyx":3947
 *             return sp.diags(
 *                 [1, 1],
 *                 [-self.n_faces_x, self.n_faces_y],             # <<<<<<<<<<<<<<
 *                 shape=(self.n_faces, self.n_edges)
 *             )
 */
    __Pyx_TraceLine(3947,0,__PYX_ERR(0, 3947, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyNumber_Negative(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
    __pyx_t_5 = 0;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3945
 *         """
 *         if self.dim == 2:
 *             return sp.diags(             # <<<<<<<<<<<<<<
 *                 [1, 1],
 *                 [-self.n_faces_x, self.n_faces_y],
 */
    __Pyx_TraceLine(3945,0,__PYX_ERR(0, 3945, __pyx_L1_error))
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3948
 *                 [1, 1],
 *                 [-self.n_faces_x, self.n_faces_y],
 *                 shape=(self.n_faces, self.n_edges)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __Pyx_TraceLine(3948,0,__PYX_ERR(0, 3948, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 3948, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":3945
 *         """
 *         if self.dim == 2:
 *             return sp.diags(             # <<<<<<<<<<<<<<
 *                 [1, 1],
 *                 [-self.n_faces_x, self.n_faces_y],
 */
    __Pyx_TraceLine(3945,0,__PYX_ERR(0, 3945, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3945, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3944
 *         where :math:`\mathbf{u_f}` is a quantity defined on the respective faces.
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return sp.diags(
 *                 [1, 1],
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3951
 *             )
 * 
 *         if self._average_edge_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_to_face
 *         cdef:
 */
  __Pyx_TraceLine(3951,0,__PYX_ERR(0, 3951, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_to_face); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3951, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = (__pyx_t_7 != Py_None);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_8 = (__pyx_t_3 != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":3952
 * 
 *         if self._average_edge_to_face is not None:
 *             return self._average_edge_to_face             # <<<<<<<<<<<<<<
 *         cdef:
 *             int_t dim = self._dim
 */
    __Pyx_TraceLine(3952,0,__PYX_ERR(0, 3952, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_to_face); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":3951
 *             )
 * 
 *         if self._average_edge_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_edge_to_face
 *         cdef:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":3954
 *             return self._average_edge_to_face
 *         cdef:
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             np.int64_t[:] I = np.empty(4*self.n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*self.n_faces, dtype=np.int64)
 */
  __Pyx_TraceLine(3954,0,__PYX_ERR(0, 3954, __pyx_L1_error))
  __pyx_t_9 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":3955
 *         cdef:
 *             int_t dim = self._dim
 *             np.int64_t[:] I = np.empty(4*self.n_faces, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] J = np.empty(4*self.n_faces, dtype=np.int64)
 *             np.float64_t[:] V = np.full(4*self.n_faces, 0.25, dtype=np.float64)
 */
  __Pyx_TraceLine(3955,0,__PYX_ERR(0, 3955, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = PyNumber_Multiply(__pyx_int_4, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 3955, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_I = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3956
 *             int_t dim = self._dim
 *             np.int64_t[:] I = np.empty(4*self.n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*self.n_faces, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] V = np.full(4*self.n_faces, 0.25, dtype=np.float64)
 *             Face *face
 */
  __Pyx_TraceLine(3956,0,__PYX_ERR(0, 3956, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_4, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 3956, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_J = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3957
 *             np.int64_t[:] I = np.empty(4*self.n_faces, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(4*self.n_faces, dtype=np.int64)
 *             np.float64_t[:] V = np.full(4*self.n_faces, 0.25, dtype=np.float64)             # <<<<<<<<<<<<<<
 *             Face *face
 *             int_t ii
 */
  __Pyx_TraceLine(3957,0,__PYX_ERR(0, 3957, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_full); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_INCREF(__pyx_float_0_25);
  __Pyx_GIVEREF(__pyx_float_0_25);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_float_0_25);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 3957, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_V = __pyx_t_11;
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":3960
 *             Face *face
 *             int_t ii
 *             int_t face_offset_y = self.n_faces_x             # <<<<<<<<<<<<<<
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y
 *             int_t edge_offset_y = self.n_total_edges_x
 */
  __Pyx_TraceLine(3960,0,__PYX_ERR(0, 3960, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3960, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_9 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3960, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_face_offset_y = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":3961
 *             int_t ii
 *             int_t face_offset_y = self.n_faces_x
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y             # <<<<<<<<<<<<<<
 *             int_t edge_offset_y = self.n_total_edges_x
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y
 */
  __Pyx_TraceLine(3961,0,__PYX_ERR(0, 3961, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyNumber_Add(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_9 = __Pyx_PyInt_As_int_t(__pyx_t_1); if (unlikely((__pyx_t_9 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3961, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_face_offset_z = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":3962
 *             int_t face_offset_y = self.n_faces_x
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y
 *             int_t edge_offset_y = self.n_total_edges_x             # <<<<<<<<<<<<<<
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y
 *             double area
 */
  __Pyx_TraceLine(3962,0,__PYX_ERR(0, 3962, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyInt_As_int_t(__pyx_t_1); if (unlikely((__pyx_t_9 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3962, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_edge_offset_y = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":3963
 *             int_t face_offset_z = self.n_faces_x + self.n_faces_y
 *             int_t edge_offset_y = self.n_total_edges_x
 *             int_t edge_offset_z = self.n_total_edges_x + self.n_total_edges_y             # <<<<<<<<<<<<<<
 *             double area
 * 
 */
  __Pyx_TraceLine(3963,0,__PYX_ERR(0, 3963, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_9 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_9 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3963, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_edge_offset_z = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":3966
 *             double area
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(3966,0,__PYX_ERR(0, 3966, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->faces_x;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":3967
 * 
 *         for it in self.tree.faces_x:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(3967,0,__PYX_ERR(0, 3967, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":3968
 *         for it in self.tree.faces_x:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    __Pyx_TraceLine(3968,0,__PYX_ERR(0, 3968, __pyx_L1_error))
    __pyx_t_8 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_8) {

      /* "discretize/_extensions/tree_ext.pyx":3969
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             I[4*ii : 4*ii + 4] = ii
 */
      __Pyx_TraceLine(3969,0,__PYX_ERR(0, 3969, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":3968
 *         for it in self.tree.faces_x:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3970
 *             if face.hanging:
 *                 continue
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 */
    __Pyx_TraceLine(3970,0,__PYX_ERR(0, 3970, __pyx_L1_error))
    __pyx_t_9 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":3971
 *                 continue
 *             ii = face.index
 *             I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index + edge_offset_y
 */
    __Pyx_TraceLine(3971,0,__PYX_ERR(0, 3971, __pyx_L1_error))
    __pyx_t_10.data = __pyx_v_I.data;
    __pyx_t_10.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3971, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_10.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3972
 *             ii = face.index
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z             # <<<<<<<<<<<<<<
 *             J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 */
    __Pyx_TraceLine(3972,0,__PYX_ERR(0, 3972, __pyx_L1_error))
    __pyx_t_17 = (4 * __pyx_v_ii);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3972, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":3973
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index + edge_offset_y             # <<<<<<<<<<<<<<
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *             J[4*ii + 3] = face.edges[3].index + edge_offset_y
 */
    __Pyx_TraceLine(3973,0,__PYX_ERR(0, 3973, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3973, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[1])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":3974
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z             # <<<<<<<<<<<<<<
 *             J[4*ii + 3] = face.edges[3].index + edge_offset_y
 * 
 */
    __Pyx_TraceLine(3974,0,__PYX_ERR(0, 3974, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3974, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":3975
 *             J[4*ii + 1] = face.edges[1].index + edge_offset_y
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *             J[4*ii + 3] = face.edges[3].index + edge_offset_y             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_y:
 */
    __Pyx_TraceLine(3975,0,__PYX_ERR(0, 3975, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3975, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[3])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":3966
 *             double area
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(3966,0,__PYX_ERR(0, 3966, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3977
 *             J[4*ii + 3] = face.edges[3].index + edge_offset_y
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(3977,0,__PYX_ERR(0, 3977, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->faces_y;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":3978
 * 
 *         for it in self.tree.faces_y:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(3978,0,__PYX_ERR(0, 3978, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":3979
 *         for it in self.tree.faces_y:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_y
 */
    __Pyx_TraceLine(3979,0,__PYX_ERR(0, 3979, __pyx_L1_error))
    __pyx_t_8 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_8) {

      /* "discretize/_extensions/tree_ext.pyx":3980
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index + face_offset_y
 *             I[4*ii : 4*ii + 4] = ii
 */
      __Pyx_TraceLine(3980,0,__PYX_ERR(0, 3980, __pyx_L1_error))
      goto __pyx_L8_continue;

      /* "discretize/_extensions/tree_ext.pyx":3979
 *         for it in self.tree.faces_y:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_y
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3981
 *             if face.hanging:
 *                 continue
 *             ii = face.index + face_offset_y             # <<<<<<<<<<<<<<
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 */
    __Pyx_TraceLine(3981,0,__PYX_ERR(0, 3981, __pyx_L1_error))
    __pyx_v_ii = (__pyx_v_face->index + __pyx_v_face_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":3982
 *                 continue
 *             ii = face.index + face_offset_y
 *             I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index
 */
    __Pyx_TraceLine(3982,0,__PYX_ERR(0, 3982, __pyx_L1_error))
    __pyx_t_10.data = __pyx_v_I.data;
    __pyx_t_10.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3982, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_10.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3983
 *             ii = face.index + face_offset_y
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z             # <<<<<<<<<<<<<<
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 */
    __Pyx_TraceLine(3983,0,__PYX_ERR(0, 3983, __pyx_L1_error))
    __pyx_t_17 = (4 * __pyx_v_ii);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3983, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":3984
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index             # <<<<<<<<<<<<<<
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *             J[4*ii + 3] = face.edges[3].index
 */
    __Pyx_TraceLine(3984,0,__PYX_ERR(0, 3984, __pyx_L1_error))
    __pyx_t_9 = (__pyx_v_face->edges[1])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3984, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":3985
 *             J[4*ii    ] = face.edges[0].index + edge_offset_z
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z             # <<<<<<<<<<<<<<
 *             J[4*ii + 3] = face.edges[3].index
 * 
 */
    __Pyx_TraceLine(3985,0,__PYX_ERR(0, 3985, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3985, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":3986
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_z
 *             J[4*ii + 3] = face.edges[3].index             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_z:
 */
    __Pyx_TraceLine(3986,0,__PYX_ERR(0, 3986, __pyx_L1_error))
    __pyx_t_9 = (__pyx_v_face->edges[3])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3986, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":3977
 *             J[4*ii + 3] = face.edges[3].index + edge_offset_y
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(3977,0,__PYX_ERR(0, 3977, __pyx_L1_error))
    __pyx_L8_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3988
 *             J[4*ii + 3] = face.edges[3].index
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(3988,0,__PYX_ERR(0, 3988, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->faces_z;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_it = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":3989
 * 
 *         for it in self.tree.faces_z:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(3989,0,__PYX_ERR(0, 3989, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":3990
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_z
 */
    __Pyx_TraceLine(3990,0,__PYX_ERR(0, 3990, __pyx_L1_error))
    __pyx_t_8 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_8) {

      /* "discretize/_extensions/tree_ext.pyx":3991
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii
 */
      __Pyx_TraceLine(3991,0,__PYX_ERR(0, 3991, __pyx_L1_error))
      goto __pyx_L11_continue;

      /* "discretize/_extensions/tree_ext.pyx":3990
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index + face_offset_z
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":3992
 *             if face.hanging:
 *                 continue
 *             ii = face.index + face_offset_z             # <<<<<<<<<<<<<<
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 */
    __Pyx_TraceLine(3992,0,__PYX_ERR(0, 3992, __pyx_L1_error))
    __pyx_v_ii = (__pyx_v_face->index + __pyx_v_face_offset_z);

    /* "discretize/_extensions/tree_ext.pyx":3993
 *                 continue
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii             # <<<<<<<<<<<<<<
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index
 */
    __Pyx_TraceLine(3993,0,__PYX_ERR(0, 3993, __pyx_L1_error))
    __pyx_t_10.data = __pyx_v_I.data;
    __pyx_t_10.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_16 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_16,
    (4 * __pyx_v_ii),
    ((4 * __pyx_v_ii) + 4),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 3993, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_10.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_10.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_10.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":3994
 *             ii = face.index + face_offset_z
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y             # <<<<<<<<<<<<<<
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 */
    __Pyx_TraceLine(3994,0,__PYX_ERR(0, 3994, __pyx_L1_error))
    __pyx_t_17 = (4 * __pyx_v_ii);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3994, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[0])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":3995
 *             I[4*ii : 4*ii + 4] = ii
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index             # <<<<<<<<<<<<<<
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 *             J[4*ii + 3] = face.edges[3].index
 */
    __Pyx_TraceLine(3995,0,__PYX_ERR(0, 3995, __pyx_L1_error))
    __pyx_t_9 = (__pyx_v_face->edges[1])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 1);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3995, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":3996
 *             J[4*ii    ] = face.edges[0].index + edge_offset_y
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y             # <<<<<<<<<<<<<<
 *             J[4*ii + 3] = face.edges[3].index
 * 
 */
    __Pyx_TraceLine(3996,0,__PYX_ERR(0, 3996, __pyx_L1_error))
    __pyx_t_17 = ((4 * __pyx_v_ii) + 2);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3996, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = ((__pyx_v_face->edges[2])->index + __pyx_v_edge_offset_y);

    /* "discretize/_extensions/tree_ext.pyx":3997
 *             J[4*ii + 1] = face.edges[1].index
 *             J[4*ii + 2] = face.edges[2].index + edge_offset_y
 *             J[4*ii + 3] = face.edges[3].index             # <<<<<<<<<<<<<<
 * 
 *         Av = sp.csr_matrix((V, (I, J)),shape=(self.n_faces, self.n_total_edges))
 */
    __Pyx_TraceLine(3997,0,__PYX_ERR(0, 3997, __pyx_L1_error))
    __pyx_t_9 = (__pyx_v_face->edges[3])->index;
    __pyx_t_17 = ((4 * __pyx_v_ii) + 3);
    __pyx_t_16 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_J.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_16 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_J.shape[0])) __pyx_t_16 = 0;
    if (unlikely(__pyx_t_16 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_16);
      __PYX_ERR(0, 3997, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":3988
 *             J[4*ii + 3] = face.edges[3].index
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(3988,0,__PYX_ERR(0, 3988, __pyx_L1_error))
    __pyx_L11_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":3999
 *             J[4*ii + 3] = face.edges[3].index
 * 
 *         Av = sp.csr_matrix((V, (I, J)),shape=(self.n_faces, self.n_total_edges))             # <<<<<<<<<<<<<<
 *         R = self._deflate_edges()
 * 
 */
  __Pyx_TraceLine(3999,0,__PYX_ERR(0, 3999, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
  __pyx_t_1 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_4);
  __pyx_t_6 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_6 = 0;
  __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_shape, __pyx_t_2) < 0) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3999, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Av = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4000
 * 
 *         Av = sp.csr_matrix((V, (I, J)),shape=(self.n_faces, self.n_total_edges))
 *         R = self._deflate_edges()             # <<<<<<<<<<<<<<
 * 
 *         self._average_edge_to_face = Av @ R
 */
  __Pyx_TraceLine(4000,0,__PYX_ERR(0, 4000, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_R = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4002
 *         R = self._deflate_edges()
 * 
 *         self._average_edge_to_face = Av @ R             # <<<<<<<<<<<<<<
 *         return self._average_edge_to_face
 * 
 */
  __Pyx_TraceLine(4002,0,__PYX_ERR(0, 4002, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyNumber_MatrixMultiply(__pyx_v_Av, __pyx_v_R); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_to_face, __pyx_t_2) < 0) __PYX_ERR(0, 4002, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4003
 * 
 *         self._average_edge_to_face = Av @ R
 *         return self._average_edge_to_face             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4003,0,__PYX_ERR(0, 4003, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_to_face); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4003, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":3915
 * 
 *     @property
 *     def average_edge_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from edges to faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_edge_to_face.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Av);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4007
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_x_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from x-faces to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face1;
  Face *__pyx_v_face2;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rfx = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  int __pyx_t_14;
  int_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4007, 0, __PYX_ERR(0, 4007, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4038
 *             phi_c = Axc @ phi_x
 *         """
 *         if self._average_face_x_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_x_to_cell
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(4038,0,__PYX_ERR(0, 4038, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_face_x_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4039
 *         """
 *         if self._average_face_x_to_cell is not None:
 *             return self._average_face_x_to_cell             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             return self.average_edge_y_to_cell
 */
    __Pyx_TraceLine(4039,0,__PYX_ERR(0, 4039, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_face_x_to_cell);
    __pyx_r = __pyx_v_self->_average_face_x_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4038
 *             phi_c = Axc @ phi_x
 *         """
 *         if self._average_face_x_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_x_to_cell
 *         if self._dim == 2:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4040
 *         if self._average_face_x_to_cell is not None:
 *             return self._average_face_x_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_edge_y_to_cell
 * 
 */
  __Pyx_TraceLine(4040,0,__PYX_ERR(0, 4040, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4041
 *             return self._average_face_x_to_cell
 *         if self._dim == 2:
 *             return self.average_edge_y_to_cell             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t[:] I,J
 */
    __Pyx_TraceLine(4041,0,__PYX_ERR(0, 4041, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_y_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4041, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4040
 *         if self._average_face_x_to_cell is not None:
 *             return self._average_face_x_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_edge_y_to_cell
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4048
 *         cdef Face *face2
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4048,0,__PYX_ERR(0, 4048, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4048, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4049
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4049,0,__PYX_ERR(0, 4049, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4049, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4050
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(4050,0,__PYX_ERR(0, 4050, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4050, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4052
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[0] # x face
 *             face2 = cell.faces[1] # x face
 */
  __Pyx_TraceLine(4052,0,__PYX_ERR(0, 4052, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4053
 * 
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[0] # x face             # <<<<<<<<<<<<<<
 *             face2 = cell.faces[1] # x face
 *             ii = cell.index
 */
    __Pyx_TraceLine(4053,0,__PYX_ERR(0, 4053, __pyx_L1_error))
    __pyx_v_face1 = (__pyx_v_cell->faces[0]);

    /* "discretize/_extensions/tree_ext.pyx":4054
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[0] # x face
 *             face2 = cell.faces[1] # x face             # <<<<<<<<<<<<<<
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 */
    __Pyx_TraceLine(4054,0,__PYX_ERR(0, 4054, __pyx_L1_error))
    __pyx_v_face2 = (__pyx_v_cell->faces[1]);

    /* "discretize/_extensions/tree_ext.pyx":4055
 *             face1 = cell.faces[0] # x face
 *             face2 = cell.faces[1] # x face
 *             ii = cell.index             # <<<<<<<<<<<<<<
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 */
    __Pyx_TraceLine(4055,0,__PYX_ERR(0, 4055, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ii = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4056
 *             face2 = cell.faces[1] # x face
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 */
    __Pyx_TraceLine(4056,0,__PYX_ERR(0, 4056, __pyx_L1_error))
    __pyx_t_8.data = __pyx_v_I.data;
    __pyx_t_8.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_8, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_8,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4056, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_8.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_8.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_8.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4057
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index             # <<<<<<<<<<<<<<
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5
 */
    __Pyx_TraceLine(4057,0,__PYX_ERR(0, 4057, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face1->index;
    __pyx_t_16 = (__pyx_v_ii * 2);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4058
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index             # <<<<<<<<<<<<<<
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 */
    __Pyx_TraceLine(4058,0,__PYX_ERR(0, 4058, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face2->index;
    __pyx_t_16 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4059
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rfx = self._deflate_faces_x()
 */
    __Pyx_TraceLine(4059,0,__PYX_ERR(0, 4059, __pyx_L1_error))
    __pyx_t_9.data = __pyx_v_V.data;
    __pyx_t_9.memview = __pyx_v_V.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_V.shape[0], __pyx_v_V.strides[0], __pyx_v_V.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4059, __pyx_L1_error)
}

{
        __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.5;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_9.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4052
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[0] # x face
 *             face2 = cell.faces[1] # x face
 */
    __Pyx_TraceLine(4052,0,__PYX_ERR(0, 4052, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":4061
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 *         Rfx = self._deflate_faces_x()             # <<<<<<<<<<<<<<
 *         self._average_face_x_to_cell = sp.csr_matrix((V, (I, J)))*Rfx
 *         return self._average_face_x_to_cell
 */
  __Pyx_TraceLine(4061,0,__PYX_ERR(0, 4061, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rfx = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4062
 * 
 *         Rfx = self._deflate_faces_x()
 *         self._average_face_x_to_cell = sp.csr_matrix((V, (I, J)))*Rfx             # <<<<<<<<<<<<<<
 *         return self._average_face_x_to_cell
 * 
 */
  __Pyx_TraceLine(4062,0,__PYX_ERR(0, 4062, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_17);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_17);
  __pyx_t_7 = 0;
  __pyx_t_17 = 0;
  __pyx_t_17 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_17)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_17, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_4, __pyx_v_Rfx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_6);
  __Pyx_GOTREF(__pyx_v_self->_average_face_x_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_x_to_cell);
  __pyx_v_self->_average_face_x_to_cell = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4063
 *         Rfx = self._deflate_faces_x()
 *         self._average_face_x_to_cell = sp.csr_matrix((V, (I, J)))*Rfx
 *         return self._average_face_x_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4063,0,__PYX_ERR(0, 4063, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_face_x_to_cell);
  __pyx_r = __pyx_v_self->_average_face_x_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4007
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_x_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from x-faces to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_face_x_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rfx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4067
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_y_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from y-faces to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face1;
  Face *__pyx_v_face2;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rfy = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  int __pyx_t_14;
  int_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4067, 0, __PYX_ERR(0, 4067, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4098
 *             phi_c = Ayc @ phi_y
 *         """
 *         if self._average_face_y_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_y_to_cell
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(4098,0,__PYX_ERR(0, 4098, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_face_y_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4099
 *         """
 *         if self._average_face_y_to_cell is not None:
 *             return self._average_face_y_to_cell             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             return self.average_edge_x_to_cell
 */
    __Pyx_TraceLine(4099,0,__PYX_ERR(0, 4099, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_face_y_to_cell);
    __pyx_r = __pyx_v_self->_average_face_y_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4098
 *             phi_c = Ayc @ phi_y
 *         """
 *         if self._average_face_y_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_y_to_cell
 *         if self._dim == 2:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4100
 *         if self._average_face_y_to_cell is not None:
 *             return self._average_face_y_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_edge_x_to_cell
 * 
 */
  __Pyx_TraceLine(4100,0,__PYX_ERR(0, 4100, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4101
 *             return self._average_face_y_to_cell
 *         if self._dim == 2:
 *             return self.average_edge_x_to_cell             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t[:] I,J
 */
    __Pyx_TraceLine(4101,0,__PYX_ERR(0, 4101, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_edge_x_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4100
 *         if self._average_face_y_to_cell is not None:
 *             return self._average_face_y_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_edge_x_to_cell
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4108
 *         cdef Face *face2
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4108,0,__PYX_ERR(0, 4108, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4108, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4109
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4109,0,__PYX_ERR(0, 4109, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4109, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4110
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(4110,0,__PYX_ERR(0, 4110, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4110, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4112
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[2] # y face
 *             face2 = cell.faces[3] # y face
 */
  __Pyx_TraceLine(4112,0,__PYX_ERR(0, 4112, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4113
 * 
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[2] # y face             # <<<<<<<<<<<<<<
 *             face2 = cell.faces[3] # y face
 *             ii = cell.index
 */
    __Pyx_TraceLine(4113,0,__PYX_ERR(0, 4113, __pyx_L1_error))
    __pyx_v_face1 = (__pyx_v_cell->faces[2]);

    /* "discretize/_extensions/tree_ext.pyx":4114
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[2] # y face
 *             face2 = cell.faces[3] # y face             # <<<<<<<<<<<<<<
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 */
    __Pyx_TraceLine(4114,0,__PYX_ERR(0, 4114, __pyx_L1_error))
    __pyx_v_face2 = (__pyx_v_cell->faces[3]);

    /* "discretize/_extensions/tree_ext.pyx":4115
 *             face1 = cell.faces[2] # y face
 *             face2 = cell.faces[3] # y face
 *             ii = cell.index             # <<<<<<<<<<<<<<
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 */
    __Pyx_TraceLine(4115,0,__PYX_ERR(0, 4115, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ii = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4116
 *             face2 = cell.faces[3] # y face
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 */
    __Pyx_TraceLine(4116,0,__PYX_ERR(0, 4116, __pyx_L1_error))
    __pyx_t_8.data = __pyx_v_I.data;
    __pyx_t_8.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_8, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_8,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4116, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_8.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_8.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_8.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4117
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index             # <<<<<<<<<<<<<<
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5
 */
    __Pyx_TraceLine(4117,0,__PYX_ERR(0, 4117, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face1->index;
    __pyx_t_16 = (__pyx_v_ii * 2);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4118
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index             # <<<<<<<<<<<<<<
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 */
    __Pyx_TraceLine(4118,0,__PYX_ERR(0, 4118, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face2->index;
    __pyx_t_16 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4119
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rfy = self._deflate_faces_y()
 */
    __Pyx_TraceLine(4119,0,__PYX_ERR(0, 4119, __pyx_L1_error))
    __pyx_t_9.data = __pyx_v_V.data;
    __pyx_t_9.memview = __pyx_v_V.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_V.shape[0], __pyx_v_V.strides[0], __pyx_v_V.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4119, __pyx_L1_error)
}

{
        __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.5;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_9.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4112
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[2] # y face
 *             face2 = cell.faces[3] # y face
 */
    __Pyx_TraceLine(4112,0,__PYX_ERR(0, 4112, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":4121
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 *         Rfy = self._deflate_faces_y()             # <<<<<<<<<<<<<<
 *         self._average_face_y_to_cell = sp.csr_matrix((V, (I, J)))*Rfy
 *         return self._average_face_y_to_cell
 */
  __Pyx_TraceLine(4121,0,__PYX_ERR(0, 4121, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rfy = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4122
 * 
 *         Rfy = self._deflate_faces_y()
 *         self._average_face_y_to_cell = sp.csr_matrix((V, (I, J)))*Rfy             # <<<<<<<<<<<<<<
 *         return self._average_face_y_to_cell
 * 
 */
  __Pyx_TraceLine(4122,0,__PYX_ERR(0, 4122, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_17);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_17);
  __pyx_t_7 = 0;
  __pyx_t_17 = 0;
  __pyx_t_17 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_17)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_17, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_4, __pyx_v_Rfy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_6);
  __Pyx_GOTREF(__pyx_v_self->_average_face_y_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_y_to_cell);
  __pyx_v_self->_average_face_y_to_cell = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4123
 *         Rfy = self._deflate_faces_y()
 *         self._average_face_y_to_cell = sp.csr_matrix((V, (I, J)))*Rfy
 *         return self._average_face_y_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4123,0,__PYX_ERR(0, 4123, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_face_y_to_cell);
  __pyx_r = __pyx_v_self->_average_face_y_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4067
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_y_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from y-faces to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_face_y_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rfy);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4127
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_z_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from z-faces to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  Face *__pyx_v_face1;
  Face *__pyx_v_face2;
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rfy = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  int __pyx_t_14;
  int_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4127, 0, __PYX_ERR(0, 4127, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4158
 *             phi_c = Azc @ phi_z
 *         """
 *         if self._average_face_z_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:
 */
  __Pyx_TraceLine(4158,0,__PYX_ERR(0, 4158, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_face_z_to_cell != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4159
 *         """
 *         if self._average_face_z_to_cell is not None:
 *             return self._average_face_z_to_cell             # <<<<<<<<<<<<<<
 *         if self._dim == 2:
 *             raise Exception('There are no z-faces in 2D')
 */
    __Pyx_TraceLine(4159,0,__PYX_ERR(0, 4159, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_face_z_to_cell);
    __pyx_r = __pyx_v_self->_average_face_z_to_cell;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4158
 *             phi_c = Azc @ phi_z
 *         """
 *         if self._average_face_z_to_cell is not None:             # <<<<<<<<<<<<<<
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4160
 *         if self._average_face_z_to_cell is not None:
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('There are no z-faces in 2D')
 *         cdef np.int64_t[:] I,J
 */
  __Pyx_TraceLine(4160,0,__PYX_ERR(0, 4160, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 2) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "discretize/_extensions/tree_ext.pyx":4161
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:
 *             raise Exception('There are no z-faces in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4161,0,__PYX_ERR(0, 4161, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4161, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 4161, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":4160
 *         if self._average_face_z_to_cell is not None:
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('There are no z-faces in 2D')
 *         cdef np.int64_t[:] I,J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4167
 *         cdef Face *face2
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4167,0,__PYX_ERR(0, 4167, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4167, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4168
 *         cdef np.int64_t ii
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4168,0,__PYX_ERR(0, 4168, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4168, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4169
 *         I = np.empty(self.n_cells*2, dtype=np.int64)
 *         J = np.empty(self.n_cells*2, dtype=np.int64)
 *         V = np.empty(self.n_cells*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(4169,0,__PYX_ERR(0, 4169, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4169, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4171
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[4]
 *             face2 = cell.faces[5]
 */
  __Pyx_TraceLine(4171,0,__PYX_ERR(0, 4171, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->cells;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_cell = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4172
 * 
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[4]             # <<<<<<<<<<<<<<
 *             face2 = cell.faces[5]
 *             ii = cell.index
 */
    __Pyx_TraceLine(4172,0,__PYX_ERR(0, 4172, __pyx_L1_error))
    __pyx_v_face1 = (__pyx_v_cell->faces[4]);

    /* "discretize/_extensions/tree_ext.pyx":4173
 *         for cell in self.tree.cells:
 *             face1 = cell.faces[4]
 *             face2 = cell.faces[5]             # <<<<<<<<<<<<<<
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 */
    __Pyx_TraceLine(4173,0,__PYX_ERR(0, 4173, __pyx_L1_error))
    __pyx_v_face2 = (__pyx_v_cell->faces[5]);

    /* "discretize/_extensions/tree_ext.pyx":4174
 *             face1 = cell.faces[4]
 *             face2 = cell.faces[5]
 *             ii = cell.index             # <<<<<<<<<<<<<<
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 */
    __Pyx_TraceLine(4174,0,__PYX_ERR(0, 4174, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_cell->index;
    __pyx_v_ii = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4175
 *             face2 = cell.faces[5]
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii             # <<<<<<<<<<<<<<
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 */
    __Pyx_TraceLine(4175,0,__PYX_ERR(0, 4175, __pyx_L1_error))
    __pyx_t_8.data = __pyx_v_I.data;
    __pyx_t_8.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_8, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_8,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4175, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_ii;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_8.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_8.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_8.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4176
 *             ii = cell.index
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index             # <<<<<<<<<<<<<<
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5
 */
    __Pyx_TraceLine(4176,0,__PYX_ERR(0, 4176, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face1->index;
    __pyx_t_16 = (__pyx_v_ii * 2);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4177
 *             I[ii*2 : ii*2 + 2] = ii
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index             # <<<<<<<<<<<<<<
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 */
    __Pyx_TraceLine(4177,0,__PYX_ERR(0, 4177, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_face2->index;
    __pyx_t_16 = ((__pyx_v_ii * 2) + 1);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_J.shape[0];
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":4178
 *             J[ii*2    ] = face1.index
 *             J[ii*2 + 1] = face2.index
 *             V[ii*2 : ii*2 + 2] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rfy = self._deflate_faces_z()
 */
    __Pyx_TraceLine(4178,0,__PYX_ERR(0, 4178, __pyx_L1_error))
    __pyx_t_9.data = __pyx_v_V.data;
    __pyx_t_9.memview = __pyx_v_V.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_14 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_V.shape[0], __pyx_v_V.strides[0], __pyx_v_V.suboffsets[0],
    0,
    0,
    &__pyx_t_14,
    (__pyx_v_ii * 2),
    ((__pyx_v_ii * 2) + 2),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 4178, __pyx_L1_error)
}

{
        __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.5;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_9.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_9.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_9.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4171
 *         V = np.empty(self.n_cells*2, dtype=np.float64)
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             face1 = cell.faces[4]
 *             face2 = cell.faces[5]
 */
    __Pyx_TraceLine(4171,0,__PYX_ERR(0, 4171, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":4180
 *             V[ii*2 : ii*2 + 2] = 0.5
 * 
 *         Rfy = self._deflate_faces_z()             # <<<<<<<<<<<<<<
 *         self._average_face_z_to_cell = sp.csr_matrix((V, (I, J)))*Rfy
 *         return self._average_face_z_to_cell
 */
  __Pyx_TraceLine(4180,0,__PYX_ERR(0, 4180, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rfy = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4181
 * 
 *         Rfy = self._deflate_faces_z()
 *         self._average_face_z_to_cell = sp.csr_matrix((V, (I, J)))*Rfy             # <<<<<<<<<<<<<<
 *         return self._average_face_z_to_cell
 * 
 */
  __Pyx_TraceLine(4181,0,__PYX_ERR(0, 4181, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_17);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_17);
  __pyx_t_7 = 0;
  __pyx_t_17 = 0;
  __pyx_t_17 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_17)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_17);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_17, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_4, __pyx_v_Rfy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_6);
  __Pyx_GOTREF(__pyx_v_self->_average_face_z_to_cell);
  __Pyx_DECREF(__pyx_v_self->_average_face_z_to_cell);
  __pyx_v_self->_average_face_z_to_cell = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4182
 *         Rfy = self._deflate_faces_z()
 *         self._average_face_z_to_cell = sp.csr_matrix((V, (I, J)))*Rfy
 *         return self._average_face_z_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4182,0,__PYX_ERR(0, 4182, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_face_z_to_cell);
  __pyx_r = __pyx_v_self->_average_face_z_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4127
 *     @property
 *     @cython.boundscheck(False)
 *     def average_face_z_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from z-faces to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_face_z_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rfy);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4185
 * 
 *     @property
 *     def average_face_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from faces to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4185, 0, __PYX_ERR(0, 4185, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4216
 *             phi_c = Afc @ phi_f
 *         """
 *         if self._average_face_to_cell is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 */
  __Pyx_TraceLine(4216,0,__PYX_ERR(0, 4216, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_face_to_cell == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4217
 *         """
 *         if self._average_face_to_cell is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]
 */
    __Pyx_TraceLine(4217,0,__PYX_ERR(0, 4217, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_face_x_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_aveFy2CC); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_v_stacks = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4218
 *         if self._average_face_to_cell is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell = 1./self._dim*sp.hstack(stacks).tocsr()
 */
    __Pyx_TraceLine(4218,0,__PYX_ERR(0, 4218, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4219
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]             # <<<<<<<<<<<<<<
 *             self._average_face_to_cell = 1./self._dim*sp.hstack(stacks).tocsr()
 *         return self._average_face_to_cell
 */
      __Pyx_TraceLine(4219,0,__PYX_ERR(0, 4219, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_face_z_to_cell); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4219, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4219, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4219, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":4218
 *         if self._average_face_to_cell is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell = 1./self._dim*sp.hstack(stacks).tocsr()
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4220
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell = 1./self._dim*sp.hstack(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_face_to_cell
 * 
 */
    __Pyx_TraceLine(4220,0,__PYX_ERR(0, 4220, __pyx_L1_error))
    if (unlikely(__pyx_v_self->_dim == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 4220, __pyx_L1_error)
    }
    __pyx_t_5 = PyFloat_FromDouble((1. / ((double)__pyx_v_self->_dim))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_hstack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_stacks);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Multiply(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_self->_average_face_to_cell);
    __Pyx_DECREF(__pyx_v_self->_average_face_to_cell);
    __pyx_v_self->_average_face_to_cell = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4216
 *             phi_c = Afc @ phi_f
 *         """
 *         if self._average_face_to_cell is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4221
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell = 1./self._dim*sp.hstack(stacks).tocsr()
 *         return self._average_face_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4221,0,__PYX_ERR(0, 4221, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_face_to_cell);
  __pyx_r = __pyx_v_self->_average_face_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4185
 * 
 *     @property
 *     def average_face_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from faces to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_face_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4224
 * 
 *     @property
 *     def average_face_to_cell_vector(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from faces to cell centers (vector quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4224, 0, __PYX_ERR(0, 4224, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4267
 *         the cell's center.
 *         """
 *         if self._average_face_to_cell_vector is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 */
  __Pyx_TraceLine(4267,0,__PYX_ERR(0, 4267, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_face_to_cell_vector == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4268
 *         """
 *         if self._average_face_to_cell_vector is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]
 */
    __Pyx_TraceLine(4268,0,__PYX_ERR(0, 4268, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_face_x_to_cell); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_aveFy2CC); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_v_stacks = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4269
 *         if self._average_face_to_cell_vector is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell_vector = sp.block_diag(stacks).tocsr()
 */
    __Pyx_TraceLine(4269,0,__PYX_ERR(0, 4269, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4270
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]             # <<<<<<<<<<<<<<
 *             self._average_face_to_cell_vector = sp.block_diag(stacks).tocsr()
 *         return self._average_face_to_cell_vector
 */
      __Pyx_TraceLine(4270,0,__PYX_ERR(0, 4270, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_face_z_to_cell); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_5);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":4269
 *         if self._average_face_to_cell_vector is None:
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell_vector = sp.block_diag(stacks).tocsr()
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4271
 *             if self._dim == 3:
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell_vector = sp.block_diag(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_face_to_cell_vector
 * 
 */
    __Pyx_TraceLine(4271,0,__PYX_ERR(0, 4271, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_stacks);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4271, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->_average_face_to_cell_vector);
    __Pyx_DECREF(__pyx_v_self->_average_face_to_cell_vector);
    __pyx_v_self->_average_face_to_cell_vector = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4267
 *         the cell's center.
 *         """
 *         if self._average_face_to_cell_vector is None:             # <<<<<<<<<<<<<<
 *             stacks = [self.average_face_x_to_cell, self.aveFy2CC]
 *             if self._dim == 3:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4272
 *                 stacks += [self.average_face_z_to_cell]
 *             self._average_face_to_cell_vector = sp.block_diag(stacks).tocsr()
 *         return self._average_face_to_cell_vector             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4272,0,__PYX_ERR(0, 4272, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_face_to_cell_vector);
  __pyx_r = __pyx_v_self->_average_face_to_cell_vector;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4224
 * 
 *     @property
 *     def average_face_to_cell_vector(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from faces to cell centers (vector quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_face_to_cell_vector.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4276
 *     @property
 *     @cython.boundscheck(False)
 *     def average_node_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to cell centers (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  __pyx_t_5numpy_int64_t __pyx_v_n_ppc;
  double __pyx_v_scale;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_10;
  std::vector<Cell *>  *__pyx_t_11;
  Cell *__pyx_t_12;
  PY_LONG_LONG __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  __pyx_t_5numpy_int64_t __pyx_t_17;
  int_t __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4276, 0, __PYX_ERR(0, 4276, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4311
 *         cdef np.int64_t ii, id, n_ppc
 *         cdef double scale
 *         if self._average_node_to_cell is None:             # <<<<<<<<<<<<<<
 *             n_ppc = 1<<self._dim
 *             scale = 1.0/n_ppc
 */
  __Pyx_TraceLine(4311,0,__PYX_ERR(0, 4311, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_cell == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4312
 *         cdef double scale
 *         if self._average_node_to_cell is None:
 *             n_ppc = 1<<self._dim             # <<<<<<<<<<<<<<
 *             scale = 1.0/n_ppc
 *             I = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 */
    __Pyx_TraceLine(4312,0,__PYX_ERR(0, 4312, __pyx_L1_error))
    __pyx_v_n_ppc = (1 << __pyx_v_self->_dim);

    /* "discretize/_extensions/tree_ext.pyx":4313
 *         if self._average_node_to_cell is None:
 *             n_ppc = 1<<self._dim
 *             scale = 1.0/n_ppc             # <<<<<<<<<<<<<<
 *             I = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 *             J = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 */
    __Pyx_TraceLine(4313,0,__PYX_ERR(0, 4313, __pyx_L1_error))
    if (unlikely(__pyx_v_n_ppc == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 4313, __pyx_L1_error)
    }
    __pyx_v_scale = (1.0 / ((double)__pyx_v_n_ppc));

    /* "discretize/_extensions/tree_ext.pyx":4314
 *             n_ppc = 1<<self._dim
 *             scale = 1.0/n_ppc
 *             I = np.empty(self.n_cells*n_ppc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             J = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 *             V = np.empty(self.n_cells*n_ppc, dtype=np.float64)
 */
    __Pyx_TraceLine(4314,0,__PYX_ERR(0, 4314, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_ppc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4314, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_I = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4315
 *             scale = 1.0/n_ppc
 *             I = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 *             J = np.empty(self.n_cells*n_ppc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             V = np.empty(self.n_cells*n_ppc, dtype=np.float64)
 * 
 */
    __Pyx_TraceLine(4315,0,__PYX_ERR(0, 4315, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_ppc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4315, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_J = __pyx_t_8;
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4316
 *             I = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 *             J = np.empty(self.n_cells*n_ppc, dtype=np.int64)
 *             V = np.empty(self.n_cells*n_ppc, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             for cell in self.tree.cells:
 */
    __Pyx_TraceLine(4316,0,__PYX_ERR(0, 4316, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_npy_int64(__pyx_v_n_ppc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4316, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_V = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":4318
 *             V = np.empty(self.n_cells*n_ppc, dtype=np.float64)
 * 
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 ii = cell.index
 *                 for id in range(n_ppc):
 */
    __Pyx_TraceLine(4318,0,__PYX_ERR(0, 4318, __pyx_L1_error))
    __pyx_t_11 = &__pyx_v_self->tree->cells;
    __pyx_t_10 = __pyx_t_11->begin();
    for (;;) {
      if (!(__pyx_t_10 != __pyx_t_11->end())) break;
      __pyx_t_12 = *__pyx_t_10;
      ++__pyx_t_10;
      __pyx_v_cell = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":4319
 * 
 *             for cell in self.tree.cells:
 *                 ii = cell.index             # <<<<<<<<<<<<<<
 *                 for id in range(n_ppc):
 *                     I[ii*n_ppc + id] = ii
 */
      __Pyx_TraceLine(4319,0,__PYX_ERR(0, 4319, __pyx_L1_error))
      __pyx_t_13 = __pyx_v_cell->index;
      __pyx_v_ii = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":4320
 *             for cell in self.tree.cells:
 *                 ii = cell.index
 *                 for id in range(n_ppc):             # <<<<<<<<<<<<<<
 *                     I[ii*n_ppc + id] = ii
 *                     J[ii*n_ppc + id] = cell.points[id].index
 */
      __Pyx_TraceLine(4320,0,__PYX_ERR(0, 4320, __pyx_L1_error))
      __pyx_t_14 = __pyx_v_n_ppc;
      __pyx_t_15 = __pyx_t_14;
      for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
        __pyx_v_id = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4321
 *                 ii = cell.index
 *                 for id in range(n_ppc):
 *                     I[ii*n_ppc + id] = ii             # <<<<<<<<<<<<<<
 *                     J[ii*n_ppc + id] = cell.points[id].index
 *                     V[ii*n_ppc + id] = scale
 */
        __Pyx_TraceLine(4321,0,__PYX_ERR(0, 4321, __pyx_L1_error))
        __pyx_t_17 = ((__pyx_v_ii * __pyx_v_n_ppc) + __pyx_v_id);
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_I.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_17 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

        /* "discretize/_extensions/tree_ext.pyx":4322
 *                 for id in range(n_ppc):
 *                     I[ii*n_ppc + id] = ii
 *                     J[ii*n_ppc + id] = cell.points[id].index             # <<<<<<<<<<<<<<
 *                     V[ii*n_ppc + id] = scale
 * 
 */
        __Pyx_TraceLine(4322,0,__PYX_ERR(0, 4322, __pyx_L1_error))
        __pyx_t_18 = (__pyx_v_cell->points[__pyx_v_id])->index;
        __pyx_t_17 = ((__pyx_v_ii * __pyx_v_n_ppc) + __pyx_v_id);
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_J.shape[0];
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_17 * __pyx_v_J.strides[0]) )) = __pyx_t_18;

        /* "discretize/_extensions/tree_ext.pyx":4323
 *                     I[ii*n_ppc + id] = ii
 *                     J[ii*n_ppc + id] = cell.points[id].index
 *                     V[ii*n_ppc + id] = scale             # <<<<<<<<<<<<<<
 * 
 *             Rn = self._deflate_nodes()
 */
        __Pyx_TraceLine(4323,0,__PYX_ERR(0, 4323, __pyx_L1_error))
        __pyx_t_17 = ((__pyx_v_ii * __pyx_v_n_ppc) + __pyx_v_id);
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_V.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_17 * __pyx_v_V.strides[0]) )) = __pyx_v_scale;
      }

      /* "discretize/_extensions/tree_ext.pyx":4318
 *             V = np.empty(self.n_cells*n_ppc, dtype=np.float64)
 * 
 *             for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 ii = cell.index
 *                 for id in range(n_ppc):
 */
      __Pyx_TraceLine(4318,0,__PYX_ERR(0, 4318, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":4325
 *                     V[ii*n_ppc + id] = scale
 * 
 *             Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *             self._average_node_to_cell = sp.csr_matrix((V, (I, J)), shape=(self.n_cells, self.n_total_nodes))*Rn
 *         return self._average_node_to_cell
 */
    __Pyx_TraceLine(4325,0,__PYX_ERR(0, 4325, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4325, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_7 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4325, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_Rn = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4326
 * 
 *             Rn = self._deflate_nodes()
 *             self._average_node_to_cell = sp.csr_matrix((V, (I, J)), shape=(self.n_cells, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_cell
 * 
 */
    __Pyx_TraceLine(4326,0,__PYX_ERR(0, 4326, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
    __pyx_t_5 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __pyx_t_7 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_5);
    __pyx_t_7 = 0;
    __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_shape, __pyx_t_19) < 0) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Multiply(__pyx_t_19, __pyx_v_Rn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_v_self->_average_node_to_cell);
    __Pyx_DECREF(__pyx_v_self->_average_node_to_cell);
    __pyx_v_self->_average_node_to_cell = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4311
 *         cdef np.int64_t ii, id, n_ppc
 *         cdef double scale
 *         if self._average_node_to_cell is None:             # <<<<<<<<<<<<<<
 *             n_ppc = 1<<self._dim
 *             scale = 1.0/n_ppc
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4327
 *             Rn = self._deflate_nodes()
 *             self._average_node_to_cell = sp.csr_matrix((V, (I, J)), shape=(self.n_cells, self.n_total_nodes))*Rn
 *         return self._average_node_to_cell             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4327,0,__PYX_ERR(0, 4327, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_cell);
  __pyx_r = __pyx_v_self->_average_node_to_cell;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4276
 *     @property
 *     @cython.boundscheck(False)
 *     def average_node_to_cell(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to cell centers (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_cell.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4330
 * 
 *     @property
 *     def average_node_to_edge_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to x edges (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Edge *>  __pyx_v_it;
  Edge *__pyx_v_edge;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4330, 0, __PYX_ERR(0, 4330, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4343
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._average_node_to_edge_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_x
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4343,0,__PYX_ERR(0, 4343, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_edge_x != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4344
 *         """
 *         if self._average_node_to_edge_x is not None:
 *             return self._average_node_to_edge_x             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4344,0,__PYX_ERR(0, 4344, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_x);
    __pyx_r = __pyx_v_self->_average_node_to_edge_x;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4343
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._average_node_to_edge_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_x
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4348
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_x*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_edges_x*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_x*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4348,0,__PYX_ERR(0, 4348, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4348, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4349
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_x*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_x*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_edges_x*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4349,0,__PYX_ERR(0, 4349, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4349, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4350
 *         I = np.empty(self.n_edges_x*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_x*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_x*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.edges_x:
 */
  __Pyx_TraceLine(4350,0,__PYX_ERR(0, 4350, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4352
 *         V = np.empty(self.n_edges_x*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
  __Pyx_TraceLine(4352,0,__PYX_ERR(0, 4352, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->edges_x;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4353
 * 
 *         for it in self.tree.edges_x:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4353,0,__PYX_ERR(0, 4353, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4354
 *         for it in self.tree.edges_x:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    __Pyx_TraceLine(4354,0,__PYX_ERR(0, 4354, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4355
 *             edge = it.second
 *             if edge.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             for id in range(2):
 */
      __Pyx_TraceLine(4355,0,__PYX_ERR(0, 4355, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":4354
 *         for it in self.tree.edges_x:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4356
 *             if edge.hanging:
 *                 continue
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 */
    __Pyx_TraceLine(4356,0,__PYX_ERR(0, 4356, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4357
 *                 continue
 *             ii = edge.index
 *             for id in range(2):             # <<<<<<<<<<<<<<
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 */
    __Pyx_TraceLine(4357,0,__PYX_ERR(0, 4357, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 2; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4358
 *             ii = edge.index
 *             for id in range(2):
 *                 I[ii*2 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5
 */
      __Pyx_TraceLine(4358,0,__PYX_ERR(0, 4358, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4358, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4359
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*2 + id] = 0.5
 * 
 */
      __Pyx_TraceLine(4359,0,__PYX_ERR(0, 4359, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_edge->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4359, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4360
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4360,0,__PYX_ERR(0, 4360, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4360, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.5;
    }

    /* "discretize/_extensions/tree_ext.pyx":4352
 *         V = np.empty(self.n_edges_x*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
    __Pyx_TraceLine(4352,0,__PYX_ERR(0, 4352, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4362
 *                 V[ii*2 + id] = 0.5
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_x = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_x, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_x
 */
  __Pyx_TraceLine(4362,0,__PYX_ERR(0, 4362, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4363
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_x = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_x, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_edge_x
 * 
 */
  __Pyx_TraceLine(4363,0,__PYX_ERR(0, 4363, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_x);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_x);
  __pyx_v_self->_average_node_to_edge_x = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4364
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_x = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_x, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4364,0,__PYX_ERR(0, 4364, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_x);
  __pyx_r = __pyx_v_self->_average_node_to_edge_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4330
 * 
 *     @property
 *     def average_node_to_edge_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to x edges (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_edge_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4367
 * 
 *     @property
 *     def average_node_to_edge_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to y edges (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Edge *>  __pyx_v_it;
  Edge *__pyx_v_edge;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4367, 0, __PYX_ERR(0, 4367, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4380
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._average_node_to_edge_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_y
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4380,0,__PYX_ERR(0, 4380, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_edge_y != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4381
 *         """
 *         if self._average_node_to_edge_y is not None:
 *             return self._average_node_to_edge_y             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4381,0,__PYX_ERR(0, 4381, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_y);
    __pyx_r = __pyx_v_self->_average_node_to_edge_y;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4380
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._average_node_to_edge_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_y
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4385
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_y*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_edges_y*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_y*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4385,0,__PYX_ERR(0, 4385, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4385, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4386
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_y*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_y*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_edges_y*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4386,0,__PYX_ERR(0, 4386, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4386, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4387
 *         I = np.empty(self.n_edges_y*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_y*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_y*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.edges_y:
 */
  __Pyx_TraceLine(4387,0,__PYX_ERR(0, 4387, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4387, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4389
 *         V = np.empty(self.n_edges_y*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
  __Pyx_TraceLine(4389,0,__PYX_ERR(0, 4389, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->edges_y;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4390
 * 
 *         for it in self.tree.edges_y:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4390,0,__PYX_ERR(0, 4390, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4391
 *         for it in self.tree.edges_y:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    __Pyx_TraceLine(4391,0,__PYX_ERR(0, 4391, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4392
 *             edge = it.second
 *             if edge.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             for id in range(2):
 */
      __Pyx_TraceLine(4392,0,__PYX_ERR(0, 4392, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":4391
 *         for it in self.tree.edges_y:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4393
 *             if edge.hanging:
 *                 continue
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 */
    __Pyx_TraceLine(4393,0,__PYX_ERR(0, 4393, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4394
 *                 continue
 *             ii = edge.index
 *             for id in range(2):             # <<<<<<<<<<<<<<
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 */
    __Pyx_TraceLine(4394,0,__PYX_ERR(0, 4394, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 2; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4395
 *             ii = edge.index
 *             for id in range(2):
 *                 I[ii*2 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5
 */
      __Pyx_TraceLine(4395,0,__PYX_ERR(0, 4395, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4395, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4396
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*2 + id] = 0.5
 * 
 */
      __Pyx_TraceLine(4396,0,__PYX_ERR(0, 4396, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_edge->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4396, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4397
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4397,0,__PYX_ERR(0, 4397, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4397, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.5;
    }

    /* "discretize/_extensions/tree_ext.pyx":4389
 *         V = np.empty(self.n_edges_y*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
    __Pyx_TraceLine(4389,0,__PYX_ERR(0, 4389, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4399
 *                 V[ii*2 + id] = 0.5
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_y = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_y, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_y
 */
  __Pyx_TraceLine(4399,0,__PYX_ERR(0, 4399, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4400
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_y = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_y, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_edge_y
 * 
 */
  __Pyx_TraceLine(4400,0,__PYX_ERR(0, 4400, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_y);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_y);
  __pyx_v_self->_average_node_to_edge_y = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4401
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_y = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_y, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4401,0,__PYX_ERR(0, 4401, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_y);
  __pyx_r = __pyx_v_self->_average_node_to_edge_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4367
 * 
 *     @property
 *     def average_node_to_edge_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to y edges (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_edge_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4404
 * 
 *     @property
 *     def average_node_to_edge_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to z edges (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Edge *>  __pyx_v_it;
  Edge *__pyx_v_edge;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_10;
  edge_map_t *__pyx_t_11;
  std::pair<int_t,Edge *>  __pyx_t_12;
  Edge *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4404, 0, __PYX_ERR(0, 4404, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4417
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z-edges in 2D')
 *         if self._average_node_to_edge_z is not None:
 */
  __Pyx_TraceLine(4417,0,__PYX_ERR(0, 4417, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "discretize/_extensions/tree_ext.pyx":4418
 *         """
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z-edges in 2D')             # <<<<<<<<<<<<<<
 *         if self._average_node_to_edge_z is not None:
 *             return self._average_node_to_edge_z
 */
    __Pyx_TraceLine(4418,0,__PYX_ERR(0, 4418, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4418, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 4418, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":4417
 *             The scalar averaging operator from nodes to edges
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z-edges in 2D')
 *         if self._average_node_to_edge_z is not None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4419
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z-edges in 2D')
 *         if self._average_node_to_edge_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_z
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4419,0,__PYX_ERR(0, 4419, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_edge_z != Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":4420
 *             raise Exception('TreeMesh has no z-edges in 2D')
 *         if self._average_node_to_edge_z is not None:
 *             return self._average_node_to_edge_z             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4420,0,__PYX_ERR(0, 4420, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_z);
    __pyx_r = __pyx_v_self->_average_node_to_edge_z;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4419
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z-edges in 2D')
 *         if self._average_node_to_edge_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge_z
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4424
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_z*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_edges_z*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_z*2, dtype=np.float64)
 */
  __Pyx_TraceLine(4424,0,__PYX_ERR(0, 4424, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_int_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4424, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4425
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_edges_z*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_z*2, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_edges_z*2, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4425,0,__PYX_ERR(0, 4425, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_7, __pyx_int_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4425, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4426
 *         I = np.empty(self.n_edges_z*2, dtype=np.int64)
 *         J = np.empty(self.n_edges_z*2, dtype=np.int64)
 *         V = np.empty(self.n_edges_z*2, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.edges_z:
 */
  __Pyx_TraceLine(4426,0,__PYX_ERR(0, 4426, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4426, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4428
 *         V = np.empty(self.n_edges_z*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
  __Pyx_TraceLine(4428,0,__PYX_ERR(0, 4428, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->edges_z;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4429
 * 
 *         for it in self.tree.edges_z:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             if edge.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4429,0,__PYX_ERR(0, 4429, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4430
 *         for it in self.tree.edges_z:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    __Pyx_TraceLine(4430,0,__PYX_ERR(0, 4430, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_edge->hanging != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":4431
 *             edge = it.second
 *             if edge.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = edge.index
 *             for id in range(2):
 */
      __Pyx_TraceLine(4431,0,__PYX_ERR(0, 4431, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":4430
 *         for it in self.tree.edges_z:
 *             edge = it.second
 *             if edge.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = edge.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4432
 *             if edge.hanging:
 *                 continue
 *             ii = edge.index             # <<<<<<<<<<<<<<
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 */
    __Pyx_TraceLine(4432,0,__PYX_ERR(0, 4432, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_edge->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4433
 *                 continue
 *             ii = edge.index
 *             for id in range(2):             # <<<<<<<<<<<<<<
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 */
    __Pyx_TraceLine(4433,0,__PYX_ERR(0, 4433, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 2; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4434
 *             ii = edge.index
 *             for id in range(2):
 *                 I[ii*2 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5
 */
      __Pyx_TraceLine(4434,0,__PYX_ERR(0, 4434, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4434, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4435
 *             for id in range(2):
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*2 + id] = 0.5
 * 
 */
      __Pyx_TraceLine(4435,0,__PYX_ERR(0, 4435, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_edge->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4435, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4436
 *                 I[ii*2 + id] = ii
 *                 J[ii*2 + id] = edge.points[id].index
 *                 V[ii*2 + id] = 0.5             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4436,0,__PYX_ERR(0, 4436, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 2) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4436, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.5;
    }

    /* "discretize/_extensions/tree_ext.pyx":4428
 *         V = np.empty(self.n_edges_z*2, dtype=np.float64)
 * 
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             if edge.hanging:
 */
    __Pyx_TraceLine(4428,0,__PYX_ERR(0, 4428, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4438
 *                 V[ii*2 + id] = 0.5
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge_z = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_z, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_z
 */
  __Pyx_TraceLine(4438,0,__PYX_ERR(0, 4438, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4438, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4438, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4439
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_z = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_z, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_edge_z
 * 
 */
  __Pyx_TraceLine(4439,0,__PYX_ERR(0, 4439, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
  __pyx_t_6 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge_z);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge_z);
  __pyx_v_self->_average_node_to_edge_z = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4440
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_edge_z = sp.csr_matrix((V, (I, J)), shape=(self.n_edges_z, self.n_total_nodes))*Rn
 *         return self._average_node_to_edge_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4440,0,__PYX_ERR(0, 4440, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_edge_z);
  __pyx_r = __pyx_v_self->_average_node_to_edge_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4404
 * 
 *     @property
 *     def average_node_to_edge_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to z edges (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_edge_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4443
 * 
 *     @property
 *     def average_node_to_edge(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to edges (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4443, 0, __PYX_ERR(0, 4443, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4475
 *             phi_e = Ane @ phi_n
 *         """
 *         if self._average_node_to_edge is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge
 * 
 */
  __Pyx_TraceLine(4475,0,__PYX_ERR(0, 4475, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_edge != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4476
 *         """
 *         if self._average_node_to_edge is not None:
 *             return self._average_node_to_edge             # <<<<<<<<<<<<<<
 * 
 *         stacks = [self.average_node_to_edge_x, self.average_node_to_edge_y]
 */
    __Pyx_TraceLine(4476,0,__PYX_ERR(0, 4476, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_edge);
    __pyx_r = __pyx_v_self->_average_node_to_edge;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4475
 *             phi_e = Ane @ phi_n
 *         """
 *         if self._average_node_to_edge is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_edge
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4478
 *             return self._average_node_to_edge
 * 
 *         stacks = [self.average_node_to_edge_x, self.average_node_to_edge_y]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_edge_z]
 */
  __Pyx_TraceLine(4478,0,__PYX_ERR(0, 4478, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_edge_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_edge_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_v_stacks = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4479
 * 
 *         stacks = [self.average_node_to_edge_x, self.average_node_to_edge_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks += [self.average_node_to_edge_z]
 *         self._average_node_to_edge = sp.vstack(stacks).tocsr()
 */
  __Pyx_TraceLine(4479,0,__PYX_ERR(0, 4479, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4480
 *         stacks = [self.average_node_to_edge_x, self.average_node_to_edge_y]
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_edge_z]             # <<<<<<<<<<<<<<
 *         self._average_node_to_edge = sp.vstack(stacks).tocsr()
 *         return self._average_node_to_edge
 */
    __Pyx_TraceLine(4480,0,__PYX_ERR(0, 4480, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_edge_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4480, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4480, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4480, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4479
 * 
 *         stacks = [self.average_node_to_edge_x, self.average_node_to_edge_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks += [self.average_node_to_edge_z]
 *         self._average_node_to_edge = sp.vstack(stacks).tocsr()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4481
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_edge_z]
 *         self._average_node_to_edge = sp.vstack(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_node_to_edge
 * 
 */
  __Pyx_TraceLine(4481,0,__PYX_ERR(0, 4481, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_vstack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_stacks);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_edge);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_edge);
  __pyx_v_self->_average_node_to_edge = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4482
 *             stacks += [self.average_node_to_edge_z]
 *         self._average_node_to_edge = sp.vstack(stacks).tocsr()
 *         return self._average_node_to_edge             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4482,0,__PYX_ERR(0, 4482, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_edge);
  __pyx_r = __pyx_v_self->_average_node_to_edge;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4443
 * 
 *     @property
 *     def average_node_to_edge(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to edges (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_edge.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4485
 * 
 *     @property
 *     def average_node_to_face_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to x faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Face *>  __pyx_v_it;
  Face *__pyx_v_face;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4485, 0, __PYX_ERR(0, 4485, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4498
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_node_to_edge_y
 *         if self._average_node_to_face_x is not None:
 */
  __Pyx_TraceLine(4498,0,__PYX_ERR(0, 4498, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":4499
 *         """
 *         if self._dim == 2:
 *             return self.average_node_to_edge_y             # <<<<<<<<<<<<<<
 *         if self._average_node_to_face_x is not None:
 *             return self._average_node_to_face_x
 */
    __Pyx_TraceLine(4499,0,__PYX_ERR(0, 4499, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_edge_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4498
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_node_to_edge_y
 *         if self._average_node_to_face_x is not None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4500
 *         if self._dim == 2:
 *             return self.average_node_to_edge_y
 *         if self._average_node_to_face_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_x
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4500,0,__PYX_ERR(0, 4500, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_face_x != Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":4501
 *             return self.average_node_to_edge_y
 *         if self._average_node_to_face_x is not None:
 *             return self._average_node_to_face_x             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4501,0,__PYX_ERR(0, 4501, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_face_x);
    __pyx_r = __pyx_v_self->_average_node_to_face_x;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4500
 *         if self._dim == 2:
 *             return self.average_node_to_edge_y
 *         if self._average_node_to_face_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_x
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4505
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_faces_x*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_faces_x*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_x*4, dtype=np.float64)
 */
  __Pyx_TraceLine(4505,0,__PYX_ERR(0, 4505, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4506
 *         cdef np.int64_t ii, id
 *         I = np.empty(self.n_faces_x*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_x*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_faces_x*4, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4506,0,__PYX_ERR(0, 4506, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_7, __pyx_int_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4506, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4507
 *         I = np.empty(self.n_faces_x*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_x*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_x*4, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_x:
 */
  __Pyx_TraceLine(4507,0,__PYX_ERR(0, 4507, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4507, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4509
 *         V = np.empty(self.n_faces_x*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(4509,0,__PYX_ERR(0, 4509, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->faces_x;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4510
 * 
 *         for it in self.tree.faces_x:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4510,0,__PYX_ERR(0, 4510, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4511
 *         for it in self.tree.faces_x:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    __Pyx_TraceLine(4511,0,__PYX_ERR(0, 4511, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":4512
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             for id in range(4):
 */
      __Pyx_TraceLine(4512,0,__PYX_ERR(0, 4512, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":4511
 *         for it in self.tree.faces_x:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4513
 *             if face.hanging:
 *                 continue
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 */
    __Pyx_TraceLine(4513,0,__PYX_ERR(0, 4513, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4514
 *                 continue
 *             ii = face.index
 *             for id in range(4):             # <<<<<<<<<<<<<<
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 */
    __Pyx_TraceLine(4514,0,__PYX_ERR(0, 4514, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4515
 *             ii = face.index
 *             for id in range(4):
 *                 I[ii*4 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25
 */
      __Pyx_TraceLine(4515,0,__PYX_ERR(0, 4515, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4515, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4516
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*4 + id] = 0.25
 * 
 */
      __Pyx_TraceLine(4516,0,__PYX_ERR(0, 4516, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_face->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4516, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4517
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4517,0,__PYX_ERR(0, 4517, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4517, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.25;
    }

    /* "discretize/_extensions/tree_ext.pyx":4509
 *         V = np.empty(self.n_faces_x*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_x:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(4509,0,__PYX_ERR(0, 4509, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4519
 *                 V[ii*4 + id] = 0.25
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_x
 */
  __Pyx_TraceLine(4519,0,__PYX_ERR(0, 4519, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4519, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4519, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4520
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_face_x
 * 
 */
  __Pyx_TraceLine(4520,0,__PYX_ERR(0, 4520, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
  __pyx_t_6 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_x);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_x);
  __pyx_v_self->_average_node_to_face_x = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4521
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4521,0,__PYX_ERR(0, 4521, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_face_x);
  __pyx_r = __pyx_v_self->_average_node_to_face_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4485
 * 
 *     @property
 *     def average_node_to_face_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to x faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_face_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4524
 * 
 *     @property
 *     def average_node_to_face_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to y faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Face *>  __pyx_v_it;
  Face *__pyx_v_face;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4524, 0, __PYX_ERR(0, 4524, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4537
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_node_to_edge_x
 *         if self._average_node_to_face_y is not None:
 */
  __Pyx_TraceLine(4537,0,__PYX_ERR(0, 4537, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (__pyx_t_1) {

    /* "discretize/_extensions/tree_ext.pyx":4538
 *         """
 *         if self._dim == 2:
 *             return self.average_node_to_edge_x             # <<<<<<<<<<<<<<
 *         if self._average_node_to_face_y is not None:
 *             return self._average_node_to_face_y
 */
    __Pyx_TraceLine(4538,0,__PYX_ERR(0, 4538, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_edge_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4537
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             return self.average_node_to_edge_x
 *         if self._average_node_to_face_y is not None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4539
 *         if self._dim == 2:
 *             return self.average_node_to_edge_x
 *         if self._average_node_to_face_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_y
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4539,0,__PYX_ERR(0, 4539, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_face_y != Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":4540
 *             return self.average_node_to_edge_x
 *         if self._average_node_to_face_y is not None:
 *             return self._average_node_to_face_y             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4540,0,__PYX_ERR(0, 4540, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_face_y);
    __pyx_r = __pyx_v_self->_average_node_to_face_y;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4539
 *         if self._dim == 2:
 *             return self.average_node_to_edge_x
 *         if self._average_node_to_face_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_y
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4545
 *         cdef np.int64_t ii, id
 * 
 *         I = np.empty(self.n_faces_y*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_faces_y*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_y*4, dtype=np.float64)
 */
  __Pyx_TraceLine(4545,0,__PYX_ERR(0, 4545, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4545, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4546
 * 
 *         I = np.empty(self.n_faces_y*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_y*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_faces_y*4, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4546,0,__PYX_ERR(0, 4546, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_7, __pyx_int_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4546, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4547
 *         I = np.empty(self.n_faces_y*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_y*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_y*4, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_y:
 */
  __Pyx_TraceLine(4547,0,__PYX_ERR(0, 4547, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4547, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4549
 *         V = np.empty(self.n_faces_y*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(4549,0,__PYX_ERR(0, 4549, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->faces_y;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4550
 * 
 *         for it in self.tree.faces_y:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4550,0,__PYX_ERR(0, 4550, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4551
 *         for it in self.tree.faces_y:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    __Pyx_TraceLine(4551,0,__PYX_ERR(0, 4551, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":4552
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             for id in range(4):
 */
      __Pyx_TraceLine(4552,0,__PYX_ERR(0, 4552, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":4551
 *         for it in self.tree.faces_y:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4553
 *             if face.hanging:
 *                 continue
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 */
    __Pyx_TraceLine(4553,0,__PYX_ERR(0, 4553, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4554
 *                 continue
 *             ii = face.index
 *             for id in range(4):             # <<<<<<<<<<<<<<
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 */
    __Pyx_TraceLine(4554,0,__PYX_ERR(0, 4554, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4555
 *             ii = face.index
 *             for id in range(4):
 *                 I[ii*4 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25
 */
      __Pyx_TraceLine(4555,0,__PYX_ERR(0, 4555, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4555, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4556
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*4 + id] = 0.25
 * 
 */
      __Pyx_TraceLine(4556,0,__PYX_ERR(0, 4556, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_face->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4556, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4557
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4557,0,__PYX_ERR(0, 4557, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4557, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.25;
    }

    /* "discretize/_extensions/tree_ext.pyx":4549
 *         V = np.empty(self.n_faces_y*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_y:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(4549,0,__PYX_ERR(0, 4549, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4559
 *                 V[ii*4 + id] = 0.25
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_y = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_y, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_y
 */
  __Pyx_TraceLine(4559,0,__PYX_ERR(0, 4559, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4560
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_y = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_y, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_face_y
 * 
 */
  __Pyx_TraceLine(4560,0,__PYX_ERR(0, 4560, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
  __pyx_t_6 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_y);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_y);
  __pyx_v_self->_average_node_to_face_y = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4561
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_y = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_y, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4561,0,__PYX_ERR(0, 4561, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_face_y);
  __pyx_r = __pyx_v_self->_average_node_to_face_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4524
 * 
 *     @property
 *     def average_node_to_face_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to y faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_face_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4564
 * 
 *     @property
 *     def average_node_to_face_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to z faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_int64_t __pyx_v_ii;
  __pyx_t_5numpy_int64_t __pyx_v_id;
  std::pair<int_t,Face *>  __pyx_v_it;
  Face *__pyx_v_face;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Face *> ::iterator __pyx_t_10;
  face_map_t *__pyx_t_11;
  std::pair<int_t,Face *>  __pyx_t_12;
  Face *__pyx_t_13;
  int_t __pyx_t_14;
  __pyx_t_5numpy_int64_t __pyx_t_15;
  __pyx_t_5numpy_int64_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4564, 0, __PYX_ERR(0, 4564, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4577
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z faces in 2D')
 *         cdef np.int64_t[:] I, J
 */
  __Pyx_TraceLine(4577,0,__PYX_ERR(0, 4577, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->_dim == 2) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "discretize/_extensions/tree_ext.pyx":4578
 *         """
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z faces in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
    __Pyx_TraceLine(4578,0,__PYX_ERR(0, 4578, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4578, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 4578, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":4577
 *             The scalar averaging operator from nodes to faces
 *         """
 *         if self._dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z faces in 2D')
 *         cdef np.int64_t[:] I, J
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4582
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id,
 *         if self._average_node_to_face_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_z
 * 
 */
  __Pyx_TraceLine(4582,0,__PYX_ERR(0, 4582, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_face_z != Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":4583
 *         cdef np.int64_t ii, id,
 *         if self._average_node_to_face_z is not None:
 *             return self._average_node_to_face_z             # <<<<<<<<<<<<<<
 * 
 *         I = np.empty(self.n_faces_z*4, dtype=np.int64)
 */
    __Pyx_TraceLine(4583,0,__PYX_ERR(0, 4583, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_face_z);
    __pyx_r = __pyx_v_self->_average_node_to_face_z;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4582
 *         cdef np.float64_t[:] V
 *         cdef np.int64_t ii, id,
 *         if self._average_node_to_face_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face_z
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4585
 *             return self._average_node_to_face_z
 * 
 *         I = np.empty(self.n_faces_z*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J = np.empty(self.n_faces_z*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_z*4, dtype=np.float64)
 */
  __Pyx_TraceLine(4585,0,__PYX_ERR(0, 4585, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4585, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4586
 * 
 *         I = np.empty(self.n_faces_z*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_z*4, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         V = np.empty(self.n_faces_z*4, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(4586,0,__PYX_ERR(0, 4586, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_7, __pyx_int_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4586, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4587
 *         I = np.empty(self.n_faces_z*4, dtype=np.int64)
 *         J = np.empty(self.n_faces_z*4, dtype=np.int64)
 *         V = np.empty(self.n_faces_z*4, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         for it in self.tree.faces_z:
 */
  __Pyx_TraceLine(4587,0,__PYX_ERR(0, 4587, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_int_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4587, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4589
 *         V = np.empty(self.n_faces_z*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
  __Pyx_TraceLine(4589,0,__PYX_ERR(0, 4589, __pyx_L1_error))
  __pyx_t_11 = &__pyx_v_self->tree->faces_z;
  __pyx_t_10 = __pyx_t_11->begin();
  for (;;) {
    if (!(__pyx_t_10 != __pyx_t_11->end())) break;
    __pyx_t_12 = *__pyx_t_10;
    ++__pyx_t_10;
    __pyx_v_it = __pyx_t_12;

    /* "discretize/_extensions/tree_ext.pyx":4590
 * 
 *         for it in self.tree.faces_z:
 *             face = it.second             # <<<<<<<<<<<<<<
 *             if face.hanging:
 *                 continue
 */
    __Pyx_TraceLine(4590,0,__PYX_ERR(0, 4590, __pyx_L1_error))
    __pyx_t_13 = __pyx_v_it.second;
    __pyx_v_face = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4591
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    __Pyx_TraceLine(4591,0,__PYX_ERR(0, 4591, __pyx_L1_error))
    __pyx_t_3 = (__pyx_v_face->hanging != 0);
    if (__pyx_t_3) {

      /* "discretize/_extensions/tree_ext.pyx":4592
 *             face = it.second
 *             if face.hanging:
 *                 continue             # <<<<<<<<<<<<<<
 *             ii = face.index
 *             for id in range(4):
 */
      __Pyx_TraceLine(4592,0,__PYX_ERR(0, 4592, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":4591
 *         for it in self.tree.faces_z:
 *             face = it.second
 *             if face.hanging:             # <<<<<<<<<<<<<<
 *                 continue
 *             ii = face.index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4593
 *             if face.hanging:
 *                 continue
 *             ii = face.index             # <<<<<<<<<<<<<<
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 */
    __Pyx_TraceLine(4593,0,__PYX_ERR(0, 4593, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_face->index;
    __pyx_v_ii = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":4594
 *                 continue
 *             ii = face.index
 *             for id in range(4):             # <<<<<<<<<<<<<<
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 */
    __Pyx_TraceLine(4594,0,__PYX_ERR(0, 4594, __pyx_L1_error))
    for (__pyx_t_15 = 0; __pyx_t_15 < 4; __pyx_t_15+=1) {
      __pyx_v_id = __pyx_t_15;

      /* "discretize/_extensions/tree_ext.pyx":4595
 *             ii = face.index
 *             for id in range(4):
 *                 I[ii*4 + id] = ii             # <<<<<<<<<<<<<<
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25
 */
      __Pyx_TraceLine(4595,0,__PYX_ERR(0, 4595, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_I.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4595, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_16 * __pyx_v_I.strides[0]) )) = __pyx_v_ii;

      /* "discretize/_extensions/tree_ext.pyx":4596
 *             for id in range(4):
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index             # <<<<<<<<<<<<<<
 *                 V[ii*4 + id] = 0.25
 * 
 */
      __Pyx_TraceLine(4596,0,__PYX_ERR(0, 4596, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_face->points[__pyx_v_id])->index;
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4596, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_16 * __pyx_v_J.strides[0]) )) = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":4597
 *                 I[ii*4 + id] = ii
 *                 J[ii*4 + id] = face.points[id].index
 *                 V[ii*4 + id] = 0.25             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(4597,0,__PYX_ERR(0, 4597, __pyx_L1_error))
      __pyx_t_16 = ((__pyx_v_ii * 4) + __pyx_v_id);
      __pyx_t_17 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_V.shape[0])) __pyx_t_17 = 0;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 4597, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_16 * __pyx_v_V.strides[0]) )) = 0.25;
    }

    /* "discretize/_extensions/tree_ext.pyx":4589
 *         V = np.empty(self.n_faces_z*4, dtype=np.float64)
 * 
 *         for it in self.tree.faces_z:             # <<<<<<<<<<<<<<
 *             face = it.second
 *             if face.hanging:
 */
    __Pyx_TraceLine(4589,0,__PYX_ERR(0, 4589, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4599
 *                 V[ii*4 + id] = 0.25
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         self._average_node_to_face_z = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_z, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_z
 */
  __Pyx_TraceLine(4599,0,__PYX_ERR(0, 4599, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_Rn = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4600
 * 
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_z = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_z, self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 *         return self._average_node_to_face_z
 * 
 */
  __Pyx_TraceLine(4600,0,__PYX_ERR(0, 4600, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
  __pyx_t_6 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_18) < 0) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Multiply(__pyx_t_18, __pyx_v_Rn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face_z);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face_z);
  __pyx_v_self->_average_node_to_face_z = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4601
 *         Rn = self._deflate_nodes()
 *         self._average_node_to_face_z = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_z, self.n_total_nodes))*Rn
 *         return self._average_node_to_face_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4601,0,__PYX_ERR(0, 4601, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_face_z);
  __pyx_r = __pyx_v_self->_average_node_to_face_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4564
 * 
 *     @property
 *     def average_node_to_face_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from nodes to z faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_face_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4604
 * 
 *     @property
 *     def average_node_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4604, 0, __PYX_ERR(0, 4604, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4636
 *             phi_f = Anf @ phi_n
 *         """
 *         if self._average_node_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face
 * 
 */
  __Pyx_TraceLine(4636,0,__PYX_ERR(0, 4636, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_node_to_face != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4637
 *         """
 *         if self._average_node_to_face is not None:
 *             return self._average_node_to_face             # <<<<<<<<<<<<<<
 * 
 *         stacks = [self.average_node_to_face_x, self.average_node_to_face_y]
 */
    __Pyx_TraceLine(4637,0,__PYX_ERR(0, 4637, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_node_to_face);
    __pyx_r = __pyx_v_self->_average_node_to_face;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4636
 *             phi_f = Anf @ phi_n
 *         """
 *         if self._average_node_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_node_to_face
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4639
 *             return self._average_node_to_face
 * 
 *         stacks = [self.average_node_to_face_x, self.average_node_to_face_y]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_face_z]
 */
  __Pyx_TraceLine(4639,0,__PYX_ERR(0, 4639, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_face_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_face_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_v_stacks = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4640
 * 
 *         stacks = [self.average_node_to_face_x, self.average_node_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks += [self.average_node_to_face_z]
 *         self._average_node_to_face = sp.vstack(stacks).tocsr()
 */
  __Pyx_TraceLine(4640,0,__PYX_ERR(0, 4640, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4641
 *         stacks = [self.average_node_to_face_x, self.average_node_to_face_y]
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_face_z]             # <<<<<<<<<<<<<<
 *         self._average_node_to_face = sp.vstack(stacks).tocsr()
 *         return self._average_node_to_face
 */
    __Pyx_TraceLine(4641,0,__PYX_ERR(0, 4641, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_node_to_face_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_stacks, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_stacks, ((PyObject*)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4640
 * 
 *         stacks = [self.average_node_to_face_x, self.average_node_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks += [self.average_node_to_face_z]
 *         self._average_node_to_face = sp.vstack(stacks).tocsr()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4642
 *         if self._dim == 3:
 *             stacks += [self.average_node_to_face_z]
 *         self._average_node_to_face = sp.vstack(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_node_to_face
 * 
 */
  __Pyx_TraceLine(4642,0,__PYX_ERR(0, 4642, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_vstack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_stacks);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_node_to_face);
  __Pyx_DECREF(__pyx_v_self->_average_node_to_face);
  __pyx_v_self->_average_node_to_face = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4643
 *             stacks += [self.average_node_to_face_z]
 *         self._average_node_to_face = sp.vstack(stacks).tocsr()
 *         return self._average_node_to_face             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4643,0,__PYX_ERR(0, 4643, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_node_to_face);
  __pyx_r = __pyx_v_self->_average_node_to_face;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4604
 * 
 *     @property
 *     def average_node_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from nodes to faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_node_to_face.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4646
 * 
 *     @property
 *     def average_cell_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from cell centers to faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4646, 0, __PYX_ERR(0, 4646, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4685
 *             phi_f = Acf @ phi_c
 *         """
 *         if self._average_cell_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 */
  __Pyx_TraceLine(4685,0,__PYX_ERR(0, 4685, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_cell_to_face != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4686
 *         """
 *         if self._average_cell_to_face is not None:
 *             return self._average_cell_to_face             # <<<<<<<<<<<<<<
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:
 */
    __Pyx_TraceLine(4686,0,__PYX_ERR(0, 4686, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_cell_to_face);
    __pyx_r = __pyx_v_self->_average_cell_to_face;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4685
 *             phi_f = Acf @ phi_c
 *         """
 *         if self._average_cell_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4687
 *         if self._average_cell_to_face is not None:
 *             return self._average_cell_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             stacks.append(self.average_cell_to_face_z)
 */
  __Pyx_TraceLine(4687,0,__PYX_ERR(0, 4687, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4687, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4687, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4687, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_v_stacks = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4688
 *             return self._average_cell_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks.append(self.average_cell_to_face_z)
 * 
 */
  __Pyx_TraceLine(4688,0,__PYX_ERR(0, 4688, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4689
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:
 *             stacks.append(self.average_cell_to_face_z)             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_to_face = sp.vstack(stacks).tocsr()
 */
    __Pyx_TraceLine(4689,0,__PYX_ERR(0, 4689, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4689, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_stacks, __pyx_t_5); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 4689, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4688
 *             return self._average_cell_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks.append(self.average_cell_to_face_z)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4691
 *             stacks.append(self.average_cell_to_face_z)
 * 
 *         self._average_cell_to_face = sp.vstack(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_cell_to_face
 * 
 */
  __Pyx_TraceLine(4691,0,__PYX_ERR(0, 4691, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_vstack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_stacks);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face);
  __pyx_v_self->_average_cell_to_face = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4692
 * 
 *         self._average_cell_to_face = sp.vstack(stacks).tocsr()
 *         return self._average_cell_to_face             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4692,0,__PYX_ERR(0, 4692, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_cell_to_face);
  __pyx_r = __pyx_v_self->_average_cell_to_face;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4646
 * 
 *     @property
 *     def average_cell_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from cell centers to faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_face.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4695
 * 
 *     @property
 *     def average_cell_vector_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from cell centers to faces (vector quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_stacks = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4695, 0, __PYX_ERR(0, 4695, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4745
 *         the values.
 *         """
 *         if self._average_cell_vector_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_vector_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 */
  __Pyx_TraceLine(4745,0,__PYX_ERR(0, 4745, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_cell_vector_to_face != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4746
 *         """
 *         if self._average_cell_vector_to_face is not None:
 *             return self._average_cell_vector_to_face             # <<<<<<<<<<<<<<
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:
 */
    __Pyx_TraceLine(4746,0,__PYX_ERR(0, 4746, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_cell_vector_to_face);
    __pyx_r = __pyx_v_self->_average_cell_vector_to_face;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4745
 *         the values.
 *         """
 *         if self._average_cell_vector_to_face is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_vector_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4747
 *         if self._average_cell_vector_to_face is not None:
 *             return self._average_cell_vector_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             stacks.append(self.average_cell_to_face_z)
 */
  __Pyx_TraceLine(4747,0,__PYX_ERR(0, 4747, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_v_stacks = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4748
 *             return self._average_cell_vector_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks.append(self.average_cell_to_face_z)
 * 
 */
  __Pyx_TraceLine(4748,0,__PYX_ERR(0, 4748, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4749
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:
 *             stacks.append(self.average_cell_to_face_z)             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_vector_to_face = sp.block_diag(stacks).tocsr()
 */
    __Pyx_TraceLine(4749,0,__PYX_ERR(0, 4749, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_average_cell_to_face_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4749, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_stacks, __pyx_t_5); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 4749, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":4748
 *             return self._average_cell_vector_to_face
 *         stacks = [self.average_cell_to_face_x, self.average_cell_to_face_y]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             stacks.append(self.average_cell_to_face_z)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4751
 *             stacks.append(self.average_cell_to_face_z)
 * 
 *         self._average_cell_vector_to_face = sp.block_diag(stacks).tocsr()             # <<<<<<<<<<<<<<
 *         return self._average_cell_vector_to_face
 * 
 */
  __Pyx_TraceLine(4751,0,__PYX_ERR(0, 4751, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_block_diag); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_v_stacks) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_stacks);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_vector_to_face);
  __Pyx_DECREF(__pyx_v_self->_average_cell_vector_to_face);
  __pyx_v_self->_average_cell_vector_to_face = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4752
 * 
 *         self._average_cell_vector_to_face = sp.block_diag(stacks).tocsr()
 *         return self._average_cell_vector_to_face             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4752,0,__PYX_ERR(0, 4752, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_cell_vector_to_face);
  __pyx_r = __pyx_v_self->_average_cell_vector_to_face;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4695
 * 
 *     @property
 *     def average_cell_vector_to_face(self):             # <<<<<<<<<<<<<<
 *         r"""Averaging operator from cell centers to faces (vector quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_vector_to_face.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_stacks);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4755
 * 
 *     @property
 *     def average_cell_to_face_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to x faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  int_t __pyx_v_ind_parent;
  int_t __pyx_v_children_per_parent;
  Cell *__pyx_v_child;
  Cell *__pyx_v_next_cell;
  Cell *__pyx_v_prev_cell;
  double __pyx_v_w;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_10;
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  Py_ssize_t __pyx_t_14;
  int __pyx_t_15;
  PY_LONG_LONG __pyx_t_16;
  double __pyx_t_17;
  double __pyx_t_18;
  long __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  PyObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4755, 0, __PYX_ERR(0, 4755, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4768
 *             The scalar averaging operator from cell centers to x faces
 *         """
 *         if self._average_cell_to_face_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
  __Pyx_TraceLine(4768,0,__PYX_ERR(0, 4768, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_cell_to_face_x != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4769
 *         """
 *         if self._average_cell_to_face_x is not None:
 *             return self._average_cell_to_face_x             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
    __Pyx_TraceLine(4769,0,__PYX_ERR(0, 4769, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_x);
    __pyx_r = __pyx_v_self->_average_cell_to_face_x;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4768
 *             The scalar averaging operator from cell centers to x faces
 *         """
 *         if self._average_cell_to_face_x is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4770
 *         if self._average_cell_to_face_x is not None:
 *             return self._average_cell_to_face_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 */
  __Pyx_TraceLine(4770,0,__PYX_ERR(0, 4770, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4770, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4771
 *             return self._average_cell_to_face_x
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(4771,0,__PYX_ERR(0, 4771, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4772
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 */
  __Pyx_TraceLine(4772,0,__PYX_ERR(0, 4772, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4772, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4773
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_x, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_x, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2
 */
  __Pyx_TraceLine(4773,0,__PYX_ERR(0, 4773, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":4775
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2             # <<<<<<<<<<<<<<
 *         cdef c_Cell* child
 *         cdef c_Cell* next_cell
 */
  __Pyx_TraceLine(4775,0,__PYX_ERR(0, 4775, __pyx_L1_error))
  __pyx_v_children_per_parent = ((__pyx_v_dim - 1) * 2);

  /* "discretize/_extensions/tree_ext.pyx":4781
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             prev_cell = cell.neighbors[0]
 */
  __Pyx_TraceLine(4781,0,__PYX_ERR(0, 4781, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4782
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]             # <<<<<<<<<<<<<<
 *             prev_cell = cell.neighbors[0]
 *             # handle extrapolation to boundary faces
 */
    __Pyx_TraceLine(4782,0,__PYX_ERR(0, 4782, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[1]);

    /* "discretize/_extensions/tree_ext.pyx":4783
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[1]
 *             prev_cell = cell.neighbors[0]             # <<<<<<<<<<<<<<
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(4783,0,__PYX_ERR(0, 4783, __pyx_L1_error))
    __pyx_v_prev_cell = (__pyx_v_cell->neighbors[0]);

    /* "discretize/_extensions/tree_ext.pyx":4785
 *             prev_cell = cell.neighbors[0]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[3].index # +x face
 */
    __Pyx_TraceLine(4785,0,__PYX_ERR(0, 4785, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4786
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index # +x face
 *                 else:
 */
      __Pyx_TraceLine(4786,0,__PYX_ERR(0, 4786, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4787
 *             if next_cell == NULL:
 *                 if dim == 2:
 *                     ind = cell.edges[3].index # +x face             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind = cell.faces[1].index # +x face
 */
        __Pyx_TraceLine(4787,0,__PYX_ERR(0, 4787, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[3])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4786
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[3].index # +x face
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":4789
 *                     ind = cell.edges[3].index # +x face
 *                 else:
 *                     ind = cell.faces[1].index # +x face             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(4789,0,__PYX_ERR(0, 4789, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[1])->index;
        __pyx_v_ind = __pyx_t_10;
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":4790
 *                 else:
 *                     ind = cell.faces[1].index # +x face
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(4790,0,__PYX_ERR(0, 4790, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4790, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":4791
 *                     ind = cell.faces[1].index # +x face
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 *                 continue
 */
      __Pyx_TraceLine(4791,0,__PYX_ERR(0, 4791, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4791, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":4792
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 *                 continue
 *             if prev_cell == NULL:
 */
      __Pyx_TraceLine(4792,0,__PYX_ERR(0, 4792, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4792, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":4793
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 *                 continue             # <<<<<<<<<<<<<<
 *             if prev_cell == NULL:
 *                 if dim == 2:
 */
      __Pyx_TraceLine(4793,0,__PYX_ERR(0, 4793, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":4785
 *             prev_cell = cell.neighbors[0]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[3].index # +x face
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4794
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[2].index # -x face
 */
    __Pyx_TraceLine(4794,0,__PYX_ERR(0, 4794, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_prev_cell == NULL) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4795
 *                 continue
 *             if prev_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[2].index # -x face
 *                 else:
 */
      __Pyx_TraceLine(4795,0,__PYX_ERR(0, 4795, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4796
 *             if prev_cell == NULL:
 *                 if dim == 2:
 *                     ind = cell.edges[2].index # -x face             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind = cell.faces[0].index # -x face
 */
        __Pyx_TraceLine(4796,0,__PYX_ERR(0, 4796, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[2])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4795
 *                 continue
 *             if prev_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[2].index # -x face
 *                 else:
 */
        goto __pyx_L9;
      }

      /* "discretize/_extensions/tree_ext.pyx":4798
 *                     ind = cell.edges[2].index # -x face
 *                 else:
 *                     ind = cell.faces[0].index # -x face             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(4798,0,__PYX_ERR(0, 4798, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[0])->index;
        __pyx_v_ind = __pyx_t_10;
      }
      __pyx_L9:;

      /* "discretize/_extensions/tree_ext.pyx":4799
 *                 else:
 *                     ind = cell.faces[0].index # -x face
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(4799,0,__PYX_ERR(0, 4799, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4799, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":4800
 *                     ind = cell.faces[0].index # -x face
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 * 
 */
      __Pyx_TraceLine(4800,0,__PYX_ERR(0, 4800, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4800, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":4801
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 * 
 *             if next_cell.is_leaf():
 */
      __Pyx_TraceLine(4801,0,__PYX_ERR(0, 4801, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4801, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":4794
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[2].index # -x face
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4803
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
    __Pyx_TraceLine(4803,0,__PYX_ERR(0, 4803, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_next_cell->is_leaf() != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4804
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 */
      __Pyx_TraceLine(4804,0,__PYX_ERR(0, 4804, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_next_cell->level == __pyx_v_cell->level) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4806
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[3].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 */
        __Pyx_TraceLine(4806,0,__PYX_ERR(0, 4806, __pyx_L1_error))
        __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
        if (__pyx_t_2) {

          /* "discretize/_extensions/tree_ext.pyx":4807
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 *                         ind = cell.edges[3].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 */
          __Pyx_TraceLine(4807,0,__PYX_ERR(0, 4807, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->edges[3])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4808
 *                     if dim == 2:
 *                         ind = cell.edges[3].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 */
          __Pyx_TraceLine(4808,0,__PYX_ERR(0, 4808, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[0]) - ((__pyx_v_cell->edges[3])->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4809
 *                         ind = cell.edges[3].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 *                              next_cell.location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     else:
 *                         ind = cell.faces[1].index
 */
          __Pyx_TraceLine(4809,0,__PYX_ERR(0, 4809, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[0]) - (__pyx_v_cell->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4808
 *                     if dim == 2:
 *                         ind = cell.edges[3].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 */
          __Pyx_TraceLine(4808,0,__PYX_ERR(0, 4808, __pyx_L1_error))
          if (unlikely(__pyx_t_18 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4808, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

          /* "discretize/_extensions/tree_ext.pyx":4806
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[3].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 */
          goto __pyx_L12;
        }

        /* "discretize/_extensions/tree_ext.pyx":4811
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 *                         ind = cell.faces[1].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 */
        __Pyx_TraceLine(4811,0,__PYX_ERR(0, 4811, __pyx_L1_error))
        /*else*/ {
          __pyx_t_10 = (__pyx_v_cell->faces[1])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4812
 *                     else:
 *                         ind = cell.faces[1].index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind
 */
          __Pyx_TraceLine(4812,0,__PYX_ERR(0, 4812, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[0]) - ((__pyx_v_cell->faces[1])->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4813
 *                         ind = cell.faces[1].index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 */
          __Pyx_TraceLine(4813,0,__PYX_ERR(0, 4813, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[0]) - (__pyx_v_cell->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4812
 *                     else:
 *                         ind = cell.faces[1].index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind
 */
          __Pyx_TraceLine(4812,0,__PYX_ERR(0, 4812, __pyx_L1_error))
          if (unlikely(__pyx_t_17 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4812, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_18 / __pyx_t_17);
        }
        __pyx_L12:;

        /* "discretize/_extensions/tree_ext.pyx":4814
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(4814,0,__PYX_ERR(0, 4814, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4814, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":4815
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(4815,0,__PYX_ERR(0, 4815, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4815, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":4816
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 */
        __Pyx_TraceLine(4816,0,__PYX_ERR(0, 4816, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4816, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4817
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)
 */
        __Pyx_TraceLine(4817,0,__PYX_ERR(0, 4817, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4817, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4818
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)
 *                 else:
 */
        __Pyx_TraceLine(4818,0,__PYX_ERR(0, 4818, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4818, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = __pyx_v_w;

        /* "discretize/_extensions/tree_ext.pyx":4819
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # if next cell is a level larger than i am, then i need to accumulate into w
 */
        __Pyx_TraceLine(4819,0,__PYX_ERR(0, 4819, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4819, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (1.0 - __pyx_v_w);

        /* "discretize/_extensions/tree_ext.pyx":4804
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 */
        goto __pyx_L11;
      }

      /* "discretize/_extensions/tree_ext.pyx":4822
 *                 else:
 *                     # if next cell is a level larger than i am, then i need to accumulate into w
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[3].index
 *                         ind_parent = cell.edges[3].parents[0].index
 */
      __Pyx_TraceLine(4822,0,__PYX_ERR(0, 4822, __pyx_L1_error))
      /*else*/ {
        __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
        if (__pyx_t_2) {

          /* "discretize/_extensions/tree_ext.pyx":4823
 *                     # if next cell is a level larger than i am, then i need to accumulate into w
 *                     if dim == 2:
 *                         ind = cell.edges[3].index             # <<<<<<<<<<<<<<
 *                         ind_parent = cell.edges[3].parents[0].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 */
          __Pyx_TraceLine(4823,0,__PYX_ERR(0, 4823, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->edges[3])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4824
 *                     if dim == 2:
 *                         ind = cell.edges[3].index
 *                         ind_parent = cell.edges[3].parents[0].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 */
          __Pyx_TraceLine(4824,0,__PYX_ERR(0, 4824, __pyx_L1_error))
          __pyx_t_10 = ((__pyx_v_cell->edges[3])->parents[0])->index;
          __pyx_v_ind_parent = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4825
 *                         ind = cell.edges[3].index
 *                         ind_parent = cell.edges[3].parents[0].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 */
          __Pyx_TraceLine(4825,0,__PYX_ERR(0, 4825, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[0]) - ((__pyx_v_cell->edges[3])->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4826
 *                         ind_parent = cell.edges[3].parents[0].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(
 *                              next_cell.location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     else:
 *                         ind = cell.faces[1].index
 */
          __Pyx_TraceLine(4826,0,__PYX_ERR(0, 4826, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[0]) - (__pyx_v_cell->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4825
 *                         ind = cell.edges[3].index
 *                         ind_parent = cell.edges[3].parents[0].index
 *                         w = (next_cell.location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 */
          __Pyx_TraceLine(4825,0,__PYX_ERR(0, 4825, __pyx_L1_error))
          if (unlikely(__pyx_t_18 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4825, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

          /* "discretize/_extensions/tree_ext.pyx":4822
 *                 else:
 *                     # if next cell is a level larger than i am, then i need to accumulate into w
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[3].index
 *                         ind_parent = cell.edges[3].parents[0].index
 */
          goto __pyx_L13;
        }

        /* "discretize/_extensions/tree_ext.pyx":4828
 *                              next_cell.location[0] - cell.location[0])
 *                     else:
 *                         ind = cell.faces[1].index             # <<<<<<<<<<<<<<
 *                         ind_parent = cell.faces[1].parent.index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 */
        __Pyx_TraceLine(4828,0,__PYX_ERR(0, 4828, __pyx_L1_error))
        /*else*/ {
          __pyx_t_10 = (__pyx_v_cell->faces[1])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4829
 *                     else:
 *                         ind = cell.faces[1].index
 *                         ind_parent = cell.faces[1].parent.index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 */
          __Pyx_TraceLine(4829,0,__PYX_ERR(0, 4829, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->faces[1])->parent->index;
          __pyx_v_ind_parent = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4830
 *                         ind = cell.faces[1].index
 *                         ind_parent = cell.faces[1].parent.index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind_parent
 */
          __Pyx_TraceLine(4830,0,__PYX_ERR(0, 4830, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[0]) - ((__pyx_v_cell->faces[1])->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4831
 *                         ind_parent = cell.faces[1].parent.index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 */
          __Pyx_TraceLine(4831,0,__PYX_ERR(0, 4831, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[0]) - (__pyx_v_cell->location[0]));

          /* "discretize/_extensions/tree_ext.pyx":4830
 *                         ind = cell.faces[1].index
 *                         ind_parent = cell.faces[1].parent.index
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind_parent
 */
          __Pyx_TraceLine(4830,0,__PYX_ERR(0, 4830, __pyx_L1_error))
          if (unlikely(__pyx_t_17 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4830, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_18 / __pyx_t_17);
        }
        __pyx_L13:;

        /* "discretize/_extensions/tree_ext.pyx":4832
 *                         w = (next_cell.location[0] - cell.faces[1].location[0])/(
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind_parent             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(4832,0,__PYX_ERR(0, 4832, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4832, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":4833
 *                              next_cell.location[0] - cell.location[0])
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(4833,0,__PYX_ERR(0, 4833, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4833, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":4834
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 */
        __Pyx_TraceLine(4834,0,__PYX_ERR(0, 4834, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4834, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4835
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 */
        __Pyx_TraceLine(4835,0,__PYX_ERR(0, 4835, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4835, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4836
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 *             else:
 */
        __Pyx_TraceLine(4836,0,__PYX_ERR(0, 4836, __pyx_L1_error))
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4836, __pyx_L1_error)
        }
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4836, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

        /* "discretize/_extensions/tree_ext.pyx":4837
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 */
        __Pyx_TraceLine(4837,0,__PYX_ERR(0, 4837, __pyx_L1_error))
        __pyx_t_17 = (1.0 - __pyx_v_w);
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4837, __pyx_L1_error)
        }
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4837, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_17 / ((double)__pyx_v_children_per_parent));
      }
      __pyx_L11:;

      /* "discretize/_extensions/tree_ext.pyx":4803
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
      goto __pyx_L10;
    }

    /* "discretize/_extensions/tree_ext.pyx":4840
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind_parent = cell.edges[3].index
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(
 */
    __Pyx_TraceLine(4840,0,__PYX_ERR(0, 4840, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4841
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:
 *                     ind_parent = cell.edges[3].index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])
 */
        __Pyx_TraceLine(4841,0,__PYX_ERR(0, 4841, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[3])->index;
        __pyx_v_ind_parent = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4842
 *                 if dim == 2:
 *                     ind_parent = cell.edges[3].index
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(2):
 */
        __Pyx_TraceLine(4842,0,__PYX_ERR(0, 4842, __pyx_L1_error))
        __pyx_t_17 = (((__pyx_v_next_cell->children[0])->location[0]) - ((__pyx_v_cell->edges[3])->location[0]));

        /* "discretize/_extensions/tree_ext.pyx":4843
 *                     ind_parent = cell.edges[3].index
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     for i in range(2):
 *                         child = next_cell.children[2*i]
 */
        __Pyx_TraceLine(4843,0,__PYX_ERR(0, 4843, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_next_cell->children[0])->location[0]) - (__pyx_v_cell->location[0]));

        /* "discretize/_extensions/tree_ext.pyx":4842
 *                 if dim == 2:
 *                     ind_parent = cell.edges[3].index
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(2):
 */
        __Pyx_TraceLine(4842,0,__PYX_ERR(0, 4842, __pyx_L1_error))
        if (unlikely(__pyx_t_18 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4842, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

        /* "discretize/_extensions/tree_ext.pyx":4844
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(2):             # <<<<<<<<<<<<<<
 *                         child = next_cell.children[2*i]
 *                         ind = child.edges[2].index
 */
        __Pyx_TraceLine(4844,0,__PYX_ERR(0, 4844, __pyx_L1_error))
        for (__pyx_t_19 = 0; __pyx_t_19 < 2; __pyx_t_19+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4844, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":4845
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(2):
 *                         child = next_cell.children[2*i]             # <<<<<<<<<<<<<<
 *                         ind = child.edges[2].index
 *                         I[2*ind    ] = ind_parent
 */
          __Pyx_TraceLine(4845,0,__PYX_ERR(0, 4845, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4845, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_20 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_20 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 4845, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_v_child = (__pyx_v_next_cell->children[__pyx_t_20]);

          /* "discretize/_extensions/tree_ext.pyx":4846
 *                     for i in range(2):
 *                         child = next_cell.children[2*i]
 *                         ind = child.edges[2].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 */
          __Pyx_TraceLine(4846,0,__PYX_ERR(0, 4846, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_child->edges[2])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4847
 *                         child = next_cell.children[2*i]
 *                         ind = child.edges[2].index
 *                         I[2*ind    ] = ind_parent             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(4847,0,__PYX_ERR(0, 4847, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4847, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4848
 *                         ind = child.edges[2].index
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 */
          __Pyx_TraceLine(4848,0,__PYX_ERR(0, 4848, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4848, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4849
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 */
          __Pyx_TraceLine(4849,0,__PYX_ERR(0, 4849, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4849, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4850
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 */
          __Pyx_TraceLine(4850,0,__PYX_ERR(0, 4850, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_child->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4850, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4851
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 *                 else:
 */
          __Pyx_TraceLine(4851,0,__PYX_ERR(0, 4851, __pyx_L1_error))
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4851, __pyx_L1_error)
          }
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4851, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

          /* "discretize/_extensions/tree_ext.pyx":4852
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind_parent = cell.faces[1].index
 */
          __Pyx_TraceLine(4852,0,__PYX_ERR(0, 4852, __pyx_L1_error))
          __pyx_t_18 = (1.0 - __pyx_v_w);
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4852, __pyx_L1_error)
          }
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4852, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_18 / ((double)__pyx_v_children_per_parent));
        }

        /* "discretize/_extensions/tree_ext.pyx":4840
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind_parent = cell.edges[3].index
 *                     w = (next_cell.children[0].location[0] - cell.edges[3].location[0])/(
 */
        goto __pyx_L14;
      }

      /* "discretize/_extensions/tree_ext.pyx":4854
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 *                 else:
 *                     ind_parent = cell.faces[1].index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.children[0].location[0] - cell.faces[1].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])
 */
      __Pyx_TraceLine(4854,0,__PYX_ERR(0, 4854, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[1])->index;
        __pyx_v_ind_parent = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4855
 *                 else:
 *                     ind_parent = cell.faces[1].index
 *                     w = (next_cell.children[0].location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(4): # four neighbors in +x direction
 */
        __Pyx_TraceLine(4855,0,__PYX_ERR(0, 4855, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_next_cell->children[0])->location[0]) - ((__pyx_v_cell->faces[1])->location[0]));

        /* "discretize/_extensions/tree_ext.pyx":4856
 *                     ind_parent = cell.faces[1].index
 *                     w = (next_cell.children[0].location[0] - cell.faces[1].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])             # <<<<<<<<<<<<<<
 *                     for i in range(4): # four neighbors in +x direction
 *                         child = next_cell.children[2*i] #0 2 4 6
 */
        __Pyx_TraceLine(4856,0,__PYX_ERR(0, 4856, __pyx_L1_error))
        __pyx_t_17 = (((__pyx_v_next_cell->children[0])->location[0]) - (__pyx_v_cell->location[0]));

        /* "discretize/_extensions/tree_ext.pyx":4855
 *                 else:
 *                     ind_parent = cell.faces[1].index
 *                     w = (next_cell.children[0].location[0] - cell.faces[1].location[0])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(4): # four neighbors in +x direction
 */
        __Pyx_TraceLine(4855,0,__PYX_ERR(0, 4855, __pyx_L1_error))
        if (unlikely(__pyx_t_17 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4855, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_18 / __pyx_t_17);

        /* "discretize/_extensions/tree_ext.pyx":4857
 *                     w = (next_cell.children[0].location[0] - cell.faces[1].location[0])/(
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(4): # four neighbors in +x direction             # <<<<<<<<<<<<<<
 *                         child = next_cell.children[2*i] #0 2 4 6
 *                         ind = child.faces[0].index
 */
        __Pyx_TraceLine(4857,0,__PYX_ERR(0, 4857, __pyx_L1_error))
        for (__pyx_t_19 = 0; __pyx_t_19 < 4; __pyx_t_19+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4857, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":4858
 *                          next_cell.children[0].location[0] - cell.location[0])
 *                     for i in range(4): # four neighbors in +x direction
 *                         child = next_cell.children[2*i] #0 2 4 6             # <<<<<<<<<<<<<<
 *                         ind = child.faces[0].index
 *                         I[2*ind    ] = ind_parent
 */
          __Pyx_TraceLine(4858,0,__PYX_ERR(0, 4858, __pyx_L1_error))
          __pyx_t_4 = PyNumber_Multiply(__pyx_int_2, __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4858, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_20 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_20 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 4858, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_v_child = (__pyx_v_next_cell->children[__pyx_t_20]);

          /* "discretize/_extensions/tree_ext.pyx":4859
 *                     for i in range(4): # four neighbors in +x direction
 *                         child = next_cell.children[2*i] #0 2 4 6
 *                         ind = child.faces[0].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 */
          __Pyx_TraceLine(4859,0,__PYX_ERR(0, 4859, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_child->faces[0])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4860
 *                         child = next_cell.children[2*i] #0 2 4 6
 *                         ind = child.faces[0].index
 *                         I[2*ind    ] = ind_parent             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(4860,0,__PYX_ERR(0, 4860, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4860, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4861
 *                         ind = child.faces[0].index
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 */
          __Pyx_TraceLine(4861,0,__PYX_ERR(0, 4861, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4861, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4862
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 */
          __Pyx_TraceLine(4862,0,__PYX_ERR(0, 4862, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4862, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4863
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 */
          __Pyx_TraceLine(4863,0,__PYX_ERR(0, 4863, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_child->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4863, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4864
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 */
          __Pyx_TraceLine(4864,0,__PYX_ERR(0, 4864, __pyx_L1_error))
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4864, __pyx_L1_error)
          }
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4864, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

          /* "discretize/_extensions/tree_ext.pyx":4865
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_cells))
 */
          __Pyx_TraceLine(4865,0,__PYX_ERR(0, 4865, __pyx_L1_error))
          __pyx_t_17 = (1.0 - __pyx_v_w);
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4865, __pyx_L1_error)
          }
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4865, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_17 / ((double)__pyx_v_children_per_parent));
        }
      }
      __pyx_L14:;
    }
    __pyx_L10:;

    /* "discretize/_extensions/tree_ext.pyx":4781
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[1]
 *             prev_cell = cell.neighbors[0]
 */
    __Pyx_TraceLine(4781,0,__PYX_ERR(0, 4781, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4867
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 *         self._average_cell_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_cells))             # <<<<<<<<<<<<<<
 *         return self._average_cell_to_face_x
 * 
 */
  __Pyx_TraceLine(4867,0,__PYX_ERR(0, 4867, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_shape, __pyx_t_21) < 0) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 4867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_21);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_x);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_x);
  __pyx_v_self->_average_cell_to_face_x = __pyx_t_21;
  __pyx_t_21 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4868
 * 
 *         self._average_cell_to_face_x = sp.csr_matrix((V, (I, J)), shape=(self.n_faces_x, self.n_cells))
 *         return self._average_cell_to_face_x             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4868,0,__PYX_ERR(0, 4868, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_x);
  __pyx_r = __pyx_v_self->_average_cell_to_face_x;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4755
 * 
 *     @property
 *     def average_cell_to_face_x(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to x faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_face_x.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4871
 * 
 *     @property
 *     def average_cell_to_face_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to y faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  int_t __pyx_v_ind_parent;
  int_t __pyx_v_children_per_parent;
  Cell *__pyx_v_child;
  Cell *__pyx_v_next_cell;
  Cell *__pyx_v_prev_cell;
  double __pyx_v_w;
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_10;
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  Py_ssize_t __pyx_t_14;
  int __pyx_t_15;
  PY_LONG_LONG __pyx_t_16;
  double __pyx_t_17;
  double __pyx_t_18;
  long __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  PyObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4871, 0, __PYX_ERR(0, 4871, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":4884
 *             The scalar averaging operator from cell centers to y faces
 *         """
 *         if self._average_cell_to_face_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_y
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 */
  __Pyx_TraceLine(4884,0,__PYX_ERR(0, 4884, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_average_cell_to_face_y != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":4885
 *         """
 *         if self._average_cell_to_face_y is not None:
 *             return self._average_cell_to_face_y             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 */
    __Pyx_TraceLine(4885,0,__PYX_ERR(0, 4885, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_y);
    __pyx_r = __pyx_v_self->_average_cell_to_face_y;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":4884
 *             The scalar averaging operator from cell centers to y faces
 *         """
 *         if self._average_cell_to_face_y is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_y
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":4886
 *         if self._average_cell_to_face_y is not None:
 *             return self._average_cell_to_face_y
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 */
  __Pyx_TraceLine(4886,0,__PYX_ERR(0, 4886, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4886, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4887
 *             return self._average_cell_to_face_y
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(4887,0,__PYX_ERR(0, 4887, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 4887, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4888
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 */
  __Pyx_TraceLine(4888,0,__PYX_ERR(0, 4888, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 4888, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":4889
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_y, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_y, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2
 */
  __Pyx_TraceLine(4889,0,__PYX_ERR(0, 4889, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":4891
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2             # <<<<<<<<<<<<<<
 *         cdef c_Cell* child
 *         cdef c_Cell* next_cell
 */
  __Pyx_TraceLine(4891,0,__PYX_ERR(0, 4891, __pyx_L1_error))
  __pyx_v_children_per_parent = ((__pyx_v_dim - 1) * 2);

  /* "discretize/_extensions/tree_ext.pyx":4897
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             prev_cell = cell.neighbors[2]
 */
  __Pyx_TraceLine(4897,0,__PYX_ERR(0, 4897, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":4898
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]             # <<<<<<<<<<<<<<
 *             prev_cell = cell.neighbors[2]
 *             # handle extrapolation to boundary faces
 */
    __Pyx_TraceLine(4898,0,__PYX_ERR(0, 4898, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[3]);

    /* "discretize/_extensions/tree_ext.pyx":4899
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[3]
 *             prev_cell = cell.neighbors[2]             # <<<<<<<<<<<<<<
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(4899,0,__PYX_ERR(0, 4899, __pyx_L1_error))
    __pyx_v_prev_cell = (__pyx_v_cell->neighbors[2]);

    /* "discretize/_extensions/tree_ext.pyx":4901
 *             prev_cell = cell.neighbors[2]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[1].index
 */
    __Pyx_TraceLine(4901,0,__PYX_ERR(0, 4901, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4902
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                 else:
 */
      __Pyx_TraceLine(4902,0,__PYX_ERR(0, 4902, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4903
 *             if next_cell == NULL:
 *                 if dim == 2:
 *                     ind = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind = cell.faces[3].index
 */
        __Pyx_TraceLine(4903,0,__PYX_ERR(0, 4903, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[1])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4902
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[1].index
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":4905
 *                     ind = cell.edges[1].index
 *                 else:
 *                     ind = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(4905,0,__PYX_ERR(0, 4905, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[3])->index;
        __pyx_v_ind = __pyx_t_10;
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":4906
 *                 else:
 *                     ind = cell.faces[3].index
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(4906,0,__PYX_ERR(0, 4906, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4906, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":4907
 *                     ind = cell.faces[3].index
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 *                 continue
 */
      __Pyx_TraceLine(4907,0,__PYX_ERR(0, 4907, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4907, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":4908
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 *                 continue
 *             if prev_cell == NULL:
 */
      __Pyx_TraceLine(4908,0,__PYX_ERR(0, 4908, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4908, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":4909
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 *                 continue             # <<<<<<<<<<<<<<
 *             if prev_cell == NULL:
 *                 if dim == 2:
 */
      __Pyx_TraceLine(4909,0,__PYX_ERR(0, 4909, __pyx_L1_error))
      goto __pyx_L4_continue;

      /* "discretize/_extensions/tree_ext.pyx":4901
 *             prev_cell = cell.neighbors[2]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[1].index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4910
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[0].index
 */
    __Pyx_TraceLine(4910,0,__PYX_ERR(0, 4910, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_prev_cell == NULL) != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4911
 *                 continue
 *             if prev_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[0].index
 *                 else:
 */
      __Pyx_TraceLine(4911,0,__PYX_ERR(0, 4911, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4912
 *             if prev_cell == NULL:
 *                 if dim == 2:
 *                     ind = cell.edges[0].index             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind = cell.faces[2].index
 */
        __Pyx_TraceLine(4912,0,__PYX_ERR(0, 4912, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[0])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4911
 *                 continue
 *             if prev_cell == NULL:
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind = cell.edges[0].index
 *                 else:
 */
        goto __pyx_L9;
      }

      /* "discretize/_extensions/tree_ext.pyx":4914
 *                     ind = cell.edges[0].index
 *                 else:
 *                     ind = cell.faces[2].index             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(4914,0,__PYX_ERR(0, 4914, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[2])->index;
        __pyx_v_ind = __pyx_t_10;
      }
      __pyx_L9:;

      /* "discretize/_extensions/tree_ext.pyx":4915
 *                 else:
 *                     ind = cell.faces[2].index
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(4915,0,__PYX_ERR(0, 4915, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4915, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":4916
 *                     ind = cell.faces[2].index
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 * 
 */
      __Pyx_TraceLine(4916,0,__PYX_ERR(0, 4916, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4916, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":4917
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 * 
 *             if next_cell.is_leaf():
 */
      __Pyx_TraceLine(4917,0,__PYX_ERR(0, 4917, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 4917, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":4910
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 if dim == 2:
 *                     ind = cell.edges[0].index
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":4919
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
    __Pyx_TraceLine(4919,0,__PYX_ERR(0, 4919, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_next_cell->is_leaf() != 0);
    if (__pyx_t_2) {

      /* "discretize/_extensions/tree_ext.pyx":4920
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 */
      __Pyx_TraceLine(4920,0,__PYX_ERR(0, 4920, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_next_cell->level == __pyx_v_cell->level) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4922
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[1].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 */
        __Pyx_TraceLine(4922,0,__PYX_ERR(0, 4922, __pyx_L1_error))
        __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
        if (__pyx_t_2) {

          /* "discretize/_extensions/tree_ext.pyx":4923
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 *                         ind = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 */
          __Pyx_TraceLine(4923,0,__PYX_ERR(0, 4923, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->edges[1])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4924
 *                     if dim == 2:
 *                         ind = cell.edges[1].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 */
          __Pyx_TraceLine(4924,0,__PYX_ERR(0, 4924, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[1]) - ((__pyx_v_cell->edges[1])->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4925
 *                         ind = cell.edges[1].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 *                              next_cell.location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     else:
 *                         ind = cell.faces[3].index
 */
          __Pyx_TraceLine(4925,0,__PYX_ERR(0, 4925, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[1]) - (__pyx_v_cell->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4924
 *                     if dim == 2:
 *                         ind = cell.edges[1].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 */
          __Pyx_TraceLine(4924,0,__PYX_ERR(0, 4924, __pyx_L1_error))
          if (unlikely(__pyx_t_18 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4924, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

          /* "discretize/_extensions/tree_ext.pyx":4922
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[1].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 */
          goto __pyx_L12;
        }

        /* "discretize/_extensions/tree_ext.pyx":4927
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 *                         ind = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 */
        __Pyx_TraceLine(4927,0,__PYX_ERR(0, 4927, __pyx_L1_error))
        /*else*/ {
          __pyx_t_10 = (__pyx_v_cell->faces[3])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4928
 *                     else:
 *                         ind = cell.faces[3].index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind
 */
          __Pyx_TraceLine(4928,0,__PYX_ERR(0, 4928, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[1]) - ((__pyx_v_cell->faces[3])->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4929
 *                         ind = cell.faces[3].index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 */
          __Pyx_TraceLine(4929,0,__PYX_ERR(0, 4929, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[1]) - (__pyx_v_cell->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4928
 *                     else:
 *                         ind = cell.faces[3].index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind
 */
          __Pyx_TraceLine(4928,0,__PYX_ERR(0, 4928, __pyx_L1_error))
          if (unlikely(__pyx_t_17 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4928, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_18 / __pyx_t_17);
        }
        __pyx_L12:;

        /* "discretize/_extensions/tree_ext.pyx":4930
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(4930,0,__PYX_ERR(0, 4930, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4930, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":4931
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(4931,0,__PYX_ERR(0, 4931, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4931, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":4932
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 */
        __Pyx_TraceLine(4932,0,__PYX_ERR(0, 4932, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4932, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4933
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)
 */
        __Pyx_TraceLine(4933,0,__PYX_ERR(0, 4933, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4933, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4934
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)
 *                 else:
 */
        __Pyx_TraceLine(4934,0,__PYX_ERR(0, 4934, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4934, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = __pyx_v_w;

        /* "discretize/_extensions/tree_ext.pyx":4935
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # if next cell is a level larger than i am
 */
        __Pyx_TraceLine(4935,0,__PYX_ERR(0, 4935, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4935, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (1.0 - __pyx_v_w);

        /* "discretize/_extensions/tree_ext.pyx":4920
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     if dim == 2:
 */
        goto __pyx_L11;
      }

      /* "discretize/_extensions/tree_ext.pyx":4938
 *                 else:
 *                     # if next cell is a level larger than i am
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[1].index
 *                         ind_parent = cell.edges[1].parents[0].index
 */
      __Pyx_TraceLine(4938,0,__PYX_ERR(0, 4938, __pyx_L1_error))
      /*else*/ {
        __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
        if (__pyx_t_2) {

          /* "discretize/_extensions/tree_ext.pyx":4939
 *                     # if next cell is a level larger than i am
 *                     if dim == 2:
 *                         ind = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                         ind_parent = cell.edges[1].parents[0].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 */
          __Pyx_TraceLine(4939,0,__PYX_ERR(0, 4939, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->edges[1])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4940
 *                     if dim == 2:
 *                         ind = cell.edges[1].index
 *                         ind_parent = cell.edges[1].parents[0].index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 */
          __Pyx_TraceLine(4940,0,__PYX_ERR(0, 4940, __pyx_L1_error))
          __pyx_t_10 = ((__pyx_v_cell->edges[1])->parents[0])->index;
          __pyx_v_ind_parent = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4941
 *                         ind = cell.edges[1].index
 *                         ind_parent = cell.edges[1].parents[0].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 */
          __Pyx_TraceLine(4941,0,__PYX_ERR(0, 4941, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[1]) - ((__pyx_v_cell->edges[1])->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4942
 *                         ind_parent = cell.edges[1].parents[0].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(
 *                              next_cell.location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     else:
 *                         ind = cell.faces[3].index
 */
          __Pyx_TraceLine(4942,0,__PYX_ERR(0, 4942, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[1]) - (__pyx_v_cell->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4941
 *                         ind = cell.edges[1].index
 *                         ind_parent = cell.edges[1].parents[0].index
 *                         w = (next_cell.location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 */
          __Pyx_TraceLine(4941,0,__PYX_ERR(0, 4941, __pyx_L1_error))
          if (unlikely(__pyx_t_18 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4941, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

          /* "discretize/_extensions/tree_ext.pyx":4938
 *                 else:
 *                     # if next cell is a level larger than i am
 *                     if dim == 2:             # <<<<<<<<<<<<<<
 *                         ind = cell.edges[1].index
 *                         ind_parent = cell.edges[1].parents[0].index
 */
          goto __pyx_L13;
        }

        /* "discretize/_extensions/tree_ext.pyx":4944
 *                              next_cell.location[1] - cell.location[1])
 *                     else:
 *                         ind = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                         ind_parent = cell.faces[3].parent.index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 */
        __Pyx_TraceLine(4944,0,__PYX_ERR(0, 4944, __pyx_L1_error))
        /*else*/ {
          __pyx_t_10 = (__pyx_v_cell->faces[3])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4945
 *                     else:
 *                         ind = cell.faces[3].index
 *                         ind_parent = cell.faces[3].parent.index             # <<<<<<<<<<<<<<
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 */
          __Pyx_TraceLine(4945,0,__PYX_ERR(0, 4945, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_cell->faces[3])->parent->index;
          __pyx_v_ind_parent = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4946
 *                         ind = cell.faces[3].index
 *                         ind_parent = cell.faces[3].parent.index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind_parent
 */
          __Pyx_TraceLine(4946,0,__PYX_ERR(0, 4946, __pyx_L1_error))
          __pyx_t_18 = ((__pyx_v_next_cell->location[1]) - ((__pyx_v_cell->faces[3])->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4947
 *                         ind_parent = cell.faces[3].parent.index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 */
          __Pyx_TraceLine(4947,0,__PYX_ERR(0, 4947, __pyx_L1_error))
          __pyx_t_17 = ((__pyx_v_next_cell->location[1]) - (__pyx_v_cell->location[1]));

          /* "discretize/_extensions/tree_ext.pyx":4946
 *                         ind = cell.faces[3].index
 *                         ind_parent = cell.faces[3].parent.index
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind_parent
 */
          __Pyx_TraceLine(4946,0,__PYX_ERR(0, 4946, __pyx_L1_error))
          if (unlikely(__pyx_t_17 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4946, __pyx_L1_error)
          }
          __pyx_v_w = (__pyx_t_18 / __pyx_t_17);
        }
        __pyx_L13:;

        /* "discretize/_extensions/tree_ext.pyx":4948
 *                         w = (next_cell.location[1] - cell.faces[3].location[1])/(
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind_parent             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(4948,0,__PYX_ERR(0, 4948, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4948, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":4949
 *                              next_cell.location[1] - cell.location[1])
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(4949,0,__PYX_ERR(0, 4949, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4949, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":4950
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 */
        __Pyx_TraceLine(4950,0,__PYX_ERR(0, 4950, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4950, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4951
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 */
        __Pyx_TraceLine(4951,0,__PYX_ERR(0, 4951, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4951, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":4952
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 *             else:
 */
        __Pyx_TraceLine(4952,0,__PYX_ERR(0, 4952, __pyx_L1_error))
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4952, __pyx_L1_error)
        }
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4952, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

        /* "discretize/_extensions/tree_ext.pyx":4953
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 */
        __Pyx_TraceLine(4953,0,__PYX_ERR(0, 4953, __pyx_L1_error))
        __pyx_t_17 = (1.0 - __pyx_v_w);
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4953, __pyx_L1_error)
        }
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 4953, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_17 / ((double)__pyx_v_children_per_parent));
      }
      __pyx_L11:;

      /* "discretize/_extensions/tree_ext.pyx":4919
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
      goto __pyx_L10;
    }

    /* "discretize/_extensions/tree_ext.pyx":4956
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind_parent = cell.edges[1].index
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(
 */
    __Pyx_TraceLine(4956,0,__PYX_ERR(0, 4956, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_2) {

        /* "discretize/_extensions/tree_ext.pyx":4957
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:
 *                     ind_parent = cell.edges[1].index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])
 */
        __Pyx_TraceLine(4957,0,__PYX_ERR(0, 4957, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->edges[1])->index;
        __pyx_v_ind_parent = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4958
 *                 if dim == 2:
 *                     ind_parent = cell.edges[1].index
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(2):
 */
        __Pyx_TraceLine(4958,0,__PYX_ERR(0, 4958, __pyx_L1_error))
        __pyx_t_17 = (((__pyx_v_next_cell->children[0])->location[1]) - ((__pyx_v_cell->edges[1])->location[1]));

        /* "discretize/_extensions/tree_ext.pyx":4959
 *                     ind_parent = cell.edges[1].index
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     for i in range(2):
 *                         child = next_cell.children[i]
 */
        __Pyx_TraceLine(4959,0,__PYX_ERR(0, 4959, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_next_cell->children[0])->location[1]) - (__pyx_v_cell->location[1]));

        /* "discretize/_extensions/tree_ext.pyx":4958
 *                 if dim == 2:
 *                     ind_parent = cell.edges[1].index
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(2):
 */
        __Pyx_TraceLine(4958,0,__PYX_ERR(0, 4958, __pyx_L1_error))
        if (unlikely(__pyx_t_18 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4958, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

        /* "discretize/_extensions/tree_ext.pyx":4960
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(2):             # <<<<<<<<<<<<<<
 *                         child = next_cell.children[i]
 *                         ind = child.edges[0].index
 */
        __Pyx_TraceLine(4960,0,__PYX_ERR(0, 4960, __pyx_L1_error))
        for (__pyx_t_19 = 0; __pyx_t_19 < 2; __pyx_t_19+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4960, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":4961
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(2):
 *                         child = next_cell.children[i]             # <<<<<<<<<<<<<<
 *                         ind = child.edges[0].index
 *                         I[2*ind    ] = ind_parent
 */
          __Pyx_TraceLine(4961,0,__PYX_ERR(0, 4961, __pyx_L1_error))
          __pyx_t_20 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_20 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 4961, __pyx_L1_error)
          __pyx_v_child = (__pyx_v_next_cell->children[__pyx_t_20]);

          /* "discretize/_extensions/tree_ext.pyx":4962
 *                     for i in range(2):
 *                         child = next_cell.children[i]
 *                         ind = child.edges[0].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 */
          __Pyx_TraceLine(4962,0,__PYX_ERR(0, 4962, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_child->edges[0])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4963
 *                         child = next_cell.children[i]
 *                         ind = child.edges[0].index
 *                         I[2*ind    ] = ind_parent             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(4963,0,__PYX_ERR(0, 4963, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4963, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4964
 *                         ind = child.edges[0].index
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 */
          __Pyx_TraceLine(4964,0,__PYX_ERR(0, 4964, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4964, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4965
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 */
          __Pyx_TraceLine(4965,0,__PYX_ERR(0, 4965, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4965, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4966
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 */
          __Pyx_TraceLine(4966,0,__PYX_ERR(0, 4966, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_child->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4966, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4967
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 *                 else:
 */
          __Pyx_TraceLine(4967,0,__PYX_ERR(0, 4967, __pyx_L1_error))
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4967, __pyx_L1_error)
          }
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4967, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

          /* "discretize/_extensions/tree_ext.pyx":4968
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 *                 else:
 *                     ind_parent = cell.faces[3].index
 */
          __Pyx_TraceLine(4968,0,__PYX_ERR(0, 4968, __pyx_L1_error))
          __pyx_t_18 = (1.0 - __pyx_v_w);
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4968, __pyx_L1_error)
          }
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4968, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_18 / ((double)__pyx_v_children_per_parent));
        }

        /* "discretize/_extensions/tree_ext.pyx":4956
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 if dim == 2:             # <<<<<<<<<<<<<<
 *                     ind_parent = cell.edges[1].index
 *                     w = (next_cell.children[0].location[1] - cell.edges[1].location[1])/(
 */
        goto __pyx_L14;
      }

      /* "discretize/_extensions/tree_ext.pyx":4970
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 *                 else:
 *                     ind_parent = cell.faces[3].index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.children[0].location[1] - cell.faces[3].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])
 */
      __Pyx_TraceLine(4970,0,__PYX_ERR(0, 4970, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[3])->index;
        __pyx_v_ind_parent = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":4971
 *                 else:
 *                     ind_parent = cell.faces[3].index
 *                     w = (next_cell.children[0].location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(4): # four neighbors in +y direction
 */
        __Pyx_TraceLine(4971,0,__PYX_ERR(0, 4971, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_next_cell->children[0])->location[1]) - ((__pyx_v_cell->faces[3])->location[1]));

        /* "discretize/_extensions/tree_ext.pyx":4972
 *                     ind_parent = cell.faces[3].index
 *                     w = (next_cell.children[0].location[1] - cell.faces[3].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])             # <<<<<<<<<<<<<<
 *                     for i in range(4): # four neighbors in +y direction
 *                         child = next_cell.children[(i>>1)*4 + i%2] #0 1 4 5
 */
        __Pyx_TraceLine(4972,0,__PYX_ERR(0, 4972, __pyx_L1_error))
        __pyx_t_17 = (((__pyx_v_next_cell->children[0])->location[1]) - (__pyx_v_cell->location[1]));

        /* "discretize/_extensions/tree_ext.pyx":4971
 *                 else:
 *                     ind_parent = cell.faces[3].index
 *                     w = (next_cell.children[0].location[1] - cell.faces[3].location[1])/(             # <<<<<<<<<<<<<<
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(4): # four neighbors in +y direction
 */
        __Pyx_TraceLine(4971,0,__PYX_ERR(0, 4971, __pyx_L1_error))
        if (unlikely(__pyx_t_17 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 4971, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_18 / __pyx_t_17);

        /* "discretize/_extensions/tree_ext.pyx":4973
 *                     w = (next_cell.children[0].location[1] - cell.faces[3].location[1])/(
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(4): # four neighbors in +y direction             # <<<<<<<<<<<<<<
 *                         child = next_cell.children[(i>>1)*4 + i%2] #0 1 4 5
 *                         ind = child.faces[2].index
 */
        __Pyx_TraceLine(4973,0,__PYX_ERR(0, 4973, __pyx_L1_error))
        for (__pyx_t_19 = 0; __pyx_t_19 < 4; __pyx_t_19+=1) {
          __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4973, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "discretize/_extensions/tree_ext.pyx":4974
 *                          next_cell.children[0].location[1] - cell.location[1])
 *                     for i in range(4): # four neighbors in +y direction
 *                         child = next_cell.children[(i>>1)*4 + i%2] #0 1 4 5             # <<<<<<<<<<<<<<
 *                         ind = child.faces[2].index
 *                         I[2*ind    ] = ind_parent
 */
          __Pyx_TraceLine(4974,0,__PYX_ERR(0, 4974, __pyx_L1_error))
          __pyx_t_4 = __Pyx_PyInt_RshiftObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_7 = PyNumber_Multiply(__pyx_t_4, __pyx_int_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_6 = PyNumber_Add(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_20 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_20 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 4974, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_v_child = (__pyx_v_next_cell->children[__pyx_t_20]);

          /* "discretize/_extensions/tree_ext.pyx":4975
 *                     for i in range(4): # four neighbors in +y direction
 *                         child = next_cell.children[(i>>1)*4 + i%2] #0 1 4 5
 *                         ind = child.faces[2].index             # <<<<<<<<<<<<<<
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 */
          __Pyx_TraceLine(4975,0,__PYX_ERR(0, 4975, __pyx_L1_error))
          __pyx_t_10 = (__pyx_v_child->faces[2])->index;
          __pyx_v_ind = __pyx_t_10;

          /* "discretize/_extensions/tree_ext.pyx":4976
 *                         child = next_cell.children[(i>>1)*4 + i%2] #0 1 4 5
 *                         ind = child.faces[2].index
 *                         I[2*ind    ] = ind_parent             # <<<<<<<<<<<<<<
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 */
          __Pyx_TraceLine(4976,0,__PYX_ERR(0, 4976, __pyx_L1_error))
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4976, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4977
 *                         ind = child.faces[2].index
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent             # <<<<<<<<<<<<<<
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 */
          __Pyx_TraceLine(4977,0,__PYX_ERR(0, 4977, __pyx_L1_error))
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_I.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4977, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

          /* "discretize/_extensions/tree_ext.pyx":4978
 *                         I[2*ind    ] = ind_parent
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 */
          __Pyx_TraceLine(4978,0,__PYX_ERR(0, 4978, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_cell->index;
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4978, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4979
 *                         I[2*ind + 1] = ind_parent
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index             # <<<<<<<<<<<<<<
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 */
          __Pyx_TraceLine(4979,0,__PYX_ERR(0, 4979, __pyx_L1_error))
          __pyx_t_16 = __pyx_v_child->index;
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4979, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

          /* "discretize/_extensions/tree_ext.pyx":4980
 *                         J[2*ind    ] = cell.index
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 */
          __Pyx_TraceLine(4980,0,__PYX_ERR(0, 4980, __pyx_L1_error))
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4980, __pyx_L1_error)
          }
          __pyx_t_14 = (2 * __pyx_v_ind);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4980, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

          /* "discretize/_extensions/tree_ext.pyx":4981
 *                         J[2*ind + 1] = child.index
 *                         V[2*ind    ] = w/children_per_parent
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_to_face_y = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_y, self.n_cells))
 */
          __Pyx_TraceLine(4981,0,__PYX_ERR(0, 4981, __pyx_L1_error))
          __pyx_t_17 = (1.0 - __pyx_v_w);
          if (unlikely(__pyx_v_children_per_parent == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 4981, __pyx_L1_error)
          }
          __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
          __pyx_t_15 = -1;
          if (__pyx_t_14 < 0) {
            __pyx_t_14 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 4981, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_17 / ((double)__pyx_v_children_per_parent));
        }
      }
      __pyx_L14:;
    }
    __pyx_L10:;

    /* "discretize/_extensions/tree_ext.pyx":4897
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[3]
 *             prev_cell = cell.neighbors[2]
 */
    __Pyx_TraceLine(4897,0,__PYX_ERR(0, 4897, __pyx_L1_error))
    __pyx_L4_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":4983
 *                         V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 *         self._average_cell_to_face_y = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_y, self.n_cells))             # <<<<<<<<<<<<<<
 *         return self._average_cell_to_face_y
 * 
 */
  __Pyx_TraceLine(4983,0,__PYX_ERR(0, 4983, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __pyx_t_7 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_7);
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_shape, __pyx_t_21) < 0) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 4983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_21);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_y);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_y);
  __pyx_v_self->_average_cell_to_face_y = __pyx_t_21;
  __pyx_t_21 = 0;

  /* "discretize/_extensions/tree_ext.pyx":4984
 * 
 *         self._average_cell_to_face_y = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_y, self.n_cells))
 *         return self._average_cell_to_face_y             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(4984,0,__PYX_ERR(0, 4984, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_y);
  __pyx_r = __pyx_v_self->_average_cell_to_face_y;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4871
 * 
 *     @property
 *     def average_cell_to_face_y(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to y faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_face_y.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":4987
 * 
 *     @property
 *     def average_cell_to_face_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to z faces (scalar quantities).
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  int_t __pyx_v_ind_parent;
  int_t __pyx_v_children_per_parent;
  Cell *__pyx_v_child;
  Cell *__pyx_v_next_cell;
  Cell *__pyx_v_prev_cell;
  double __pyx_v_w;
  Cell *__pyx_v_cell;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_10;
  std::vector<Cell *> ::iterator __pyx_t_11;
  std::vector<Cell *>  *__pyx_t_12;
  Cell *__pyx_t_13;
  Py_ssize_t __pyx_t_14;
  int __pyx_t_15;
  PY_LONG_LONG __pyx_t_16;
  double __pyx_t_17;
  double __pyx_t_18;
  long __pyx_t_19;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 4987, 0, __PYX_ERR(0, 4987, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5000
 *             The scalar averaging operator from cell centers to z faces
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z-faces in 2D')
 *         if self._average_cell_to_face_z is not None:
 */
  __Pyx_TraceLine(5000,0,__PYX_ERR(0, 5000, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 5000, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "discretize/_extensions/tree_ext.pyx":5001
 *         """
 *         if self.dim == 2:
 *             raise Exception('TreeMesh has no z-faces in 2D')             # <<<<<<<<<<<<<<
 *         if self._average_cell_to_face_z is not None:
 *             return self._average_cell_to_face_z
 */
    __Pyx_TraceLine(5001,0,__PYX_ERR(0, 5001, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 5001, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":5000
 *             The scalar averaging operator from cell centers to z faces
 *         """
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             raise Exception('TreeMesh has no z-faces in 2D')
 *         if self._average_cell_to_face_z is not None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5002
 *         if self.dim == 2:
 *             raise Exception('TreeMesh has no z-faces in 2D')
 *         if self._average_cell_to_face_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_z
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 */
  __Pyx_TraceLine(5002,0,__PYX_ERR(0, 5002, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_self->_average_cell_to_face_z != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "discretize/_extensions/tree_ext.pyx":5003
 *             raise Exception('TreeMesh has no z-faces in 2D')
 *         if self._average_cell_to_face_z is not None:
 *             return self._average_cell_to_face_z             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 */
    __Pyx_TraceLine(5003,0,__PYX_ERR(0, 5003, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_z);
    __pyx_r = __pyx_v_self->_average_cell_to_face_z;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":5002
 *         if self.dim == 2:
 *             raise Exception('TreeMesh has no z-faces in 2D')
 *         if self._average_cell_to_face_z is not None:             # <<<<<<<<<<<<<<
 *             return self._average_cell_to_face_z
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5004
 *         if self._average_cell_to_face_z is not None:
 *             return self._average_cell_to_face_z
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 */
  __Pyx_TraceLine(5004,0,__PYX_ERR(0, 5004, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 5004, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5005
 *             return self._average_cell_to_face_z
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 *         cdef int dim = self._dim
 */
  __Pyx_TraceLine(5005,0,__PYX_ERR(0, 5005, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_Multiply(__pyx_int_2, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 5005, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5006
 *         cdef np.int64_t[:] I = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 */
  __Pyx_TraceLine(5006,0,__PYX_ERR(0, 5006, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_z); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Multiply(__pyx_int_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5006, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5007
 *         cdef np.int64_t[:] J = np.zeros(2*self.n_total_faces_z, dtype=np.int64)
 *         cdef np.float64_t[:] V = np.zeros(2*self.n_total_faces_z, dtype=np.float64)
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2
 */
  __Pyx_TraceLine(5007,0,__PYX_ERR(0, 5007, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":5009
 *         cdef int dim = self._dim
 *         cdef int_t ind, ind_parent
 *         cdef int_t children_per_parent = (dim-1)*2             # <<<<<<<<<<<<<<
 *         cdef c_Cell* child
 *         cdef c_Cell* next_cell
 */
  __Pyx_TraceLine(5009,0,__PYX_ERR(0, 5009, __pyx_L1_error))
  __pyx_v_children_per_parent = ((__pyx_v_dim - 1) * 2);

  /* "discretize/_extensions/tree_ext.pyx":5015
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             prev_cell = cell.neighbors[4]
 */
  __Pyx_TraceLine(5015,0,__PYX_ERR(0, 5015, __pyx_L1_error))
  __pyx_t_12 = &__pyx_v_self->tree->cells;
  __pyx_t_11 = __pyx_t_12->begin();
  for (;;) {
    if (!(__pyx_t_11 != __pyx_t_12->end())) break;
    __pyx_t_13 = *__pyx_t_11;
    ++__pyx_t_11;
    __pyx_v_cell = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":5016
 * 
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]             # <<<<<<<<<<<<<<
 *             prev_cell = cell.neighbors[4]
 *             # handle extrapolation to boundary faces
 */
    __Pyx_TraceLine(5016,0,__PYX_ERR(0, 5016, __pyx_L1_error))
    __pyx_v_next_cell = (__pyx_v_cell->neighbors[5]);

    /* "discretize/_extensions/tree_ext.pyx":5017
 *         for cell in self.tree.cells :
 *             next_cell = cell.neighbors[5]
 *             prev_cell = cell.neighbors[4]             # <<<<<<<<<<<<<<
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 */
    __Pyx_TraceLine(5017,0,__PYX_ERR(0, 5017, __pyx_L1_error))
    __pyx_v_prev_cell = (__pyx_v_cell->neighbors[4]);

    /* "discretize/_extensions/tree_ext.pyx":5019
 *             prev_cell = cell.neighbors[4]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index # +z face
 *                 I[2*ind  ] = ind
 */
    __Pyx_TraceLine(5019,0,__PYX_ERR(0, 5019, __pyx_L1_error))
    __pyx_t_4 = ((__pyx_v_next_cell == NULL) != 0);
    if (__pyx_t_4) {

      /* "discretize/_extensions/tree_ext.pyx":5020
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:
 *                 ind = cell.faces[5].index # +z face             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(5020,0,__PYX_ERR(0, 5020, __pyx_L1_error))
      __pyx_t_10 = (__pyx_v_cell->faces[5])->index;
      __pyx_v_ind = __pyx_t_10;

      /* "discretize/_extensions/tree_ext.pyx":5021
 *             if next_cell == NULL:
 *                 ind = cell.faces[5].index # +z face
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(5021,0,__PYX_ERR(0, 5021, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5021, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":5022
 *                 ind = cell.faces[5].index # +z face
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 *                 continue
 */
      __Pyx_TraceLine(5022,0,__PYX_ERR(0, 5022, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5022, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":5023
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 *                 continue
 *             if prev_cell == NULL:
 */
      __Pyx_TraceLine(5023,0,__PYX_ERR(0, 5023, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5023, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":5024
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 *                 continue             # <<<<<<<<<<<<<<
 *             if prev_cell == NULL:
 *                 ind = cell.faces[4].index # -z face
 */
      __Pyx_TraceLine(5024,0,__PYX_ERR(0, 5024, __pyx_L1_error))
      goto __pyx_L5_continue;

      /* "discretize/_extensions/tree_ext.pyx":5019
 *             prev_cell = cell.neighbors[4]
 *             # handle extrapolation to boundary faces
 *             if next_cell == NULL:             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[5].index # +z face
 *                 I[2*ind  ] = ind
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":5025
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[4].index # -z face
 *                 I[2*ind  ] = ind
 */
    __Pyx_TraceLine(5025,0,__PYX_ERR(0, 5025, __pyx_L1_error))
    __pyx_t_4 = ((__pyx_v_prev_cell == NULL) != 0);
    if (__pyx_t_4) {

      /* "discretize/_extensions/tree_ext.pyx":5026
 *                 continue
 *             if prev_cell == NULL:
 *                 ind = cell.faces[4].index # -z face             # <<<<<<<<<<<<<<
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 */
      __Pyx_TraceLine(5026,0,__PYX_ERR(0, 5026, __pyx_L1_error))
      __pyx_t_10 = (__pyx_v_cell->faces[4])->index;
      __pyx_v_ind = __pyx_t_10;

      /* "discretize/_extensions/tree_ext.pyx":5027
 *             if prev_cell == NULL:
 *                 ind = cell.faces[4].index # -z face
 *                 I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0
 */
      __Pyx_TraceLine(5027,0,__PYX_ERR(0, 5027, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_I.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5027, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

      /* "discretize/_extensions/tree_ext.pyx":5028
 *                 ind = cell.faces[4].index # -z face
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                 V[2*ind  ] = 1.0
 * 
 */
      __Pyx_TraceLine(5028,0,__PYX_ERR(0, 5028, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_cell->index;
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5028, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

      /* "discretize/_extensions/tree_ext.pyx":5029
 *                 I[2*ind  ] = ind
 *                 J[2*ind  ] = cell.index
 *                 V[2*ind  ] = 1.0             # <<<<<<<<<<<<<<
 * 
 *             if next_cell.is_leaf():
 */
      __Pyx_TraceLine(5029,0,__PYX_ERR(0, 5029, __pyx_L1_error))
      __pyx_t_14 = (2 * __pyx_v_ind);
      __pyx_t_15 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
      if (unlikely(__pyx_t_15 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_15);
        __PYX_ERR(0, 5029, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = 1.0;

      /* "discretize/_extensions/tree_ext.pyx":5025
 *                 V[2*ind  ] = 1.0
 *                 continue
 *             if prev_cell == NULL:             # <<<<<<<<<<<<<<
 *                 ind = cell.faces[4].index # -z face
 *                 I[2*ind  ] = ind
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":5031
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
    __Pyx_TraceLine(5031,0,__PYX_ERR(0, 5031, __pyx_L1_error))
    __pyx_t_4 = (__pyx_v_next_cell->is_leaf() != 0);
    if (__pyx_t_4) {

      /* "discretize/_extensions/tree_ext.pyx":5032
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     ind = cell.faces[5].index
 */
      __Pyx_TraceLine(5032,0,__PYX_ERR(0, 5032, __pyx_L1_error))
      __pyx_t_4 = ((__pyx_v_next_cell->level == __pyx_v_cell->level) != 0);
      if (__pyx_t_4) {

        /* "discretize/_extensions/tree_ext.pyx":5034
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 *                     ind = cell.faces[5].index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])
 */
        __Pyx_TraceLine(5034,0,__PYX_ERR(0, 5034, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->faces[5])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":5035
 *                     #I am on the same level and easy to interpolate
 *                     ind = cell.faces[5].index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind
 */
        __Pyx_TraceLine(5035,0,__PYX_ERR(0, 5035, __pyx_L1_error))
        __pyx_t_17 = ((__pyx_v_next_cell->location[2]) - ((__pyx_v_cell->faces[5])->location[2]));

        /* "discretize/_extensions/tree_ext.pyx":5036
 *                     ind = cell.faces[5].index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 */
        __Pyx_TraceLine(5036,0,__PYX_ERR(0, 5036, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_next_cell->location[2]) - (__pyx_v_cell->location[2]));

        /* "discretize/_extensions/tree_ext.pyx":5035
 *                     #I am on the same level and easy to interpolate
 *                     ind = cell.faces[5].index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind
 */
        __Pyx_TraceLine(5035,0,__PYX_ERR(0, 5035, __pyx_L1_error))
        if (unlikely(__pyx_t_18 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5035, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

        /* "discretize/_extensions/tree_ext.pyx":5037
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(5037,0,__PYX_ERR(0, 5037, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5037, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":5038
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(5038,0,__PYX_ERR(0, 5038, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5038, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind;

        /* "discretize/_extensions/tree_ext.pyx":5039
 *                     I[2*ind  ] = ind
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 */
        __Pyx_TraceLine(5039,0,__PYX_ERR(0, 5039, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5039, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5040
 *                     I[2*ind+1] = ind
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)
 */
        __Pyx_TraceLine(5040,0,__PYX_ERR(0, 5040, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5040, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5041
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)
 *                 else:
 */
        __Pyx_TraceLine(5041,0,__PYX_ERR(0, 5041, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5041, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = __pyx_v_w;

        /* "discretize/_extensions/tree_ext.pyx":5042
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w
 *                     V[2*ind+1] = (1.0-w)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # if next cell is a level larger than i am
 */
        __Pyx_TraceLine(5042,0,__PYX_ERR(0, 5042, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5042, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (1.0 - __pyx_v_w);

        /* "discretize/_extensions/tree_ext.pyx":5032
 * 
 *             if next_cell.is_leaf():
 *                 if next_cell.level == cell.level:             # <<<<<<<<<<<<<<
 *                     #I am on the same level and easy to interpolate
 *                     ind = cell.faces[5].index
 */
        goto __pyx_L10;
      }

      /* "discretize/_extensions/tree_ext.pyx":5045
 *                 else:
 *                     # if next cell is a level larger than i am
 *                     ind = cell.faces[5].index             # <<<<<<<<<<<<<<
 *                     ind_parent = cell.faces[5].parent.index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 */
      __Pyx_TraceLine(5045,0,__PYX_ERR(0, 5045, __pyx_L1_error))
      /*else*/ {
        __pyx_t_10 = (__pyx_v_cell->faces[5])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":5046
 *                     # if next cell is a level larger than i am
 *                     ind = cell.faces[5].index
 *                     ind_parent = cell.faces[5].parent.index             # <<<<<<<<<<<<<<
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])
 */
        __Pyx_TraceLine(5046,0,__PYX_ERR(0, 5046, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_cell->faces[5])->parent->index;
        __pyx_v_ind_parent = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":5047
 *                     ind = cell.faces[5].index
 *                     ind_parent = cell.faces[5].parent.index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind_parent
 */
        __Pyx_TraceLine(5047,0,__PYX_ERR(0, 5047, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_next_cell->location[2]) - ((__pyx_v_cell->faces[5])->location[2]));

        /* "discretize/_extensions/tree_ext.pyx":5048
 *                     ind_parent = cell.faces[5].parent.index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])             # <<<<<<<<<<<<<<
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 */
        __Pyx_TraceLine(5048,0,__PYX_ERR(0, 5048, __pyx_L1_error))
        __pyx_t_17 = ((__pyx_v_next_cell->location[2]) - (__pyx_v_cell->location[2]));

        /* "discretize/_extensions/tree_ext.pyx":5047
 *                     ind = cell.faces[5].index
 *                     ind_parent = cell.faces[5].parent.index
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind_parent
 */
        __Pyx_TraceLine(5047,0,__PYX_ERR(0, 5047, __pyx_L1_error))
        if (unlikely(__pyx_t_17 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5047, __pyx_L1_error)
        }
        __pyx_v_w = (__pyx_t_18 / __pyx_t_17);

        /* "discretize/_extensions/tree_ext.pyx":5049
 *                     w = (next_cell.location[2] - cell.faces[5].location[2])/(
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind_parent             # <<<<<<<<<<<<<<
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 */
        __Pyx_TraceLine(5049,0,__PYX_ERR(0, 5049, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5049, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":5050
 *                          next_cell.location[2] - cell.location[2])
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent             # <<<<<<<<<<<<<<
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 */
        __Pyx_TraceLine(5050,0,__PYX_ERR(0, 5050, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5050, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":5051
 *                     I[2*ind  ] = ind_parent
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 */
        __Pyx_TraceLine(5051,0,__PYX_ERR(0, 5051, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5051, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5052
 *                     I[2*ind+1] = ind_parent
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index             # <<<<<<<<<<<<<<
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 */
        __Pyx_TraceLine(5052,0,__PYX_ERR(0, 5052, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_next_cell->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5052, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5053
 *                     J[2*ind  ] = cell.index
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                     V[2*ind+1] = (1.0-w)/children_per_parent
 *             else:
 */
        __Pyx_TraceLine(5053,0,__PYX_ERR(0, 5053, __pyx_L1_error))
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5053, __pyx_L1_error)
        }
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5053, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

        /* "discretize/_extensions/tree_ext.pyx":5054
 *                     J[2*ind+1] = next_cell.index
 *                     V[2*ind  ] = w/children_per_parent
 *                     V[2*ind+1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 */
        __Pyx_TraceLine(5054,0,__PYX_ERR(0, 5054, __pyx_L1_error))
        __pyx_t_17 = (1.0 - __pyx_v_w);
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5054, __pyx_L1_error)
        }
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5054, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_17 / ((double)__pyx_v_children_per_parent));
      }
      __pyx_L10:;

      /* "discretize/_extensions/tree_ext.pyx":5031
 *                 V[2*ind  ] = 1.0
 * 
 *             if next_cell.is_leaf():             # <<<<<<<<<<<<<<
 *                 if next_cell.level == cell.level:
 *                     #I am on the same level and easy to interpolate
 */
      goto __pyx_L9;
    }

    /* "discretize/_extensions/tree_ext.pyx":5057
 *             else:
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 ind_parent = cell.faces[5].index             # <<<<<<<<<<<<<<
 *                 w = (next_cell.children[0].location[2] - cell.faces[5].location[2])/(
 *                      next_cell.children[0].location[2] - cell.location[2])
 */
    __Pyx_TraceLine(5057,0,__PYX_ERR(0, 5057, __pyx_L1_error))
    /*else*/ {
      __pyx_t_10 = (__pyx_v_cell->faces[5])->index;
      __pyx_v_ind_parent = __pyx_t_10;

      /* "discretize/_extensions/tree_ext.pyx":5058
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 ind_parent = cell.faces[5].index
 *                 w = (next_cell.children[0].location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                      next_cell.children[0].location[2] - cell.location[2])
 *                 for i in range(4): # four neighbors in +x direction
 */
      __Pyx_TraceLine(5058,0,__PYX_ERR(0, 5058, __pyx_L1_error))
      __pyx_t_17 = (((__pyx_v_next_cell->children[0])->location[2]) - ((__pyx_v_cell->faces[5])->location[2]));

      /* "discretize/_extensions/tree_ext.pyx":5059
 *                 ind_parent = cell.faces[5].index
 *                 w = (next_cell.children[0].location[2] - cell.faces[5].location[2])/(
 *                      next_cell.children[0].location[2] - cell.location[2])             # <<<<<<<<<<<<<<
 *                 for i in range(4): # four neighbors in +x direction
 *                     child = next_cell.children[i]
 */
      __Pyx_TraceLine(5059,0,__PYX_ERR(0, 5059, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_next_cell->children[0])->location[2]) - (__pyx_v_cell->location[2]));

      /* "discretize/_extensions/tree_ext.pyx":5058
 *                 #should mean next cell is not a leaf so need to loop over children
 *                 ind_parent = cell.faces[5].index
 *                 w = (next_cell.children[0].location[2] - cell.faces[5].location[2])/(             # <<<<<<<<<<<<<<
 *                      next_cell.children[0].location[2] - cell.location[2])
 *                 for i in range(4): # four neighbors in +x direction
 */
      __Pyx_TraceLine(5058,0,__PYX_ERR(0, 5058, __pyx_L1_error))
      if (unlikely(__pyx_t_18 == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 5058, __pyx_L1_error)
      }
      __pyx_v_w = (__pyx_t_17 / __pyx_t_18);

      /* "discretize/_extensions/tree_ext.pyx":5060
 *                 w = (next_cell.children[0].location[2] - cell.faces[5].location[2])/(
 *                      next_cell.children[0].location[2] - cell.location[2])
 *                 for i in range(4): # four neighbors in +x direction             # <<<<<<<<<<<<<<
 *                     child = next_cell.children[i]
 *                     ind = child.faces[4].index #0 1 2 3
 */
      __Pyx_TraceLine(5060,0,__PYX_ERR(0, 5060, __pyx_L1_error))
      for (__pyx_t_19 = 0; __pyx_t_19 < 4; __pyx_t_19+=1) {
        __pyx_v_i = __pyx_t_19;

        /* "discretize/_extensions/tree_ext.pyx":5061
 *                      next_cell.children[0].location[2] - cell.location[2])
 *                 for i in range(4): # four neighbors in +x direction
 *                     child = next_cell.children[i]             # <<<<<<<<<<<<<<
 *                     ind = child.faces[4].index #0 1 2 3
 *                     I[2*ind    ] = ind_parent
 */
        __Pyx_TraceLine(5061,0,__PYX_ERR(0, 5061, __pyx_L1_error))
        __pyx_v_child = (__pyx_v_next_cell->children[__pyx_v_i]);

        /* "discretize/_extensions/tree_ext.pyx":5062
 *                 for i in range(4): # four neighbors in +x direction
 *                     child = next_cell.children[i]
 *                     ind = child.faces[4].index #0 1 2 3             # <<<<<<<<<<<<<<
 *                     I[2*ind    ] = ind_parent
 *                     I[2*ind + 1] = ind_parent
 */
        __Pyx_TraceLine(5062,0,__PYX_ERR(0, 5062, __pyx_L1_error))
        __pyx_t_10 = (__pyx_v_child->faces[4])->index;
        __pyx_v_ind = __pyx_t_10;

        /* "discretize/_extensions/tree_ext.pyx":5063
 *                     child = next_cell.children[i]
 *                     ind = child.faces[4].index #0 1 2 3
 *                     I[2*ind    ] = ind_parent             # <<<<<<<<<<<<<<
 *                     I[2*ind + 1] = ind_parent
 *                     J[2*ind    ] = cell.index
 */
        __Pyx_TraceLine(5063,0,__PYX_ERR(0, 5063, __pyx_L1_error))
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5063, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":5064
 *                     ind = child.faces[4].index #0 1 2 3
 *                     I[2*ind    ] = ind_parent
 *                     I[2*ind + 1] = ind_parent             # <<<<<<<<<<<<<<
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = child.index
 */
        __Pyx_TraceLine(5064,0,__PYX_ERR(0, 5064, __pyx_L1_error))
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_I.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_I.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5064, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_I.data + __pyx_t_14 * __pyx_v_I.strides[0]) )) = __pyx_v_ind_parent;

        /* "discretize/_extensions/tree_ext.pyx":5065
 *                     I[2*ind    ] = ind_parent
 *                     I[2*ind + 1] = ind_parent
 *                     J[2*ind    ] = cell.index             # <<<<<<<<<<<<<<
 *                     J[2*ind + 1] = child.index
 *                     V[2*ind    ] = w/children_per_parent
 */
        __Pyx_TraceLine(5065,0,__PYX_ERR(0, 5065, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_cell->index;
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5065, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5066
 *                     I[2*ind + 1] = ind_parent
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = child.index             # <<<<<<<<<<<<<<
 *                     V[2*ind    ] = w/children_per_parent
 *                     V[2*ind + 1] = (1.0-w)/children_per_parent
 */
        __Pyx_TraceLine(5066,0,__PYX_ERR(0, 5066, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_child->index;
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_J.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_J.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5066, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_14 * __pyx_v_J.strides[0]) )) = __pyx_t_16;

        /* "discretize/_extensions/tree_ext.pyx":5067
 *                     J[2*ind    ] = cell.index
 *                     J[2*ind + 1] = child.index
 *                     V[2*ind    ] = w/children_per_parent             # <<<<<<<<<<<<<<
 *                     V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 */
        __Pyx_TraceLine(5067,0,__PYX_ERR(0, 5067, __pyx_L1_error))
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5067, __pyx_L1_error)
        }
        __pyx_t_14 = (2 * __pyx_v_ind);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5067, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_v_w / ((double)__pyx_v_children_per_parent));

        /* "discretize/_extensions/tree_ext.pyx":5068
 *                     J[2*ind + 1] = child.index
 *                     V[2*ind    ] = w/children_per_parent
 *                     V[2*ind + 1] = (1.0-w)/children_per_parent             # <<<<<<<<<<<<<<
 * 
 *         self._average_cell_to_face_z = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_z, self.n_cells))
 */
        __Pyx_TraceLine(5068,0,__PYX_ERR(0, 5068, __pyx_L1_error))
        __pyx_t_18 = (1.0 - __pyx_v_w);
        if (unlikely(__pyx_v_children_per_parent == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5068, __pyx_L1_error)
        }
        __pyx_t_14 = ((2 * __pyx_v_ind) + 1);
        __pyx_t_15 = -1;
        if (__pyx_t_14 < 0) {
          __pyx_t_14 += __pyx_v_V.shape[0];
          if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_14 >= __pyx_v_V.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 5068, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_14 * __pyx_v_V.strides[0]) )) = (__pyx_t_18 / ((double)__pyx_v_children_per_parent));
      }
    }
    __pyx_L9:;

    /* "discretize/_extensions/tree_ext.pyx":5015
 *         cdef double w
 * 
 *         for cell in self.tree.cells :             # <<<<<<<<<<<<<<
 *             next_cell = cell.neighbors[5]
 *             prev_cell = cell.neighbors[4]
 */
    __Pyx_TraceLine(5015,0,__PYX_ERR(0, 5015, __pyx_L1_error))
    __pyx_L5_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5070
 *                     V[2*ind + 1] = (1.0-w)/children_per_parent
 * 
 *         self._average_cell_to_face_z = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_z, self.n_cells))             # <<<<<<<<<<<<<<
 *         return self._average_cell_to_face_z
 * 
 */
  __Pyx_TraceLine(5070,0,__PYX_ERR(0, 5070, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_sp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
  __pyx_t_6 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __pyx_t_1 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_6);
  __pyx_t_1 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_shape, __pyx_t_20) < 0) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 5070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_20);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_20);
  __Pyx_GOTREF(__pyx_v_self->_average_cell_to_face_z);
  __Pyx_DECREF(__pyx_v_self->_average_cell_to_face_z);
  __pyx_v_self->_average_cell_to_face_z = __pyx_t_20;
  __pyx_t_20 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5071
 * 
 *         self._average_cell_to_face_z = sp.csr_matrix((V, (I,J)), shape=(self.n_faces_z, self.n_cells))
 *         return self._average_cell_to_face_z             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(5071,0,__PYX_ERR(0, 5071, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_average_cell_to_face_z);
  __pyx_r = __pyx_v_self->_average_cell_to_face_z;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":4987
 * 
 *     @property
 *     def average_cell_to_face_z(self):             # <<<<<<<<<<<<<<
 *         """Averaging operator from cell centers to z faces (scalar quantities).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.average_cell_to_face_z.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5074
 * 
 *     @property
 *     def project_face_to_boundary_face(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all faces to boundary faces.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_faces_x = NULL;
  PyObject *__pyx_v_faces_y = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_b = NULL;
  PyObject *__pyx_v_faces_z = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 5074, 0, __PYX_ERR(0, 5074, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5090
 *             (n_boundary_faces, n_faces) Projection matrix with shape
 *         """
 *         faces_x = self.faces_x             # <<<<<<<<<<<<<<
 *         faces_y = self.faces_y
 * 
 */
  __Pyx_TraceLine(5090,0,__PYX_ERR(0, 5090, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5090, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5091
 *         """
 *         faces_x = self.faces_x
 *         faces_y = self.faces_y             # <<<<<<<<<<<<<<
 * 
 *         x0, xF = self._xs[0], self._xs[-1]
 */
  __Pyx_TraceLine(5091,0,__PYX_ERR(0, 5091, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_faces_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5093
 *         faces_y = self.faces_y
 * 
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = np.r_[
 */
  __Pyx_TraceLine(5093,0,__PYX_ERR(0, 5093, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5093, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5093, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5093, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5093, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5094
 * 
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_b = np.r_[
 *             (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF),
 */
  __Pyx_TraceLine(5094,0,__PYX_ERR(0, 5094, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5094, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5094, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5094, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5094, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5095
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = np.r_[             # <<<<<<<<<<<<<<
 *             (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF),
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 */
  __Pyx_TraceLine(5095,0,__PYX_ERR(0, 5095, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5096
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = np.r_[
 *             (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF),             # <<<<<<<<<<<<<<
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 *         ]
 */
  __Pyx_TraceLine(5096,0,__PYX_ERR(0, 5096, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5096, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_faces_x, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5096, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5097
 *         is_b = np.r_[
 *             (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF),
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)             # <<<<<<<<<<<<<<
 *         ]
 *         if self.dim == 3:
 */
  __Pyx_TraceLine(5097,0,__PYX_ERR(0, 5097, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5097, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_faces_y, __pyx_tuple__22); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5097, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Or(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5095
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = np.r_[             # <<<<<<<<<<<<<<
 *             (faces_x[:, 0] == x0) | (faces_x[:, 0] == xF),
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 */
  __Pyx_TraceLine(5095,0,__PYX_ERR(0, 5095, __pyx_L1_error))
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __pyx_t_1 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5095, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_is_b = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5099
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 *         ]
 *         if self.dim == 3:             # <<<<<<<<<<<<<<
 *             faces_z = self.faces_z
 *             z0, zF = self._zs[0], self._zs[-1]
 */
  __Pyx_TraceLine(5099,0,__PYX_ERR(0, 5099, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 5099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5100
 *         ]
 *         if self.dim == 3:
 *             faces_z = self.faces_z             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b = np.r_[
 */
    __Pyx_TraceLine(5100,0,__PYX_ERR(0, 5100, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_faces_z); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5100, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_v_faces_z = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5101
 *         if self.dim == 3:
 *             faces_z = self.faces_z
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             is_b = np.r_[
 *                 is_b,
 */
    __Pyx_TraceLine(5101,0,__PYX_ERR(0, 5101, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5101, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5101, __pyx_L1_error)
    }
    __pyx_t_7 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5101, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5101, __pyx_L1_error)
    }
    __pyx_t_6 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_v_z0 = __pyx_t_7;
    __pyx_t_7 = 0;
    __pyx_v_zF = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5102
 *             faces_z = self.faces_z
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b = np.r_[             # <<<<<<<<<<<<<<
 *                 is_b,
 *                 (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 */
    __Pyx_TraceLine(5102,0,__PYX_ERR(0, 5102, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5102, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_r); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5102, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5104
 *             is_b = np.r_[
 *                 is_b,
 *                 (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             ]
 *         return sp.eye(self.n_faces, format='csr')[is_b]
 */
    __Pyx_TraceLine(5104,0,__PYX_ERR(0, 5104, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5104, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5104, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_faces_z, __pyx_tuple__23); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5104, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5104, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Or(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5104, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5102
 *             faces_z = self.faces_z
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b = np.r_[             # <<<<<<<<<<<<<<
 *                 is_b,
 *                 (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 */
    __Pyx_TraceLine(5102,0,__PYX_ERR(0, 5102, __pyx_L1_error))
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5102, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_is_b);
    __Pyx_GIVEREF(__pyx_v_is_b);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_is_b);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5102, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_b, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5099
 *             (faces_y[:, 1] == y0) | (faces_y[:, 1] == yF)
 *         ]
 *         if self.dim == 3:             # <<<<<<<<<<<<<<
 *             faces_z = self.faces_z
 *             z0, zF = self._zs[0], self._zs[-1]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5106
 *                 (faces_z[:, 2] == z0) | (faces_z[:, 2] == zF)
 *             ]
 *         return sp.eye(self.n_faces, format='csr')[is_b]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(5106,0,__PYX_ERR(0, 5106, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_eye); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_faces); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_format, __pyx_n_u_csr) < 0) __PYX_ERR(0, 5106, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_v_is_b); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5074
 * 
 *     @property
 *     def project_face_to_boundary_face(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all faces to boundary faces.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.project_face_to_boundary_face.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_faces_x);
  __Pyx_XDECREF(__pyx_v_faces_y);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_b);
  __Pyx_XDECREF(__pyx_v_faces_z);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5109
 * 
 *     @property
 *     def project_edge_to_boundary_edge(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all edges to boundary edges.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_edges_x = NULL;
  PyObject *__pyx_v_edges_y = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_bx = NULL;
  PyObject *__pyx_v_is_by = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_v_edges_z = NULL;
  PyObject *__pyx_v_is_bz = NULL;
  PyObject *__pyx_v_is_b = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 5109, 0, __PYX_ERR(0, 5109, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5125
 *             Projection matrix with shape
 *         """
 *         edges_x = self.edges_x             # <<<<<<<<<<<<<<
 *         edges_y = self.edges_y
 * 
 */
  __Pyx_TraceLine(5125,0,__PYX_ERR(0, 5125, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_edges_x = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5126
 *         """
 *         edges_x = self.edges_x
 *         edges_y = self.edges_y             # <<<<<<<<<<<<<<
 * 
 *         x0, xF = self._xs[0], self._xs[-1]
 */
  __Pyx_TraceLine(5126,0,__PYX_ERR(0, 5126, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_edges_y = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5128
 *         edges_y = self.edges_y
 * 
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 */
  __Pyx_TraceLine(5128,0,__PYX_ERR(0, 5128, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5128, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5128, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5128, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5128, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5129
 * 
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 */
  __Pyx_TraceLine(5129,0,__PYX_ERR(0, 5129, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5129, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5129, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5129, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5129, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5130
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)             # <<<<<<<<<<<<<<
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 *         if self.dim == 3:
 */
  __Pyx_TraceLine(5130,0,__PYX_ERR(0, 5130, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5130, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5130, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_is_bx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5131
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)             # <<<<<<<<<<<<<<
 *         if self.dim == 3:
 *             z0, zF = self._zs[0], self._zs[-1]
 */
  __Pyx_TraceLine(5131,0,__PYX_ERR(0, 5131, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5131, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5131, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_is_by = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5132
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 *         if self.dim == 3:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z
 */
  __Pyx_TraceLine(5132,0,__PYX_ERR(0, 5132, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 5132, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":5133
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 *         if self.dim == 3:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             edges_z = self.edges_z
 * 
 */
    __Pyx_TraceLine(5133,0,__PYX_ERR(0, 5133, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5133, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5133, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5133, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5133, __pyx_L1_error)
    }
    __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_z0 = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_v_zF = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5134
 *         if self.dim == 3:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z             # <<<<<<<<<<<<<<
 * 
 *             is_bx |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)
 */
    __Pyx_TraceLine(5134,0,__PYX_ERR(0, 5134, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_edges_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_edges_z = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5136
 *             edges_z = self.edges_z
 * 
 *             is_bx |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)             # <<<<<<<<<<<<<<
 *             is_by |= (edges_y[:, 2] == z0) | (edges_y[:, 2] == zF)
 * 
 */
    __Pyx_TraceLine(5136,0,__PYX_ERR(0, 5136, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__23); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_x, __pyx_tuple__23); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceOr(__pyx_v_is_bx, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_bx, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5137
 * 
 *             is_bx |= (edges_x[:, 2] == z0) | (edges_x[:, 2] == zF)
 *             is_by |= (edges_y[:, 2] == z0) | (edges_y[:, 2] == zF)             # <<<<<<<<<<<<<<
 * 
 *             is_bz = (
 */
    __Pyx_TraceLine(5137,0,__PYX_ERR(0, 5137, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_y, __pyx_tuple__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_InPlaceOr(__pyx_v_is_by, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5137, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_by, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5140
 * 
 *             is_bz = (
 *                 (edges_z[:, 0] == x0)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)
 */
    __Pyx_TraceLine(5140,0,__PYX_ERR(0, 5140, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5140, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5141
 *             is_bz = (
 *                 (edges_z[:, 0] == x0)
 *                 | (edges_z[:, 0] == xF)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 1] == y0)
 *                 | (edges_z[:, 1] == yF)
 */
    __Pyx_TraceLine(5141,0,__PYX_ERR(0, 5141, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5141, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5141, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5142
 *                 (edges_z[:, 0] == x0)
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)             # <<<<<<<<<<<<<<
 *                 | (edges_z[:, 1] == yF)
 *             )
 */
    __Pyx_TraceLine(5142,0,__PYX_ERR(0, 5142, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5142, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5143
 *                 | (edges_z[:, 0] == xF)
 *                 | (edges_z[:, 1] == y0)
 *                 | (edges_z[:, 1] == yF)             # <<<<<<<<<<<<<<
 *             )
 *             is_b = np.r_[is_bx, is_by, is_bz]
 */
    __Pyx_TraceLine(5143,0,__PYX_ERR(0, 5143, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_edges_z, __pyx_tuple__22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5143, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5143, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5143, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_is_bz = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5145
 *                 | (edges_z[:, 1] == yF)
 *             )
 *             is_b = np.r_[is_bx, is_by, is_bz]             # <<<<<<<<<<<<<<
 *         else:
 *             is_b = np.r_[is_bx, is_by]
 */
    __Pyx_TraceLine(5145,0,__PYX_ERR(0, 5145, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5145, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5145, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5145, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_is_bx);
    __Pyx_GIVEREF(__pyx_v_is_bx);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_is_bx);
    __Pyx_INCREF(__pyx_v_is_by);
    __Pyx_GIVEREF(__pyx_v_is_by);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_is_by);
    __Pyx_INCREF(__pyx_v_is_bz);
    __Pyx_GIVEREF(__pyx_v_is_bz);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_is_bz);
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5145, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_is_b = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5132
 *         is_bx = (edges_x[:, 1] == y0) | (edges_x[:, 1] == yF)
 *         is_by = (edges_y[:, 0] == x0) | (edges_y[:, 0] == xF)
 *         if self.dim == 3:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             edges_z = self.edges_z
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5147
 *             is_b = np.r_[is_bx, is_by, is_bz]
 *         else:
 *             is_b = np.r_[is_bx, is_by]             # <<<<<<<<<<<<<<
 *         return sp.eye(self.n_edges, format='csr')[is_b]
 * 
 */
  __Pyx_TraceLine(5147,0,__PYX_ERR(0, 5147, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5147, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5147, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5147, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_is_bx);
    __Pyx_GIVEREF(__pyx_v_is_bx);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_is_bx);
    __Pyx_INCREF(__pyx_v_is_by);
    __Pyx_GIVEREF(__pyx_v_is_by);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_is_by);
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5147, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_is_b = __pyx_t_4;
    __pyx_t_4 = 0;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":5148
 *         else:
 *             is_b = np.r_[is_bx, is_by]
 *         return sp.eye(self.n_edges, format='csr')[is_b]             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(5148,0,__PYX_ERR(0, 5148, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_eye); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_edges); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_format, __pyx_n_u_csr) < 0) __PYX_ERR(0, 5148, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_v_is_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5109
 * 
 *     @property
 *     def project_edge_to_boundary_edge(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all edges to boundary edges.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.project_edge_to_boundary_edge.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_edges_x);
  __Pyx_XDECREF(__pyx_v_edges_y);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_bx);
  __Pyx_XDECREF(__pyx_v_is_by);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XDECREF(__pyx_v_edges_z);
  __Pyx_XDECREF(__pyx_v_is_bz);
  __Pyx_XDECREF(__pyx_v_is_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5151
 * 
 *     @property
 *     def project_node_to_boundary_node(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all nodes to boundary nodes.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_x0 = NULL;
  PyObject *__pyx_v_xF = NULL;
  PyObject *__pyx_v_y0 = NULL;
  PyObject *__pyx_v_yF = NULL;
  PyObject *__pyx_v_is_b = NULL;
  PyObject *__pyx_v_z0 = NULL;
  PyObject *__pyx_v_zF = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 5151, 0, __PYX_ERR(0, 5151, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5167
 *             Projection matrix with shape
 *         """
 *         nodes = self.nodes             # <<<<<<<<<<<<<<
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]
 */
  __Pyx_TraceLine(5167,0,__PYX_ERR(0, 5167, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5168
 *         """
 *         nodes = self.nodes
 *         x0, xF = self._xs[0], self._xs[-1]             # <<<<<<<<<<<<<<
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = (
 */
  __Pyx_TraceLine(5168,0,__PYX_ERR(0, 5168, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5168, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5168, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5168, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_xs.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_xs.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5168, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_2 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_x0 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_xF = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5169
 *         nodes = self.nodes
 *         x0, xF = self._xs[0], self._xs[-1]
 *         y0, yF = self._ys[0], self._ys[-1]             # <<<<<<<<<<<<<<
 *         is_b = (
 *             (nodes[:, 0] == x0)
 */
  __Pyx_TraceLine(5169,0,__PYX_ERR(0, 5169, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5169, __pyx_L1_error)}
  __pyx_t_2 = 0;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5169, __pyx_L1_error)
  }
  __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5169, __pyx_L1_error)}
  __pyx_t_2 = -1L;
  __pyx_t_3 = -1;
  if (__pyx_t_2 < 0) {
    __pyx_t_2 += __pyx_v_self->_ys.shape[0];
    if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
  } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_ys.shape[0])) __pyx_t_3 = 0;
  if (unlikely(__pyx_t_3 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_3);
    __PYX_ERR(0, 5169, __pyx_L1_error)
  }
  __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_2 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_y0 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_yF = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5171
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_b = (
 *             (nodes[:, 0] == x0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)
 */
  __Pyx_TraceLine(5171,0,__PYX_ERR(0, 5171, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_v_x0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5171, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5172
 *         is_b = (
 *             (nodes[:, 0] == x0)
 *             | (nodes[:, 0] == xF)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 1] == y0)
 *             | (nodes[:, 1] == yF)
 */
  __Pyx_TraceLine(5172,0,__PYX_ERR(0, 5172, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_v_xF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5172, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5173
 *             (nodes[:, 0] == x0)
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 1] == yF)
 *         )
 */
  __Pyx_TraceLine(5173,0,__PYX_ERR(0, 5173, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__22); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_y0, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5173, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5174
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)
 *             | (nodes[:, 1] == yF)             # <<<<<<<<<<<<<<
 *         )
 *         if self.dim > 2:
 */
  __Pyx_TraceLine(5174,0,__PYX_ERR(0, 5174, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__22); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_yF, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5174, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_is_b = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5176
 *             | (nodes[:, 1] == yF)
 *         )
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b |= (nodes[:, 2] == z0) | (nodes[:, 2] == zF)
 */
  __Pyx_TraceLine(5176,0,__PYX_ERR(0, 5176, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5176, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 5176, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":5177
 *         )
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]             # <<<<<<<<<<<<<<
 *             is_b |= (nodes[:, 2] == z0) | (nodes[:, 2] == zF)
 *         return sp.eye(self.n_nodes, format='csr')[is_b]
 */
    __Pyx_TraceLine(5177,0,__PYX_ERR(0, 5177, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5177, __pyx_L1_error)}
    __pyx_t_2 = 0;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5177, __pyx_L1_error)
    }
    __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5177, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 5177, __pyx_L1_error)}
    __pyx_t_2 = -1L;
    __pyx_t_3 = -1;
    if (__pyx_t_2 < 0) {
      __pyx_t_2 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0;
    } else if (unlikely(__pyx_t_2 >= __pyx_v_self->_zs.shape[0])) __pyx_t_3 = 0;
    if (unlikely(__pyx_t_3 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_3);
      __PYX_ERR(0, 5177, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_2 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5177, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_z0 = __pyx_t_1;
    __pyx_t_1 = 0;
    __pyx_v_zF = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5178
 *         if self.dim > 2:
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b |= (nodes[:, 2] == z0) | (nodes[:, 2] == zF)             # <<<<<<<<<<<<<<
 *         return sp.eye(self.n_nodes, format='csr')[is_b]
 * 
 */
    __Pyx_TraceLine(5178,0,__PYX_ERR(0, 5178, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_z0, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_nodes, __pyx_tuple__23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_zF, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Or(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceOr(__pyx_v_is_b, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_is_b, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5176
 *             | (nodes[:, 1] == yF)
 *         )
 *         if self.dim > 2:             # <<<<<<<<<<<<<<
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b |= (nodes[:, 2] == z0) | (nodes[:, 2] == zF)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5179
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_b |= (nodes[:, 2] == z0) | (nodes[:, 2] == zF)
 *         return sp.eye(self.n_nodes, format='csr')[is_b]             # <<<<<<<<<<<<<<
 * 
 *     def _get_containing_cell_index(self, loc):
 */
  __Pyx_TraceLine(5179,0,__PYX_ERR(0, 5179, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_eye); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_format, __pyx_n_u_csr) < 0) __PYX_ERR(0, 5179, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_v_is_b); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5151
 * 
 *     @property
 *     def project_node_to_boundary_node(self):             # <<<<<<<<<<<<<<
 *         r"""Projection matrix from all nodes to boundary nodes.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.project_node_to_boundary_node.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_x0);
  __Pyx_XDECREF(__pyx_v_xF);
  __Pyx_XDECREF(__pyx_v_y0);
  __Pyx_XDECREF(__pyx_v_yF);
  __Pyx_XDECREF(__pyx_v_is_b);
  __Pyx_XDECREF(__pyx_v_z0);
  __Pyx_XDECREF(__pyx_v_zF);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5181
 *         return sp.eye(self.n_nodes, format='csr')[is_b]
 * 
 *     def _get_containing_cell_index(self, loc):             # <<<<<<<<<<<<<<
 *         cdef double x, y, z
 *         x = loc[0]
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_61_get_containing_cell_index(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_60_get_containing_cell_index[] = "_TreeMesh._get_containing_cell_index(self, loc)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_61_get_containing_cell_index(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_containing_cell_index (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_60_get_containing_cell_index(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_loc));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_60_get_containing_cell_index(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_loc) {
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  double __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_containing_cell_index", 0);
  __Pyx_TraceCall("_get_containing_cell_index", __pyx_f[0], 5181, 0, __PYX_ERR(0, 5181, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5183
 *     def _get_containing_cell_index(self, loc):
 *         cdef double x, y, z
 *         x = loc[0]             # <<<<<<<<<<<<<<
 *         y = loc[1]
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(5183,0,__PYX_ERR(0, 5183, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_loc, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5183, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5183, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_x = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5184
 *         cdef double x, y, z
 *         x = loc[0]
 *         y = loc[1]             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             z = loc[2]
 */
  __Pyx_TraceLine(5184,0,__PYX_ERR(0, 5184, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_loc, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5184, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_y = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5185
 *         x = loc[0]
 *         y = loc[1]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             z = loc[2]
 *         else:
 */
  __Pyx_TraceLine(5185,0,__PYX_ERR(0, 5185, __pyx_L1_error))
  __pyx_t_3 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_3) {

    /* "discretize/_extensions/tree_ext.pyx":5186
 *         y = loc[1]
 *         if self._dim == 3:
 *             z = loc[2]             # <<<<<<<<<<<<<<
 *         else:
 *             z = 0
 */
    __Pyx_TraceLine(5186,0,__PYX_ERR(0, 5186, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_loc, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5186, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_z = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5185
 *         x = loc[0]
 *         y = loc[1]
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             z = loc[2]
 *         else:
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5188
 *             z = loc[2]
 *         else:
 *             z = 0             # <<<<<<<<<<<<<<
 *         return self.tree.containing_cell(x, y, z).index
 * 
 */
  __Pyx_TraceLine(5188,0,__PYX_ERR(0, 5188, __pyx_L1_error))
  /*else*/ {
    __pyx_v_z = 0.0;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":5189
 *         else:
 *             z = 0
 *         return self.tree.containing_cell(x, y, z).index             # <<<<<<<<<<<<<<
 * 
 *     def _get_containing_cell_indexes(self, locs):
 */
  __Pyx_TraceLine(5189,0,__PYX_ERR(0, 5189, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z)->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5181
 *         return sp.eye(self.n_nodes, format='csr')[is_b]
 * 
 *     def _get_containing_cell_index(self, loc):             # <<<<<<<<<<<<<<
 *         cdef double x, y, z
 *         x = loc[0]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._get_containing_cell_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5191
 *         return self.tree.containing_cell(x, y, z).index
 * 
 *     def _get_containing_cell_indexes(self, locs):             # <<<<<<<<<<<<<<
 *         locs = np.require(np.atleast_2d(locs), dtype=np.float64, requirements='C')
 *         cdef double[:,:] d_locs = locs
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_63_get_containing_cell_indexes(PyObject *__pyx_v_self, PyObject *__pyx_v_locs); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_62_get_containing_cell_indexes[] = "_TreeMesh._get_containing_cell_indexes(self, locs)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_63_get_containing_cell_indexes(PyObject *__pyx_v_self, PyObject *__pyx_v_locs) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_containing_cell_indexes (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_62_get_containing_cell_indexes(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_locs));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_62_get_containing_cell_indexes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs) {
  __Pyx_memviewslice __pyx_v_d_locs = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_n_locs;
  __Pyx_memviewslice __pyx_v_indexes = { 0, 0, { 0 }, { 0 }, { 0 } };
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  int_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_8;
  int_t __pyx_t_9;
  int_t __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_containing_cell_indexes", 0);
  __Pyx_TraceCall("_get_containing_cell_indexes", __pyx_f[0], 5191, 0, __PYX_ERR(0, 5191, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_locs);

  /* "discretize/_extensions/tree_ext.pyx":5192
 * 
 *     def _get_containing_cell_indexes(self, locs):
 *         locs = np.require(np.atleast_2d(locs), dtype=np.float64, requirements='C')             # <<<<<<<<<<<<<<
 *         cdef double[:,:] d_locs = locs
 *         cdef int_t n_locs = d_locs.shape[0]
 */
  __Pyx_TraceLine(5192,0,__PYX_ERR(0, 5192, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_2d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_locs) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_locs);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 5192, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_locs, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5193
 *     def _get_containing_cell_indexes(self, locs):
 *         locs = np.require(np.atleast_2d(locs), dtype=np.float64, requirements='C')
 *         cdef double[:,:] d_locs = locs             # <<<<<<<<<<<<<<
 *         cdef int_t n_locs = d_locs.shape[0]
 *         cdef np.int64_t[:] indexes = np.empty(n_locs, dtype=np.int64)
 */
  __Pyx_TraceLine(5193,0,__PYX_ERR(0, 5193, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_locs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 5193, __pyx_L1_error)
  __pyx_v_d_locs = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5194
 *         locs = np.require(np.atleast_2d(locs), dtype=np.float64, requirements='C')
 *         cdef double[:,:] d_locs = locs
 *         cdef int_t n_locs = d_locs.shape[0]             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] indexes = np.empty(n_locs, dtype=np.int64)
 *         cdef double x, y, z
 */
  __Pyx_TraceLine(5194,0,__PYX_ERR(0, 5194, __pyx_L1_error))
  __pyx_v_n_locs = (__pyx_v_d_locs.shape[0]);

  /* "discretize/_extensions/tree_ext.pyx":5195
 *         cdef double[:,:] d_locs = locs
 *         cdef int_t n_locs = d_locs.shape[0]
 *         cdef np.int64_t[:] indexes = np.empty(n_locs, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef double x, y, z
 *         for i in range(n_locs):
 */
  __Pyx_TraceLine(5195,0,__PYX_ERR(0, 5195, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int_t(__pyx_v_n_locs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5195, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_indexes = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5197
 *         cdef np.int64_t[:] indexes = np.empty(n_locs, dtype=np.int64)
 *         cdef double x, y, z
 *         for i in range(n_locs):             # <<<<<<<<<<<<<<
 *             x = d_locs[i, 0]
 *             y = d_locs[i, 1]
 */
  __Pyx_TraceLine(5197,0,__PYX_ERR(0, 5197, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_n_locs;
  __pyx_t_9 = __pyx_t_8;
  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
    __pyx_v_i = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":5198
 *         cdef double x, y, z
 *         for i in range(n_locs):
 *             x = d_locs[i, 0]             # <<<<<<<<<<<<<<
 *             y = d_locs[i, 1]
 *             if self._dim == 3:
 */
    __Pyx_TraceLine(5198,0,__PYX_ERR(0, 5198, __pyx_L1_error))
    __pyx_t_11 = __pyx_v_i;
    __pyx_t_12 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_11 < 0) {
      __pyx_t_11 += __pyx_v_d_locs.shape[0];
      if (unlikely(__pyx_t_11 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_11 >= __pyx_v_d_locs.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_d_locs.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_d_locs.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 5198, __pyx_L1_error)
    }
    __pyx_v_x = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_d_locs.data + __pyx_t_11 * __pyx_v_d_locs.strides[0]) ) + __pyx_t_12 * __pyx_v_d_locs.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5199
 *         for i in range(n_locs):
 *             x = d_locs[i, 0]
 *             y = d_locs[i, 1]             # <<<<<<<<<<<<<<
 *             if self._dim == 3:
 *                 z = d_locs[i, 2]
 */
    __Pyx_TraceLine(5199,0,__PYX_ERR(0, 5199, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_i;
    __pyx_t_11 = 1;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_d_locs.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_d_locs.shape[0])) __pyx_t_13 = 0;
    if (__pyx_t_11 < 0) {
      __pyx_t_11 += __pyx_v_d_locs.shape[1];
      if (unlikely(__pyx_t_11 < 0)) __pyx_t_13 = 1;
    } else if (unlikely(__pyx_t_11 >= __pyx_v_d_locs.shape[1])) __pyx_t_13 = 1;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 5199, __pyx_L1_error)
    }
    __pyx_v_y = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_d_locs.data + __pyx_t_12 * __pyx_v_d_locs.strides[0]) ) + __pyx_t_11 * __pyx_v_d_locs.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5200
 *             x = d_locs[i, 0]
 *             y = d_locs[i, 1]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 z = d_locs[i, 2]
 *             else:
 */
    __Pyx_TraceLine(5200,0,__PYX_ERR(0, 5200, __pyx_L1_error))
    __pyx_t_14 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":5201
 *             y = d_locs[i, 1]
 *             if self._dim == 3:
 *                 z = d_locs[i, 2]             # <<<<<<<<<<<<<<
 *             else:
 *                 z = 0
 */
      __Pyx_TraceLine(5201,0,__PYX_ERR(0, 5201, __pyx_L1_error))
      __pyx_t_11 = __pyx_v_i;
      __pyx_t_12 = 2;
      __pyx_t_13 = -1;
      if (__pyx_t_11 < 0) {
        __pyx_t_11 += __pyx_v_d_locs.shape[0];
        if (unlikely(__pyx_t_11 < 0)) __pyx_t_13 = 0;
      } else if (unlikely(__pyx_t_11 >= __pyx_v_d_locs.shape[0])) __pyx_t_13 = 0;
      if (__pyx_t_12 < 0) {
        __pyx_t_12 += __pyx_v_d_locs.shape[1];
        if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1;
      } else if (unlikely(__pyx_t_12 >= __pyx_v_d_locs.shape[1])) __pyx_t_13 = 1;
      if (unlikely(__pyx_t_13 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_13);
        __PYX_ERR(0, 5201, __pyx_L1_error)
      }
      __pyx_v_z = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_d_locs.data + __pyx_t_11 * __pyx_v_d_locs.strides[0]) ) + __pyx_t_12 * __pyx_v_d_locs.strides[1]) )));

      /* "discretize/_extensions/tree_ext.pyx":5200
 *             x = d_locs[i, 0]
 *             y = d_locs[i, 1]
 *             if self._dim == 3:             # <<<<<<<<<<<<<<
 *                 z = d_locs[i, 2]
 *             else:
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":5203
 *                 z = d_locs[i, 2]
 *             else:
 *                 z = 0             # <<<<<<<<<<<<<<
 *             indexes[i] = self.tree.containing_cell(x, y, z).index
 *         if n_locs==1:
 */
    __Pyx_TraceLine(5203,0,__PYX_ERR(0, 5203, __pyx_L1_error))
    /*else*/ {
      __pyx_v_z = 0.0;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":5204
 *             else:
 *                 z = 0
 *             indexes[i] = self.tree.containing_cell(x, y, z).index             # <<<<<<<<<<<<<<
 *         if n_locs==1:
 *             return indexes[0]
 */
    __Pyx_TraceLine(5204,0,__PYX_ERR(0, 5204, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z)->index;
    __pyx_t_12 = __pyx_v_i;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_indexes.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_indexes.shape[0])) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 5204, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indexes.data + __pyx_t_12 * __pyx_v_indexes.strides[0]) )) = __pyx_t_15;
  }

  /* "discretize/_extensions/tree_ext.pyx":5205
 *                 z = 0
 *             indexes[i] = self.tree.containing_cell(x, y, z).index
 *         if n_locs==1:             # <<<<<<<<<<<<<<
 *             return indexes[0]
 *         return np.array(indexes)
 */
  __Pyx_TraceLine(5205,0,__PYX_ERR(0, 5205, __pyx_L1_error))
  __pyx_t_14 = ((__pyx_v_n_locs == 1) != 0);
  if (__pyx_t_14) {

    /* "discretize/_extensions/tree_ext.pyx":5206
 *             indexes[i] = self.tree.containing_cell(x, y, z).index
 *         if n_locs==1:
 *             return indexes[0]             # <<<<<<<<<<<<<<
 *         return np.array(indexes)
 * 
 */
    __Pyx_TraceLine(5206,0,__PYX_ERR(0, 5206, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_12 = 0;
    __pyx_t_13 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_indexes.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_indexes.shape[0])) __pyx_t_13 = 0;
    if (unlikely(__pyx_t_13 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_13);
      __PYX_ERR(0, 5206, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyInt_From_npy_int64((*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indexes.data + __pyx_t_12 * __pyx_v_indexes.strides[0]) )))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":5205
 *                 z = 0
 *             indexes[i] = self.tree.containing_cell(x, y, z).index
 *         if n_locs==1:             # <<<<<<<<<<<<<<
 *             return indexes[0]
 *         return np.array(indexes)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5207
 *         if n_locs==1:
 *             return indexes[0]
 *         return np.array(indexes)             # <<<<<<<<<<<<<<
 * 
 *     def _count_cells_per_index(self):
 */
  __Pyx_TraceLine(5207,0,__PYX_ERR(0, 5207, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_indexes, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5207, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5191
 *         return self.tree.containing_cell(x, y, z).index
 * 
 *     def _get_containing_cell_indexes(self, locs):             # <<<<<<<<<<<<<<
 *         locs = np.require(np.atleast_2d(locs), dtype=np.float64, requirements='C')
 *         cdef double[:,:] d_locs = locs
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._get_containing_cell_indexes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_d_locs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indexes, 1);
  __Pyx_XDECREF(__pyx_v_locs);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5209
 *         return np.array(indexes)
 * 
 *     def _count_cells_per_index(self):             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)
 *         for cell in self.tree.cells:
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_65_count_cells_per_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_64_count_cells_per_index[] = "_TreeMesh._count_cells_per_index(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_65_count_cells_per_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_count_cells_per_index (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_64_count_cells_per_index(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_64_count_cells_per_index(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_counts = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_7;
  std::vector<Cell *>  *__pyx_t_8;
  Cell *__pyx_t_9;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_count_cells_per_index", 0);
  __Pyx_TraceCall("_count_cells_per_index", __pyx_f[0], 5209, 0, __PYX_ERR(0, 5209, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5210
 * 
 *     def _count_cells_per_index(self):
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             counts[cell.level] += 1
 */
  __Pyx_TraceLine(5210,0,__PYX_ERR(0, 5210, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_max_level); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 5210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_counts = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5211
 *     def _count_cells_per_index(self):
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             counts[cell.level] += 1
 *         return np.array(counts)
 */
  __Pyx_TraceLine(5211,0,__PYX_ERR(0, 5211, __pyx_L1_error))
  __pyx_t_8 = &__pyx_v_self->tree->cells;
  __pyx_t_7 = __pyx_t_8->begin();
  for (;;) {
    if (!(__pyx_t_7 != __pyx_t_8->end())) break;
    __pyx_t_9 = *__pyx_t_7;
    ++__pyx_t_7;
    __pyx_v_cell = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":5212
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)
 *         for cell in self.tree.cells:
 *             counts[cell.level] += 1             # <<<<<<<<<<<<<<
 *         return np.array(counts)
 * 
 */
    __Pyx_TraceLine(5212,0,__PYX_ERR(0, 5212, __pyx_L1_error))
    __pyx_t_10 = __pyx_v_cell->level;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_counts.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_counts.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5212, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_counts.data + __pyx_t_10 * __pyx_v_counts.strides[0]) )) += 1;

    /* "discretize/_extensions/tree_ext.pyx":5211
 *     def _count_cells_per_index(self):
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             counts[cell.level] += 1
 *         return np.array(counts)
 */
    __Pyx_TraceLine(5211,0,__PYX_ERR(0, 5211, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":5213
 *         for cell in self.tree.cells:
 *             counts[cell.level] += 1
 *         return np.array(counts)             # <<<<<<<<<<<<<<
 * 
 *     def _cell_levels_by_indexes(self, index):
 */
  __Pyx_TraceLine(5213,0,__PYX_ERR(0, 5213, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_counts, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5209
 *         return np.array(indexes)
 * 
 *     def _count_cells_per_index(self):             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] counts = np.zeros(self.max_level+1, dtype=np.int64)
 *         for cell in self.tree.cells:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._count_cells_per_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_counts, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5215
 *         return np.array(counts)
 * 
 *     def _cell_levels_by_indexes(self, index):             # <<<<<<<<<<<<<<
 *         index = np.require(np.atleast_1d(index), dtype=np.int64, requirements='C')
 *         cdef np.int64_t[:] inds = index
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_67_cell_levels_by_indexes(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_66_cell_levels_by_indexes[] = "_TreeMesh._cell_levels_by_indexes(self, index)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_67_cell_levels_by_indexes(PyObject *__pyx_v_self, PyObject *__pyx_v_index) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_cell_levels_by_indexes (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_66_cell_levels_by_indexes(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_index));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_66_cell_levels_by_indexes(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_index) {
  __Pyx_memviewslice __pyx_v_inds = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_n_cells;
  __Pyx_memviewslice __pyx_v_levels = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_7;
  int_t __pyx_t_8;
  int_t __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  int_t __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_cell_levels_by_indexes", 0);
  __Pyx_TraceCall("_cell_levels_by_indexes", __pyx_f[0], 5215, 0, __PYX_ERR(0, 5215, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_index);

  /* "discretize/_extensions/tree_ext.pyx":5216
 * 
 *     def _cell_levels_by_indexes(self, index):
 *         index = np.require(np.atleast_1d(index), dtype=np.int64, requirements='C')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] inds = index
 *         cdef int_t n_cells = inds.shape[0]
 */
  __Pyx_TraceLine(5216,0,__PYX_ERR(0, 5216, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_require); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_index) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_index);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_requirements, __pyx_n_u_C) < 0) __PYX_ERR(0, 5216, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5217
 *     def _cell_levels_by_indexes(self, index):
 *         index = np.require(np.atleast_1d(index), dtype=np.int64, requirements='C')
 *         cdef np.int64_t[:] inds = index             # <<<<<<<<<<<<<<
 *         cdef int_t n_cells = inds.shape[0]
 *         cdef np.int64_t[:] levels = np.empty(n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(5217,0,__PYX_ERR(0, 5217, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_v_index, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 5217, __pyx_L1_error)
  __pyx_v_inds = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5218
 *         index = np.require(np.atleast_1d(index), dtype=np.int64, requirements='C')
 *         cdef np.int64_t[:] inds = index
 *         cdef int_t n_cells = inds.shape[0]             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] levels = np.empty(n_cells, dtype=np.int64)
 *         for i in range(n_cells):
 */
  __Pyx_TraceLine(5218,0,__PYX_ERR(0, 5218, __pyx_L1_error))
  __pyx_v_n_cells = (__pyx_v_inds.shape[0]);

  /* "discretize/_extensions/tree_ext.pyx":5219
 *         cdef np.int64_t[:] inds = index
 *         cdef int_t n_cells = inds.shape[0]
 *         cdef np.int64_t[:] levels = np.empty(n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         for i in range(n_cells):
 *             levels[i] = self.tree.cells[inds[i]].level
 */
  __Pyx_TraceLine(5219,0,__PYX_ERR(0, 5219, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int_t(__pyx_v_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 5219, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_levels = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5220
 *         cdef int_t n_cells = inds.shape[0]
 *         cdef np.int64_t[:] levels = np.empty(n_cells, dtype=np.int64)
 *         for i in range(n_cells):             # <<<<<<<<<<<<<<
 *             levels[i] = self.tree.cells[inds[i]].level
 *         if n_cells == 1:
 */
  __Pyx_TraceLine(5220,0,__PYX_ERR(0, 5220, __pyx_L1_error))
  __pyx_t_7 = __pyx_v_n_cells;
  __pyx_t_8 = __pyx_t_7;
  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
    __pyx_v_i = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":5221
 *         cdef np.int64_t[:] levels = np.empty(n_cells, dtype=np.int64)
 *         for i in range(n_cells):
 *             levels[i] = self.tree.cells[inds[i]].level             # <<<<<<<<<<<<<<
 *         if n_cells == 1:
 *             return levels[0]
 */
    __Pyx_TraceLine(5221,0,__PYX_ERR(0, 5221, __pyx_L1_error))
    __pyx_t_10 = __pyx_v_i;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_inds.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_inds.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5221, __pyx_L1_error)
    }
    __pyx_t_12 = (__pyx_v_self->tree->cells[(*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_inds.data + __pyx_t_10 * __pyx_v_inds.strides[0]) )))])->level;
    __pyx_t_10 = __pyx_v_i;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_levels.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_levels.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5221, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_levels.data + __pyx_t_10 * __pyx_v_levels.strides[0]) )) = __pyx_t_12;
  }

  /* "discretize/_extensions/tree_ext.pyx":5222
 *         for i in range(n_cells):
 *             levels[i] = self.tree.cells[inds[i]].level
 *         if n_cells == 1:             # <<<<<<<<<<<<<<
 *             return levels[0]
 *         else:
 */
  __Pyx_TraceLine(5222,0,__PYX_ERR(0, 5222, __pyx_L1_error))
  __pyx_t_13 = ((__pyx_v_n_cells == 1) != 0);
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":5223
 *             levels[i] = self.tree.cells[inds[i]].level
 *         if n_cells == 1:
 *             return levels[0]             # <<<<<<<<<<<<<<
 *         else:
 *             return np.array(levels)
 */
    __Pyx_TraceLine(5223,0,__PYX_ERR(0, 5223, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_10 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_levels.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_levels.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5223, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyInt_From_npy_int64((*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_levels.data + __pyx_t_10 * __pyx_v_levels.strides[0]) )))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":5222
 *         for i in range(n_cells):
 *             levels[i] = self.tree.cells[inds[i]].level
 *         if n_cells == 1:             # <<<<<<<<<<<<<<
 *             return levels[0]
 *         else:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5225
 *             return levels[0]
 *         else:
 *             return np.array(levels)             # <<<<<<<<<<<<<<
 * 
 *     def _getFaceP(self, xFace, yFace, zFace):
 */
  __Pyx_TraceLine(5225,0,__PYX_ERR(0, 5225, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_levels, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "discretize/_extensions/tree_ext.pyx":5215
 *         return np.array(counts)
 * 
 *     def _cell_levels_by_indexes(self, index):             # <<<<<<<<<<<<<<
 *         index = np.require(np.atleast_1d(index), dtype=np.int64, requirements='C')
 *         cdef np.int64_t[:] inds = index
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._cell_levels_by_indexes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_inds, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_levels, 1);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5227
 *             return np.array(levels)
 * 
 *     def _getFaceP(self, xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, id
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_69_getFaceP(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_68_getFaceP[] = "_TreeMesh._getFaceP(self, xFace, yFace, zFace)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_69_getFaceP(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xFace = 0;
  PyObject *__pyx_v_yFace = 0;
  PyObject *__pyx_v_zFace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getFaceP (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xFace,&__pyx_n_s_yFace,&__pyx_n_s_zFace,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_xFace)) != 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_yFace)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getFaceP", 1, 3, 3, 1); __PYX_ERR(0, 5227, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zFace)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getFaceP", 1, 3, 3, 2); __PYX_ERR(0, 5227, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getFaceP") < 0)) __PYX_ERR(0, 5227, __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_xFace = values[0];
    __pyx_v_yFace = values[1];
    __pyx_v_zFace = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getFaceP", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5227, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFaceP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_68_getFaceP(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_xFace, __pyx_v_yFace, __pyx_v_zFace);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_68_getFaceP(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace, PyObject *__pyx_v_zFace) {
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J2 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J3 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_faces[3];
  __Pyx_memviewslice __pyx_v_offsets = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_P = NULL;
  PyObject *__pyx_v_Rf = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_8;
  int __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  __pyx_t_5numpy_int64_t __pyx_t_11;
  std::vector<Cell *> ::iterator __pyx_t_12;
  std::vector<Cell *>  *__pyx_t_13;
  Cell *__pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  __Pyx_memviewslice __pyx_t_17 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getFaceP", 0);
  __Pyx_TraceCall("_getFaceP", __pyx_f[0], 5227, 0, __PYX_ERR(0, 5227, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5228
 * 
 *     def _getFaceP(self, xFace, yFace, zFace):
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind, id
 * 
 */
  __Pyx_TraceLine(5228,0,__PYX_ERR(0, 5228, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":5234
 *         cdef np.float64_t[:] V
 * 
 *         J1 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim==3:
 */
  __Pyx_TraceLine(5234,0,__PYX_ERR(0, 5234, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J1 = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5235
 * 
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if dim==3:
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(5235,0,__PYX_ERR(0, 5235, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5235, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_J2 = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5236
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 * 
 */
  __Pyx_TraceLine(5236,0,__PYX_ERR(0, 5236, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5237
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim==3:
 *             J3 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 * 
 *         cdef int[3] faces
 */
    __Pyx_TraceLine(5237,0,__PYX_ERR(0, 5237, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5237, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_J3 = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5236
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5240
 * 
 *         cdef int[3] faces
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         faces[0] = (xFace == 'fXp')
 *         faces[1] = (yFace == 'fYp')
 */
  __Pyx_TraceLine(5240,0,__PYX_ERR(0, 5240, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5240, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_offsets = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5241
 *         cdef int[3] faces
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         faces[0] = (xFace == 'fXp')             # <<<<<<<<<<<<<<
 *         faces[1] = (yFace == 'fYp')
 *         if dim == 3:
 */
  __Pyx_TraceLine(5241,0,__PYX_ERR(0, 5241, __pyx_L1_error))
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_xFace, __pyx_n_u_fXp, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5241, __pyx_L1_error)
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5241, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  (__pyx_v_faces[0]) = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":5242
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         faces[0] = (xFace == 'fXp')
 *         faces[1] = (yFace == 'fYp')             # <<<<<<<<<<<<<<
 *         if dim == 3:
 *             faces[2] = (zFace == 'fZp')
 */
  __Pyx_TraceLine(5242,0,__PYX_ERR(0, 5242, __pyx_L1_error))
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_yFace, __pyx_n_u_fYp, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5242, __pyx_L1_error)
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5242, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  (__pyx_v_faces[1]) = __pyx_t_9;

  /* "discretize/_extensions/tree_ext.pyx":5243
 *         faces[0] = (xFace == 'fXp')
 *         faces[1] = (yFace == 'fYp')
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             faces[2] = (zFace == 'fZp')
 * 
 */
  __Pyx_TraceLine(5243,0,__PYX_ERR(0, 5243, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5244
 *         faces[1] = (yFace == 'fYp')
 *         if dim == 3:
 *             faces[2] = (zFace == 'fZp')             # <<<<<<<<<<<<<<
 * 
 *         if dim == 2:
 */
    __Pyx_TraceLine(5244,0,__PYX_ERR(0, 5244, __pyx_L1_error))
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_zFace, __pyx_n_u_fZp, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5244, __pyx_L1_error)
    __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5244, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    (__pyx_v_faces[2]) = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":5243
 *         faces[0] = (xFace == 'fXp')
 *         faces[1] = (yFace == 'fYp')
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             faces[2] = (zFace == 'fZp')
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5246
 *             faces[2] = (zFace == 'fZp')
 * 
 *         if dim == 2:             # <<<<<<<<<<<<<<
 *             offsets[0] = 0
 *             offsets[1] = self.n_total_faces_x
 */
  __Pyx_TraceLine(5246,0,__PYX_ERR(0, 5246, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 2) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5247
 * 
 *         if dim == 2:
 *             offsets[0] = 0             # <<<<<<<<<<<<<<
 *             offsets[1] = self.n_total_faces_x
 *         else:
 */
    __Pyx_TraceLine(5247,0,__PYX_ERR(0, 5247, __pyx_L1_error))
    __pyx_t_10 = 0;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 5247, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) )) = 0;

    /* "discretize/_extensions/tree_ext.pyx":5248
 *         if dim == 2:
 *             offsets[0] = 0
 *             offsets[1] = self.n_total_faces_x             # <<<<<<<<<<<<<<
 *         else:
 *             offsets[0] = 0
 */
    __Pyx_TraceLine(5248,0,__PYX_ERR(0, 5248, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5248, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_t_2); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5248, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = 1;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 5248, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5246
 *             faces[2] = (zFace == 'fZp')
 * 
 *         if dim == 2:             # <<<<<<<<<<<<<<
 *             offsets[0] = 0
 *             offsets[1] = self.n_total_faces_x
 */
    goto __pyx_L5;
  }

  /* "discretize/_extensions/tree_ext.pyx":5250
 *             offsets[1] = self.n_total_faces_x
 *         else:
 *             offsets[0] = 0             # <<<<<<<<<<<<<<
 *             offsets[1] = self.n_total_faces_x
 *             offsets[2] = self.n_total_faces_x + self.n_total_faces_y
 */
  __Pyx_TraceLine(5250,0,__PYX_ERR(0, 5250, __pyx_L1_error))
  /*else*/ {
    __pyx_t_10 = 0;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 5250, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) )) = 0;

    /* "discretize/_extensions/tree_ext.pyx":5251
 *         else:
 *             offsets[0] = 0
 *             offsets[1] = self.n_total_faces_x             # <<<<<<<<<<<<<<
 *             offsets[2] = self.n_total_faces_x + self.n_total_faces_y
 * 
 */
    __Pyx_TraceLine(5251,0,__PYX_ERR(0, 5251, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_t_2); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5251, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = 1;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 5251, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5252
 *             offsets[0] = 0
 *             offsets[1] = self.n_total_faces_x
 *             offsets[2] = self.n_total_faces_x + self.n_total_faces_y             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
    __Pyx_TraceLine(5252,0,__PYX_ERR(0, 5252, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_11 = __Pyx_PyInt_As_npy_int64(__pyx_t_4); if (unlikely((__pyx_t_11 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5252, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_10 = 2;
    __pyx_t_9 = -1;
    if (__pyx_t_10 < 0) {
      __pyx_t_10 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
    } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
    if (unlikely(__pyx_t_9 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_9);
      __PYX_ERR(0, 5252, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) )) = __pyx_t_11;
  }
  __pyx_L5:;

  /* "discretize/_extensions/tree_ext.pyx":5254
 *             offsets[2] = self.n_total_faces_x + self.n_total_faces_y
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             if dim==2:
 */
  __Pyx_TraceLine(5254,0,__PYX_ERR(0, 5254, __pyx_L1_error))
  __pyx_t_13 = &__pyx_v_self->tree->cells;
  __pyx_t_12 = __pyx_t_13->begin();
  for (;;) {
    if (!(__pyx_t_12 != __pyx_t_13->end())) break;
    __pyx_t_14 = *__pyx_t_12;
    ++__pyx_t_12;
    __pyx_v_cell = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":5255
 * 
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             if dim==2:
 *                 J1[ind] = cell.edges[2 + faces[0]].index
 */
    __Pyx_TraceLine(5255,0,__PYX_ERR(0, 5255, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":5256
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 J1[ind] = cell.edges[2 + faces[0]].index
 *                 J2[ind] = cell.edges[    faces[1]].index + offsets[1]
 */
    __Pyx_TraceLine(5256,0,__PYX_ERR(0, 5256, __pyx_L1_error))
    __pyx_t_8 = ((__pyx_v_dim == 2) != 0);
    if (__pyx_t_8) {

      /* "discretize/_extensions/tree_ext.pyx":5257
 *             ind = cell.index
 *             if dim==2:
 *                 J1[ind] = cell.edges[2 + faces[0]].index             # <<<<<<<<<<<<<<
 *                 J2[ind] = cell.edges[    faces[1]].index + offsets[1]
 *             else:
 */
      __Pyx_TraceLine(5257,0,__PYX_ERR(0, 5257, __pyx_L1_error))
      __pyx_t_1 = (__pyx_v_cell->edges[(2 + (__pyx_v_faces[0]))])->index;
      __pyx_t_10 = __pyx_v_ind;
      __pyx_t_9 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_J1.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_J1.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5257, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J1.data + __pyx_t_10 * __pyx_v_J1.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":5258
 *             if dim==2:
 *                 J1[ind] = cell.edges[2 + faces[0]].index
 *                 J2[ind] = cell.edges[    faces[1]].index + offsets[1]             # <<<<<<<<<<<<<<
 *             else:
 *                 J1[ind] = cell.faces[    faces[0]].index
 */
      __Pyx_TraceLine(5258,0,__PYX_ERR(0, 5258, __pyx_L1_error))
      __pyx_t_10 = 1;
      __pyx_t_9 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_offsets.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5258, __pyx_L1_error)
      }
      __pyx_t_16 = __pyx_v_ind;
      __pyx_t_9 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J2.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J2.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5258, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J2.data + __pyx_t_16 * __pyx_v_J2.strides[0]) )) = ((__pyx_v_cell->edges[(__pyx_v_faces[1])])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) ))));

      /* "discretize/_extensions/tree_ext.pyx":5256
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             if dim==2:             # <<<<<<<<<<<<<<
 *                 J1[ind] = cell.edges[2 + faces[0]].index
 *                 J2[ind] = cell.edges[    faces[1]].index + offsets[1]
 */
      goto __pyx_L8;
    }

    /* "discretize/_extensions/tree_ext.pyx":5260
 *                 J2[ind] = cell.edges[    faces[1]].index + offsets[1]
 *             else:
 *                 J1[ind] = cell.faces[    faces[0]].index             # <<<<<<<<<<<<<<
 *                 J2[ind] = cell.faces[2 + faces[1]].index + offsets[1]
 *                 J3[ind] = cell.faces[4 + faces[2]].index + offsets[2]
 */
    __Pyx_TraceLine(5260,0,__PYX_ERR(0, 5260, __pyx_L1_error))
    /*else*/ {
      __pyx_t_1 = (__pyx_v_cell->faces[(__pyx_v_faces[0])])->index;
      __pyx_t_10 = __pyx_v_ind;
      __pyx_t_9 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_J1.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_J1.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5260, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J1.data + __pyx_t_10 * __pyx_v_J1.strides[0]) )) = __pyx_t_1;

      /* "discretize/_extensions/tree_ext.pyx":5261
 *             else:
 *                 J1[ind] = cell.faces[    faces[0]].index
 *                 J2[ind] = cell.faces[2 + faces[1]].index + offsets[1]             # <<<<<<<<<<<<<<
 *                 J3[ind] = cell.faces[4 + faces[2]].index + offsets[2]
 * 
 */
      __Pyx_TraceLine(5261,0,__PYX_ERR(0, 5261, __pyx_L1_error))
      __pyx_t_10 = 1;
      __pyx_t_9 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_offsets.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5261, __pyx_L1_error)
      }
      __pyx_t_16 = __pyx_v_ind;
      __pyx_t_9 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J2.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J2.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5261, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J2.data + __pyx_t_16 * __pyx_v_J2.strides[0]) )) = ((__pyx_v_cell->faces[(2 + (__pyx_v_faces[1]))])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) ))));

      /* "discretize/_extensions/tree_ext.pyx":5262
 *                 J1[ind] = cell.faces[    faces[0]].index
 *                 J2[ind] = cell.faces[2 + faces[1]].index + offsets[1]
 *                 J3[ind] = cell.faces[4 + faces[2]].index + offsets[2]             # <<<<<<<<<<<<<<
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 */
      __Pyx_TraceLine(5262,0,__PYX_ERR(0, 5262, __pyx_L1_error))
      __pyx_t_10 = 2;
      __pyx_t_9 = -1;
      if (__pyx_t_10 < 0) {
        __pyx_t_10 += __pyx_v_offsets.shape[0];
        if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_10 >= __pyx_v_offsets.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5262, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_J3.memview)) { __Pyx_RaiseUnboundLocalError("J3"); __PYX_ERR(0, 5262, __pyx_L1_error) }
      __pyx_t_16 = __pyx_v_ind;
      __pyx_t_9 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_J3.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_9 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_J3.shape[0])) __pyx_t_9 = 0;
      if (unlikely(__pyx_t_9 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_9);
        __PYX_ERR(0, 5262, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J3.data + __pyx_t_16 * __pyx_v_J3.strides[0]) )) = ((__pyx_v_cell->faces[(4 + (__pyx_v_faces[2]))])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_10 * __pyx_v_offsets.strides[0]) ))));
    }
    __pyx_L8:;

    /* "discretize/_extensions/tree_ext.pyx":5254
 *             offsets[2] = self.n_total_faces_x + self.n_total_faces_y
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             if dim==2:
 */
    __Pyx_TraceLine(5254,0,__PYX_ERR(0, 5254, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":5264
 *                 J3[ind] = cell.faces[4 + faces[2]].index + offsets[2]
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if dim==2:
 *             J = np.r_[J1, J2]
 */
  __Pyx_TraceLine(5264,0,__PYX_ERR(0, 5264, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5264, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_I = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5265
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:             # <<<<<<<<<<<<<<
 *             J = np.r_[J1, J2]
 *         else:
 */
  __Pyx_TraceLine(5265,0,__PYX_ERR(0, 5265, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 2) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5266
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:
 *             J = np.r_[J1, J2]             # <<<<<<<<<<<<<<
 *         else:
 *             J = np.r_[J1, J2, J3]
 */
    __Pyx_TraceLine(5266,0,__PYX_ERR(0, 5266, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_J1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J2, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
    __pyx_t_6 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5266, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_J = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5265
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:             # <<<<<<<<<<<<<<
 *             J = np.r_[J1, J2]
 *         else:
 */
    goto __pyx_L9;
  }

  /* "discretize/_extensions/tree_ext.pyx":5268
 *             J = np.r_[J1, J2]
 *         else:
 *             J = np.r_[J1, J2, J3]             # <<<<<<<<<<<<<<
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5268,0,__PYX_ERR(0, 5268, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_r); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_J1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_J2, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(!__pyx_v_J3.memview)) { __Pyx_RaiseUnboundLocalError("J3"); __PYX_ERR(0, 5268, __pyx_L1_error) }
    __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_J3, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5268, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_J = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;
  }
  __pyx_L9:;

  /* "discretize/_extensions/tree_ext.pyx":5269
 *         else:
 *             J = np.r_[J1, J2, J3]
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_faces))
 */
  __Pyx_TraceLine(5269,0,__PYX_ERR(0, 5269, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ones); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 5269, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_V = __pyx_t_17;
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5271
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_faces))             # <<<<<<<<<<<<<<
 *         Rf = self._deflate_faces()
 *         return P*Rf
 */
  __Pyx_TraceLine(5271,0,__PYX_ERR(0, 5271, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_sp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6);
  __pyx_t_2 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_18 = PyNumber_Multiply(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_18);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __pyx_t_18 = 0;
  __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_shape, __pyx_t_2) < 0) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_P = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5272
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_faces))
 *         Rf = self._deflate_faces()             # <<<<<<<<<<<<<<
 *         return P*Rf
 * 
 */
  __Pyx_TraceLine(5272,0,__PYX_ERR(0, 5272, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5272, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5272, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_Rf = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5273
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_faces))
 *         Rf = self._deflate_faces()
 *         return P*Rf             # <<<<<<<<<<<<<<
 * 
 *     def _getFacePxx(self):
 */
  __Pyx_TraceLine(5273,0,__PYX_ERR(0, 5273, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyNumber_Multiply(__pyx_v_P, __pyx_v_Rf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5227
 *             return np.array(levels)
 * 
 *     def _getFaceP(self, xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, id
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFaceP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J1, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J2, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J3, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_offsets, 1);
  __Pyx_XDECREF(__pyx_v_P);
  __Pyx_XDECREF(__pyx_v_Rf);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5275
 *         return P*Rf
 * 
 *     def _getFacePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_71_getFacePxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_70_getFacePxx[] = "_TreeMesh._getFacePxx(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_71_getFacePxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getFacePxx (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_70_getFacePxx(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

/* "discretize/_extensions/tree_ext.pyx":5276
 * 
 *     def _getFacePxx(self):
 *         def Pxx(xFace, yFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, None)
 *         return Pxx
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_1Pxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_1Pxx = {"Pxx", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_1Pxx, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_1Pxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xFace = 0;
  PyObject *__pyx_v_yFace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("Pxx (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xFace,&__pyx_n_s_yFace,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_xFace)) != 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_yFace)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxx", 1, 2, 2, 1); __PYX_ERR(0, 5276, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "Pxx") < 0)) __PYX_ERR(0, 5276, __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_xFace = values[0];
    __pyx_v_yFace = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Pxx", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5276, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxx.Pxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_Pxx(__pyx_self, __pyx_v_xFace, __pyx_v_yFace);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_Pxx(PyObject *__pyx_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *__pyx_cur_scope;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("Pxx", 0);
  __pyx_outer_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_TraceCall("Pxx", __pyx_f[0], 5276, 0, __PYX_ERR(0, 5276, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5277
 *     def _getFacePxx(self):
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)             # <<<<<<<<<<<<<<
 *         return Pxx
 * 
 */
  __Pyx_TraceLine(5277,0,__PYX_ERR(0, 5277, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 5277, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_getFaceP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5277, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xFace, __pyx_v_yFace, Py_None};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5277, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xFace, __pyx_v_yFace, Py_None};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5277, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_xFace);
    __Pyx_GIVEREF(__pyx_v_xFace);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_xFace);
    __Pyx_INCREF(__pyx_v_yFace);
    __Pyx_GIVEREF(__pyx_v_yFace);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_yFace);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, Py_None);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5276
 * 
 *     def _getFacePxx(self):
 *         def Pxx(xFace, yFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, None)
 *         return Pxx
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxx.Pxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5275
 *         return P*Rf
 * 
 *     def _getFacePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)
 */

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_70_getFacePxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *__pyx_cur_scope;
  PyObject *__pyx_v_Pxx = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getFacePxx", 0);
  __pyx_cur_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 5275, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __Pyx_TraceCall("_getFacePxx", __pyx_f[0], 5275, 0, __PYX_ERR(0, 5275, __pyx_L1_error));
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);

  /* "discretize/_extensions/tree_ext.pyx":5276
 * 
 *     def _getFacePxx(self):
 *         def Pxx(xFace, yFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, None)
 *         return Pxx
 */
  __Pyx_TraceLine(5276,0,__PYX_ERR(0, 5276, __pyx_L1_error))
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getFacePxx_1Pxx, 0, __pyx_n_s_getFacePxx_locals_Pxx, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_Pxx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5278
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)
 *         return Pxx             # <<<<<<<<<<<<<<
 * 
 *     def _getFacePxxx(self):
 */
  __Pyx_TraceLine(5278,0,__PYX_ERR(0, 5278, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Pxx);
  __pyx_r = __pyx_v_Pxx;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5275
 *         return P*Rf
 * 
 *     def _getFacePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xFace, yFace):
 *             return self._getFaceP(xFace, yFace, None)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Pxx);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5280
 *         return Pxx
 * 
 *     def _getFacePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_73_getFacePxxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_72_getFacePxxx[] = "_TreeMesh._getFacePxxx(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_73_getFacePxxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getFacePxxx (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_72_getFacePxxx(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

/* "discretize/_extensions/tree_ext.pyx":5281
 * 
 *     def _getFacePxxx(self):
 *         def Pxxx(xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, zFace)
 *         return Pxxx
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_1Pxxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_1Pxxx = {"Pxxx", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_1Pxxx, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_1Pxxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xFace = 0;
  PyObject *__pyx_v_yFace = 0;
  PyObject *__pyx_v_zFace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("Pxxx (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xFace,&__pyx_n_s_yFace,&__pyx_n_s_zFace,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_xFace)) != 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_yFace)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, 1); __PYX_ERR(0, 5281, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zFace)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, 2); __PYX_ERR(0, 5281, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "Pxxx") < 0)) __PYX_ERR(0, 5281, __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_xFace = values[0];
    __pyx_v_yFace = values[1];
    __pyx_v_zFace = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5281, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxxx.Pxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_Pxxx(__pyx_self, __pyx_v_xFace, __pyx_v_yFace, __pyx_v_zFace);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_Pxxx(PyObject *__pyx_self, PyObject *__pyx_v_xFace, PyObject *__pyx_v_yFace, PyObject *__pyx_v_zFace) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *__pyx_cur_scope;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("Pxxx", 0);
  __pyx_outer_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_TraceCall("Pxxx", __pyx_f[0], 5281, 0, __PYX_ERR(0, 5281, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5282
 *     def _getFacePxxx(self):
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)             # <<<<<<<<<<<<<<
 *         return Pxxx
 * 
 */
  __Pyx_TraceLine(5282,0,__PYX_ERR(0, 5282, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 5282, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_getFaceP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xFace, __pyx_v_yFace, __pyx_v_zFace};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5282, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xFace, __pyx_v_yFace, __pyx_v_zFace};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5282, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_xFace);
    __Pyx_GIVEREF(__pyx_v_xFace);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_xFace);
    __Pyx_INCREF(__pyx_v_yFace);
    __Pyx_GIVEREF(__pyx_v_yFace);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_yFace);
    __Pyx_INCREF(__pyx_v_zFace);
    __Pyx_GIVEREF(__pyx_v_zFace);
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_zFace);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5281
 * 
 *     def _getFacePxxx(self):
 *         def Pxxx(xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, zFace)
 *         return Pxxx
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxxx.Pxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5280
 *         return Pxx
 * 
 *     def _getFacePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)
 */

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_72_getFacePxxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *__pyx_cur_scope;
  PyObject *__pyx_v_Pxxx = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getFacePxxx", 0);
  __pyx_cur_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 5280, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __Pyx_TraceCall("_getFacePxxx", __pyx_f[0], 5280, 0, __PYX_ERR(0, 5280, __pyx_L1_error));
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);

  /* "discretize/_extensions/tree_ext.pyx":5281
 * 
 *     def _getFacePxxx(self):
 *         def Pxxx(xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, zFace)
 *         return Pxxx
 */
  __Pyx_TraceLine(5281,0,__PYX_ERR(0, 5281, __pyx_L1_error))
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getFacePxxx_1Pxxx, 0, __pyx_n_s_getFacePxxx_locals_Pxxx, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_Pxxx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5283
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)
 *         return Pxxx             # <<<<<<<<<<<<<<
 * 
 *     def _getEdgeP(self, xEdge, yEdge, zEdge):
 */
  __Pyx_TraceLine(5283,0,__PYX_ERR(0, 5283, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Pxxx);
  __pyx_r = __pyx_v_Pxxx;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5280
 *         return Pxx
 * 
 *     def _getFacePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xFace, yFace, zFace):
 *             return self._getFaceP(xFace, yFace, zFace)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFacePxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Pxxx);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5285
 *         return Pxxx
 * 
 *     def _getEdgeP(self, xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, id
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_75_getEdgeP(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_74_getEdgeP[] = "_TreeMesh._getEdgeP(self, xEdge, yEdge, zEdge)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_75_getEdgeP(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xEdge = 0;
  PyObject *__pyx_v_yEdge = 0;
  PyObject *__pyx_v_zEdge = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getEdgeP (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xEdge,&__pyx_n_s_yEdge,&__pyx_n_s_zEdge,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_xEdge)) != 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_yEdge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getEdgeP", 1, 3, 3, 1); __PYX_ERR(0, 5285, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zEdge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getEdgeP", 1, 3, 3, 2); __PYX_ERR(0, 5285, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getEdgeP") < 0)) __PYX_ERR(0, 5285, __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_xEdge = values[0];
    __pyx_v_yEdge = values[1];
    __pyx_v_zEdge = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getEdgeP", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5285, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgeP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_74_getEdgeP(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_xEdge, __pyx_v_yEdge, __pyx_v_zEdge);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_74_getEdgeP(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge, PyObject *__pyx_v_zEdge) {
  int __pyx_v_dim;
  int_t __pyx_v_ind;
  int __pyx_v_epc;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J2 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J3 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_edges[3];
  __Pyx_memviewslice __pyx_v_offsets = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  PyObject *__pyx_v_P = NULL;
  PyObject *__pyx_v_Rf = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  __pyx_t_5numpy_int64_t __pyx_t_14;
  std::vector<Cell *> ::iterator __pyx_t_15;
  std::vector<Cell *>  *__pyx_t_16;
  Cell *__pyx_t_17;
  PY_LONG_LONG __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  __Pyx_memviewslice __pyx_t_20 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getEdgeP", 0);
  __Pyx_TraceCall("_getEdgeP", __pyx_f[0], 5285, 0, __PYX_ERR(0, 5285, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5286
 * 
 *     def _getEdgeP(self, xEdge, yEdge, zEdge):
 *         cdef int dim = self._dim             # <<<<<<<<<<<<<<
 *         cdef int_t ind, id
 *         cdef int epc = 1<<(dim-1) #edges per cell 2/4
 */
  __Pyx_TraceLine(5286,0,__PYX_ERR(0, 5286, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":5288
 *         cdef int dim = self._dim
 *         cdef int_t ind, id
 *         cdef int epc = 1<<(dim-1) #edges per cell 2/4             # <<<<<<<<<<<<<<
 * 
 *         cdef np.int64_t[:] I, J, J1, J2, J3
 */
  __Pyx_TraceLine(5288,0,__PYX_ERR(0, 5288, __pyx_L1_error))
  __pyx_v_epc = (1 << (__pyx_v_dim - 1));

  /* "discretize/_extensions/tree_ext.pyx":5293
 *         cdef np.float64_t[:] V
 * 
 *         J1 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim == 3:
 */
  __Pyx_TraceLine(5293,0,__PYX_ERR(0, 5293, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5293, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J1 = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5294
 * 
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if dim == 3:
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 */
  __Pyx_TraceLine(5294,0,__PYX_ERR(0, 5294, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5294, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_J2 = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5295
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 * 
 */
  __Pyx_TraceLine(5295,0,__PYX_ERR(0, 5295, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5296
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim == 3:
 *             J3 = np.empty(self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 * 
 *         cdef int[3] edges
 */
    __Pyx_TraceLine(5296,0,__PYX_ERR(0, 5296, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5296, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_J3 = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5295
 *         J1 = np.empty(self.n_cells, dtype=np.int64)
 *         J2 = np.empty(self.n_cells, dtype=np.int64)
 *         if dim == 3:             # <<<<<<<<<<<<<<
 *             J3 = np.empty(self.n_cells, dtype=np.int64)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5299
 * 
 *         cdef int[3] edges
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         try:
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 */
  __Pyx_TraceLine(5299,0,__PYX_ERR(0, 5299, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5299, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_offsets = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5300
 *         cdef int[3] edges
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         try:             # <<<<<<<<<<<<<<
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 */
  __Pyx_TraceLine(5300,0,__PYX_ERR(0, 5300, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
    __Pyx_XGOTREF(__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_11);
    /*try:*/ {

      /* "discretize/_extensions/tree_ext.pyx":5301
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         try:
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3             # <<<<<<<<<<<<<<
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 *             if dim == 3:
 */
      __Pyx_TraceLine(5301,0,__PYX_ERR(0, 5301, __pyx_L4_error))
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_xEdge, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5301, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5301, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5301, __pyx_L4_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      (__pyx_v_edges[0]) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":5302
 *         try:
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3             # <<<<<<<<<<<<<<
 *             if dim == 3:
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 */
      __Pyx_TraceLine(5302,0,__PYX_ERR(0, 5302, __pyx_L4_error))
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_yEdge, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5302, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5302, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5302, __pyx_L4_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      (__pyx_v_edges[1]) = __pyx_t_12;

      /* "discretize/_extensions/tree_ext.pyx":5303
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 *         except ValueError:
 */
      __Pyx_TraceLine(5303,0,__PYX_ERR(0, 5303, __pyx_L4_error))
      __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_8) {

        /* "discretize/_extensions/tree_ext.pyx":5304
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 *             if dim == 3:
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3             # <<<<<<<<<<<<<<
 *         except ValueError:
 *             raise Exception('Last character of edge string must be 0, 1, 2, or 3')
 */
        __Pyx_TraceLine(5304,0,__PYX_ERR(0, 5304, __pyx_L4_error))
        __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_zEdge, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5304, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5304, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5304, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        (__pyx_v_edges[2]) = __pyx_t_12;

        /* "discretize/_extensions/tree_ext.pyx":5303
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 *         except ValueError:
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":5300
 *         cdef int[3] edges
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         try:             # <<<<<<<<<<<<<<
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 */
    }
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    goto __pyx_L9_try_end;
    __pyx_L4_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);

    /* "discretize/_extensions/tree_ext.pyx":5305
 *             if dim == 3:
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             raise Exception('Last character of edge string must be 0, 1, 2, or 3')
 * 
 */
    __Pyx_TraceLine(5305,0,__PYX_ERR(0, 5305, __pyx_L6_except_error))
    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_12) {
      __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgeP", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_4) < 0) __PYX_ERR(0, 5305, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_4);

      /* "discretize/_extensions/tree_ext.pyx":5306
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 *         except ValueError:
 *             raise Exception('Last character of edge string must be 0, 1, 2, or 3')             # <<<<<<<<<<<<<<
 * 
 *         offsets[0] = 0
 */
      __Pyx_TraceLine(5306,0,__PYX_ERR(0, 5306, __pyx_L6_except_error))
      __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5306, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 5306, __pyx_L6_except_error)
    }
    goto __pyx_L6_except_error;
    __pyx_L6_except_error:;

    /* "discretize/_extensions/tree_ext.pyx":5300
 *         cdef int[3] edges
 *         cdef np.int64_t[:] offsets = np.empty(self._dim, dtype=np.int64)
 *         try:             # <<<<<<<<<<<<<<
 *             edges[0] = int(xEdge[-1]) #0, 1, 2, 3
 *             edges[1] = int(yEdge[-1]) #0, 1, 2, 3
 */
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
    goto __pyx_L1_error;
    __pyx_L9_try_end:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5308
 *             raise Exception('Last character of edge string must be 0, 1, 2, or 3')
 * 
 *         offsets[0] = 0             # <<<<<<<<<<<<<<
 *         offsets[1] = self.n_total_edges_x
 *         if dim==3:
 */
  __Pyx_TraceLine(5308,0,__PYX_ERR(0, 5308, __pyx_L1_error))
  __pyx_t_13 = 0;
  __pyx_t_12 = -1;
  if (__pyx_t_13 < 0) {
    __pyx_t_13 += __pyx_v_offsets.shape[0];
    if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 5308, __pyx_L1_error)
  }
  *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) )) = 0;

  /* "discretize/_extensions/tree_ext.pyx":5309
 * 
 *         offsets[0] = 0
 *         offsets[1] = self.n_total_edges_x             # <<<<<<<<<<<<<<
 *         if dim==3:
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y
 */
  __Pyx_TraceLine(5309,0,__PYX_ERR(0, 5309, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_14 = __Pyx_PyInt_As_npy_int64(__pyx_t_4); if (unlikely((__pyx_t_14 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5309, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_13 = 1;
  __pyx_t_12 = -1;
  if (__pyx_t_13 < 0) {
    __pyx_t_13 += __pyx_v_offsets.shape[0];
    if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
  } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
  if (unlikely(__pyx_t_12 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_12);
    __PYX_ERR(0, 5309, __pyx_L1_error)
  }
  *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) )) = __pyx_t_14;

  /* "discretize/_extensions/tree_ext.pyx":5310
 *         offsets[0] = 0
 *         offsets[1] = self.n_total_edges_x
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y
 * 
 */
  __Pyx_TraceLine(5310,0,__PYX_ERR(0, 5310, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5311
 *         offsets[1] = self.n_total_edges_x
 *         if dim==3:
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
    __Pyx_TraceLine(5311,0,__PYX_ERR(0, 5311, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_14 = __Pyx_PyInt_As_npy_int64(__pyx_t_3); if (unlikely((__pyx_t_14 == ((npy_int64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5311, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_13 = 2;
    __pyx_t_12 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5311, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) )) = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":5310
 *         offsets[0] = 0
 *         offsets[1] = self.n_total_edges_x
 *         if dim==3:             # <<<<<<<<<<<<<<
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":5313
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 */
  __Pyx_TraceLine(5313,0,__PYX_ERR(0, 5313, __pyx_L1_error))
  __pyx_t_16 = &__pyx_v_self->tree->cells;
  __pyx_t_15 = __pyx_t_16->begin();
  for (;;) {
    if (!(__pyx_t_15 != __pyx_t_16->end())) break;
    __pyx_t_17 = *__pyx_t_15;
    ++__pyx_t_15;
    __pyx_v_cell = __pyx_t_17;

    /* "discretize/_extensions/tree_ext.pyx":5314
 * 
 *         for cell in self.tree.cells:
 *             ind = cell.index             # <<<<<<<<<<<<<<
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]
 */
    __Pyx_TraceLine(5314,0,__PYX_ERR(0, 5314, __pyx_L1_error))
    __pyx_t_18 = __pyx_v_cell->index;
    __pyx_v_ind = __pyx_t_18;

    /* "discretize/_extensions/tree_ext.pyx":5315
 *         for cell in self.tree.cells:
 *             ind = cell.index
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]             # <<<<<<<<<<<<<<
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]
 *             if dim==3:
 */
    __Pyx_TraceLine(5315,0,__PYX_ERR(0, 5315, __pyx_L1_error))
    __pyx_t_13 = 0;
    __pyx_t_12 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5315, __pyx_L1_error)
    }
    __pyx_t_19 = __pyx_v_ind;
    __pyx_t_12 = -1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_J1.shape[0];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_J1.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5315, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J1.data + __pyx_t_19 * __pyx_v_J1.strides[0]) )) = ((__pyx_v_cell->edges[((0 * __pyx_v_epc) + (__pyx_v_edges[0]))])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) ))));

    /* "discretize/_extensions/tree_ext.pyx":5316
 *             ind = cell.index
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]             # <<<<<<<<<<<<<<
 *             if dim==3:
 *                 J3[ind] = cell.edges[2*epc + edges[2]].index + offsets[2]
 */
    __Pyx_TraceLine(5316,0,__PYX_ERR(0, 5316, __pyx_L1_error))
    __pyx_t_13 = 1;
    __pyx_t_12 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_offsets.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5316, __pyx_L1_error)
    }
    __pyx_t_19 = __pyx_v_ind;
    __pyx_t_12 = -1;
    if (__pyx_t_19 < 0) {
      __pyx_t_19 += __pyx_v_J2.shape[0];
      if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_19 >= __pyx_v_J2.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5316, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J2.data + __pyx_t_19 * __pyx_v_J2.strides[0]) )) = ((__pyx_v_cell->edges[((1 * __pyx_v_epc) + (__pyx_v_edges[1]))])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) ))));

    /* "discretize/_extensions/tree_ext.pyx":5317
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]
 *             if dim==3:             # <<<<<<<<<<<<<<
 *                 J3[ind] = cell.edges[2*epc + edges[2]].index + offsets[2]
 * 
 */
    __Pyx_TraceLine(5317,0,__PYX_ERR(0, 5317, __pyx_L1_error))
    __pyx_t_8 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_8) {

      /* "discretize/_extensions/tree_ext.pyx":5318
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]
 *             if dim==3:
 *                 J3[ind] = cell.edges[2*epc + edges[2]].index + offsets[2]             # <<<<<<<<<<<<<<
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 */
      __Pyx_TraceLine(5318,0,__PYX_ERR(0, 5318, __pyx_L1_error))
      __pyx_t_13 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_13 < 0) {
        __pyx_t_13 += __pyx_v_offsets.shape[0];
        if (unlikely(__pyx_t_13 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_13 >= __pyx_v_offsets.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5318, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_J3.memview)) { __Pyx_RaiseUnboundLocalError("J3"); __PYX_ERR(0, 5318, __pyx_L1_error) }
      __pyx_t_19 = __pyx_v_ind;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_J3.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_J3.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5318, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J3.data + __pyx_t_19 * __pyx_v_J3.strides[0]) )) = ((__pyx_v_cell->edges[((2 * __pyx_v_epc) + (__pyx_v_edges[2]))])->index + (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_offsets.data + __pyx_t_13 * __pyx_v_offsets.strides[0]) ))));

      /* "discretize/_extensions/tree_ext.pyx":5317
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 *             J2[ind] = cell.edges[1*epc + edges[1]].index + offsets[1]
 *             if dim==3:             # <<<<<<<<<<<<<<
 *                 J3[ind] = cell.edges[2*epc + edges[2]].index + offsets[2]
 * 
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":5313
 *             offsets[2] = self.n_total_edges_x + self.n_total_edges_y
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             ind = cell.index
 *             J1[ind] = cell.edges[0*epc + edges[0]].index + offsets[0]
 */
    __Pyx_TraceLine(5313,0,__PYX_ERR(0, 5313, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":5320
 *                 J3[ind] = cell.edges[2*epc + edges[2]].index + offsets[2]
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         if dim==2:
 *             J = np.r_[J1, J2]
 */
  __Pyx_TraceLine(5320,0,__PYX_ERR(0, 5320, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_arange); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5320, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_I = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5321
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:             # <<<<<<<<<<<<<<
 *             J = np.r_[J1, J2]
 *         else:
 */
  __Pyx_TraceLine(5321,0,__PYX_ERR(0, 5321, __pyx_L1_error))
  __pyx_t_8 = ((__pyx_v_dim == 2) != 0);
  if (__pyx_t_8) {

    /* "discretize/_extensions/tree_ext.pyx":5322
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:
 *             J = np.r_[J1, J2]             # <<<<<<<<<<<<<<
 *         else:
 *             J = np.r_[J1, J2, J3]
 */
    __Pyx_TraceLine(5322,0,__PYX_ERR(0, 5322, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_J1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_J2, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
    __pyx_t_6 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_J = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5321
 * 
 *         I = np.arange(dim*self.n_cells, dtype=np.int64)
 *         if dim==2:             # <<<<<<<<<<<<<<
 *             J = np.r_[J1, J2]
 *         else:
 */
    goto __pyx_L17;
  }

  /* "discretize/_extensions/tree_ext.pyx":5324
 *             J = np.r_[J1, J2]
 *         else:
 *             J = np.r_[J1, J2, J3]             # <<<<<<<<<<<<<<
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5324,0,__PYX_ERR(0, 5324, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_r); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_J1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_J2, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(!__pyx_v_J3.memview)) { __Pyx_RaiseUnboundLocalError("J3"); __PYX_ERR(0, 5324, __pyx_L1_error) }
    __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_J3, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_6);
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 5324, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_J = __pyx_t_7;
    __pyx_t_7.memview = NULL;
    __pyx_t_7.data = NULL;
  }
  __pyx_L17:;

  /* "discretize/_extensions/tree_ext.pyx":5325
 *         else:
 *             J = np.r_[J1, J2, J3]
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_edges))
 */
  __Pyx_TraceLine(5325,0,__PYX_ERR(0, 5325, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ones); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_20.memview)) __PYX_ERR(0, 5325, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_V = __pyx_t_20;
  __pyx_t_20.memview = NULL;
  __pyx_t_20.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5327
 *         V = np.ones(self.n_cells*dim, dtype=np.float64)
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_edges))             # <<<<<<<<<<<<<<
 *         Rf = self._deflate_edges()
 *         return P*Rf
 */
  __Pyx_TraceLine(5327,0,__PYX_ERR(0, 5327, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_sp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int_t(__pyx_v_self->_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_21 = PyNumber_Multiply(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_21);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_21);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_21);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __pyx_t_21 = 0;
  __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_shape, __pyx_t_4) < 0) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_P = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5328
 * 
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_edges))
 *         Rf = self._deflate_edges()             # <<<<<<<<<<<<<<
 *         return P*Rf
 * 
 */
  __Pyx_TraceLine(5328,0,__PYX_ERR(0, 5328, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5328, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5328, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_Rf = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5329
 *         P = sp.csr_matrix((V, (I, J)), shape=(self._dim*self.n_cells, self.n_total_edges))
 *         Rf = self._deflate_edges()
 *         return P*Rf             # <<<<<<<<<<<<<<
 * 
 *     def _getEdgePxx(self):
 */
  __Pyx_TraceLine(5329,0,__PYX_ERR(0, 5329, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyNumber_Multiply(__pyx_v_P, __pyx_v_Rf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5329, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5285
 *         return Pxxx
 * 
 *     def _getEdgeP(self, xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *         cdef int dim = self._dim
 *         cdef int_t ind, id
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgeP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J1, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J2, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J3, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_offsets, 1);
  __Pyx_XDECREF(__pyx_v_P);
  __Pyx_XDECREF(__pyx_v_Rf);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5331
 *         return P*Rf
 * 
 *     def _getEdgePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_77_getEdgePxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_76_getEdgePxx[] = "_TreeMesh._getEdgePxx(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_77_getEdgePxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getEdgePxx (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_76_getEdgePxx(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

/* "discretize/_extensions/tree_ext.pyx":5332
 * 
 *     def _getEdgePxx(self):
 *         def Pxx(xEdge, yEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, None)
 *         return Pxx
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_1Pxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_1Pxx = {"Pxx", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_1Pxx, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_1Pxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xEdge = 0;
  PyObject *__pyx_v_yEdge = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("Pxx (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xEdge,&__pyx_n_s_yEdge,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_xEdge)) != 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_yEdge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxx", 1, 2, 2, 1); __PYX_ERR(0, 5332, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "Pxx") < 0)) __PYX_ERR(0, 5332, __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_xEdge = values[0];
    __pyx_v_yEdge = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Pxx", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5332, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxx.Pxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_Pxx(__pyx_self, __pyx_v_xEdge, __pyx_v_yEdge);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_Pxx(PyObject *__pyx_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *__pyx_cur_scope;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("Pxx", 0);
  __pyx_outer_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_TraceCall("Pxx", __pyx_f[0], 5332, 0, __PYX_ERR(0, 5332, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5333
 *     def _getEdgePxx(self):
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)             # <<<<<<<<<<<<<<
 *         return Pxx
 * 
 */
  __Pyx_TraceLine(5333,0,__PYX_ERR(0, 5333, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 5333, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_getEdgeP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5333, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xEdge, __pyx_v_yEdge, Py_None};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5333, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xEdge, __pyx_v_yEdge, Py_None};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5333, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_xEdge);
    __Pyx_GIVEREF(__pyx_v_xEdge);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_xEdge);
    __Pyx_INCREF(__pyx_v_yEdge);
    __Pyx_GIVEREF(__pyx_v_yEdge);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_yEdge);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, Py_None);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5333, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5332
 * 
 *     def _getEdgePxx(self):
 *         def Pxx(xEdge, yEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, None)
 *         return Pxx
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxx.Pxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5331
 *         return P*Rf
 * 
 *     def _getEdgePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)
 */

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_76_getEdgePxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *__pyx_cur_scope;
  PyObject *__pyx_v_Pxx = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getEdgePxx", 0);
  __pyx_cur_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 5331, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __Pyx_TraceCall("_getEdgePxx", __pyx_f[0], 5331, 0, __PYX_ERR(0, 5331, __pyx_L1_error));
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);

  /* "discretize/_extensions/tree_ext.pyx":5332
 * 
 *     def _getEdgePxx(self):
 *         def Pxx(xEdge, yEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, None)
 *         return Pxx
 */
  __Pyx_TraceLine(5332,0,__PYX_ERR(0, 5332, __pyx_L1_error))
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_getEdgePxx_1Pxx, 0, __pyx_n_s_getEdgePxx_locals_Pxx, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_Pxx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5334
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)
 *         return Pxx             # <<<<<<<<<<<<<<
 * 
 *     def _getEdgePxxx(self):
 */
  __Pyx_TraceLine(5334,0,__PYX_ERR(0, 5334, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Pxx);
  __pyx_r = __pyx_v_Pxx;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5331
 *         return P*Rf
 * 
 *     def _getEdgePxx(self):             # <<<<<<<<<<<<<<
 *         def Pxx(xEdge, yEdge):
 *             return self._getEdgeP(xEdge, yEdge, None)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Pxx);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5336
 *         return Pxx
 * 
 *     def _getEdgePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_79_getEdgePxxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_78_getEdgePxxx[] = "_TreeMesh._getEdgePxxx(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_79_getEdgePxxx(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getEdgePxxx (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_78_getEdgePxxx(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

/* "discretize/_extensions/tree_ext.pyx":5337
 * 
 *     def _getEdgePxxx(self):
 *         def Pxxx(xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 *         return Pxxx
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_1Pxxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_1Pxxx = {"Pxxx", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_1Pxxx, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_1Pxxx(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xEdge = 0;
  PyObject *__pyx_v_yEdge = 0;
  PyObject *__pyx_v_zEdge = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("Pxxx (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xEdge,&__pyx_n_s_yEdge,&__pyx_n_s_zEdge,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_xEdge)) != 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_yEdge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, 1); __PYX_ERR(0, 5337, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zEdge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, 2); __PYX_ERR(0, 5337, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "Pxxx") < 0)) __PYX_ERR(0, 5337, __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_xEdge = values[0];
    __pyx_v_yEdge = values[1];
    __pyx_v_zEdge = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Pxxx", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5337, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxxx.Pxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_Pxxx(__pyx_self, __pyx_v_xEdge, __pyx_v_yEdge, __pyx_v_zEdge);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_Pxxx(PyObject *__pyx_self, PyObject *__pyx_v_xEdge, PyObject *__pyx_v_yEdge, PyObject *__pyx_v_zEdge) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *__pyx_cur_scope;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("Pxxx", 0);
  __pyx_outer_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_TraceCall("Pxxx", __pyx_f[0], 5337, 0, __PYX_ERR(0, 5337, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5338
 *     def _getEdgePxxx(self):
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)             # <<<<<<<<<<<<<<
 *         return Pxxx
 * 
 */
  __Pyx_TraceLine(5338,0,__PYX_ERR(0, 5338, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 5338, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_getEdgeP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xEdge, __pyx_v_yEdge, __pyx_v_zEdge};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5338, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_xEdge, __pyx_v_yEdge, __pyx_v_zEdge};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5338, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_xEdge);
    __Pyx_GIVEREF(__pyx_v_xEdge);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_xEdge);
    __Pyx_INCREF(__pyx_v_yEdge);
    __Pyx_GIVEREF(__pyx_v_yEdge);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_yEdge);
    __Pyx_INCREF(__pyx_v_zEdge);
    __Pyx_GIVEREF(__pyx_v_zEdge);
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_zEdge);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5337
 * 
 *     def _getEdgePxxx(self):
 *         def Pxxx(xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 *         return Pxxx
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxxx.Pxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5336
 *         return Pxx
 * 
 *     def _getEdgePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 */

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_78_getEdgePxxx(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *__pyx_cur_scope;
  PyObject *__pyx_v_Pxxx = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getEdgePxxx", 0);
  __pyx_cur_scope = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(__pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 5336, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __Pyx_TraceCall("_getEdgePxxx", __pyx_f[0], 5336, 0, __PYX_ERR(0, 5336, __pyx_L1_error));
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);

  /* "discretize/_extensions/tree_ext.pyx":5337
 * 
 *     def _getEdgePxxx(self):
 *         def Pxxx(xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 *         return Pxxx
 */
  __Pyx_TraceLine(5337,0,__PYX_ERR(0, 5337, __pyx_L1_error))
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_10discretize_11_extensions_8tree_ext_9_TreeMesh_12_getEdgePxxx_1Pxxx, 0, __pyx_n_s_getEdgePxxx_locals_Pxxx, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discretize__extensions_tree_ext_2, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_Pxxx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5339
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 *         return Pxxx             # <<<<<<<<<<<<<<
 * 
 *     def _getEdgeIntMat(self, locs, zeros_outside, direction):
 */
  __Pyx_TraceLine(5339,0,__PYX_ERR(0, 5339, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_Pxxx);
  __pyx_r = __pyx_v_Pxxx;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5336
 *         return Pxx
 * 
 *     def _getEdgePxxx(self):             # <<<<<<<<<<<<<<
 *         def Pxxx(xEdge, yEdge, zEdge):
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgePxxx", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_Pxxx);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5341
 *         return Pxxx
 * 
 *     def _getEdgeIntMat(self, locs, zeros_outside, direction):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_81_getEdgeIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_80_getEdgeIntMat[] = "_TreeMesh._getEdgeIntMat(self, locs, zeros_outside, direction)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_81_getEdgeIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_locs = 0;
  PyObject *__pyx_v_zeros_outside = 0;
  PyObject *__pyx_v_direction = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getEdgeIntMat (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_locs,&__pyx_n_s_zeros_outside,&__pyx_n_s_direction,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_locs)) != 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_zeros_outside)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getEdgeIntMat", 1, 3, 3, 1); __PYX_ERR(0, 5341, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_direction)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getEdgeIntMat", 1, 3, 3, 2); __PYX_ERR(0, 5341, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getEdgeIntMat") < 0)) __PYX_ERR(0, 5341, __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_locs = values[0];
    __pyx_v_zeros_outside = values[1];
    __pyx_v_direction = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getEdgeIntMat", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5341, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgeIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_80_getEdgeIntMat(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_locs, __pyx_v_zeros_outside, __pyx_v_direction);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_80_getEdgeIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside, PyObject *__pyx_v_direction) {
  __Pyx_memviewslice __pyx_v_locations = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_dir;
  int_t __pyx_v_dir1;
  int_t __pyx_v_dir2;
  int_t __pyx_v_dim;
  int_t __pyx_v_n_loc;
  int_t __pyx_v_n_edges;
  __Pyx_memviewslice __pyx_v_indptr = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indices = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_data = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_row_inds = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_row_data = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_i;
  int_t __pyx_v_offset;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_i0;
  Cell *__pyx_v_i1;
  Edge *__pyx_v_i000;
  Edge *__pyx_v_i001;
  Edge *__pyx_v_i010;
  Edge *__pyx_v_i011;
  Edge *__pyx_v_i100;
  Edge *__pyx_v_i101;
  Edge *__pyx_v_i110;
  Edge *__pyx_v_i111;
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  double __pyx_v_w1;
  double __pyx_v_w2;
  double __pyx_v_w3;
  double __pyx_v_eps;
  int __pyx_v_zeros_out;
  PyObject *__pyx_v_Re = NULL;
  PyObject *__pyx_v_A = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  double __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int_t __pyx_t_14;
  int_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_t_18;
  double __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getEdgeIntMat", 0);
  __Pyx_TraceCall("_getEdgeIntMat", __pyx_f[0], 5341, 0, __PYX_ERR(0, 5341, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5343
 *     def _getEdgeIntMat(self, locs, zeros_outside, direction):
 *         cdef:
 *             double[:, :] locations = locs             # <<<<<<<<<<<<<<
 *             int_t dir, dir1, dir2
 *             int_t dim = self._dim
 */
  __Pyx_TraceLine(5343,0,__PYX_ERR(0, 5343, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_locs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 5343, __pyx_L1_error)
  __pyx_v_locations = __pyx_t_1;
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5345
 *             double[:, :] locations = locs
 *             int_t dir, dir1, dir2
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             int_t n_loc = locs.shape[0]
 *             int_t n_edges = 2 if self._dim == 2 else 4
 */
  __Pyx_TraceLine(5345,0,__PYX_ERR(0, 5345, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5346
 *             int_t dir, dir1, dir2
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]             # <<<<<<<<<<<<<<
 *             int_t n_edges = 2 if self._dim == 2 else 4
 *             np.int64_t[:] indptr = 2 * n_edges * np.arange(n_loc+1, dtype=np.int64)
 */
  __Pyx_TraceLine(5346,0,__PYX_ERR(0, 5346, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5346, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5346, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_4); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5346, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_n_loc = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5347
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]
 *             int_t n_edges = 2 if self._dim == 2 else 4             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indptr = 2 * n_edges * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc * 2 * n_edges, dtype=np.int64)
 */
  __Pyx_TraceLine(5347,0,__PYX_ERR(0, 5347, __pyx_L1_error))
  if (((__pyx_v_self->_dim == 2) != 0)) {
    __pyx_t_2 = 2;
  } else {
    __pyx_t_2 = 4;
  }
  __pyx_v_n_edges = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5348
 *             int_t n_loc = locs.shape[0]
 *             int_t n_edges = 2 if self._dim == 2 else 4
 *             np.int64_t[:] indptr = 2 * n_edges * np.arange(n_loc+1, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indices = np.empty(n_loc * 2 * n_edges, dtype=np.int64)
 *             np.float64_t[:] data = np.empty(n_loc * 2 * n_edges, dtype=np.float64)
 */
  __Pyx_TraceLine(5348,0,__PYX_ERR(0, 5348, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyInt_From_long((2 * __pyx_v_n_edges)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_arange); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_n_loc + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5348, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_indptr = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5349
 *             int_t n_edges = 2 if self._dim == 2 else 4
 *             np.int64_t[:] indptr = 2 * n_edges * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc * 2 * n_edges, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] data = np.empty(n_loc * 2 * n_edges, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5349,0,__PYX_ERR(0, 5349, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long(((__pyx_v_n_loc * 2) * __pyx_v_n_edges)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5349, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_indices = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5350
 *             np.int64_t[:] indptr = 2 * n_edges * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc * 2 * n_edges, dtype=np.int64)
 *             np.float64_t[:] data = np.empty(n_loc * 2 * n_edges, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             np.int64_t[:] row_inds
 */
  __Pyx_TraceLine(5350,0,__PYX_ERR(0, 5350, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_long(((__pyx_v_n_loc * 2) * __pyx_v_n_edges)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 5350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_data = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5361
 *             double x, y, z
 *             double w1, w2, w3
 *             double eps = 100*np.finfo(float).eps             # <<<<<<<<<<<<<<
 *             int zeros_out = zeros_outside
 * 
 */
  __Pyx_TraceLine(5361,0,__PYX_ERR(0, 5361, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_finfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, ((PyObject *)(&PyFloat_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyFloat_Type)));
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_eps); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_100, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5361, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_eps = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":5362
 *             double w1, w2, w3
 *             double eps = 100*np.finfo(float).eps
 *             int zeros_out = zeros_outside             # <<<<<<<<<<<<<<
 * 
 *         if direction == 'x':
 */
  __Pyx_TraceLine(5362,0,__PYX_ERR(0, 5362, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_v_zeros_outside); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5362, __pyx_L1_error)
  __pyx_v_zeros_out = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":5364
 *             int zeros_out = zeros_outside
 * 
 *         if direction == 'x':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 0, 1, 2
 *             offset = 0
 */
  __Pyx_TraceLine(5364,0,__PYX_ERR(0, 5364, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_x, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5364, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":5365
 * 
 *         if direction == 'x':
 *             dir, dir1, dir2 = 0, 1, 2             # <<<<<<<<<<<<<<
 *             offset = 0
 *         elif direction == 'y':
 */
    __Pyx_TraceLine(5365,0,__PYX_ERR(0, 5365, __pyx_L1_error))
    __pyx_t_2 = 0;
    __pyx_t_14 = 1;
    __pyx_t_15 = 2;
    __pyx_v_dir = __pyx_t_2;
    __pyx_v_dir1 = __pyx_t_14;
    __pyx_v_dir2 = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":5366
 *         if direction == 'x':
 *             dir, dir1, dir2 = 0, 1, 2
 *             offset = 0             # <<<<<<<<<<<<<<
 *         elif direction == 'y':
 *             dir, dir1, dir2 = 1, 0, 2
 */
    __Pyx_TraceLine(5366,0,__PYX_ERR(0, 5366, __pyx_L1_error))
    __pyx_v_offset = 0;

    /* "discretize/_extensions/tree_ext.pyx":5364
 *             int zeros_out = zeros_outside
 * 
 *         if direction == 'x':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 0, 1, 2
 *             offset = 0
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5367
 *             dir, dir1, dir2 = 0, 1, 2
 *             offset = 0
 *         elif direction == 'y':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 1, 0, 2
 *             offset = self.n_total_edges_x
 */
  __Pyx_TraceLine(5367,0,__PYX_ERR(0, 5367, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_y, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5367, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":5368
 *             offset = 0
 *         elif direction == 'y':
 *             dir, dir1, dir2 = 1, 0, 2             # <<<<<<<<<<<<<<
 *             offset = self.n_total_edges_x
 *         elif direction == 'z':
 */
    __Pyx_TraceLine(5368,0,__PYX_ERR(0, 5368, __pyx_L1_error))
    __pyx_t_15 = 1;
    __pyx_t_14 = 0;
    __pyx_t_2 = 2;
    __pyx_v_dir = __pyx_t_15;
    __pyx_v_dir1 = __pyx_t_14;
    __pyx_v_dir2 = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5369
 *         elif direction == 'y':
 *             dir, dir1, dir2 = 1, 0, 2
 *             offset = self.n_total_edges_x             # <<<<<<<<<<<<<<
 *         elif direction == 'z':
 *             dir, dir1, dir2 = 2, 0, 1
 */
    __Pyx_TraceLine(5369,0,__PYX_ERR(0, 5369, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5369, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_offset = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5367
 *             dir, dir1, dir2 = 0, 1, 2
 *             offset = 0
 *         elif direction == 'y':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 1, 0, 2
 *             offset = self.n_total_edges_x
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5370
 *             dir, dir1, dir2 = 1, 0, 2
 *             offset = self.n_total_edges_x
 *         elif direction == 'z':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 2, 0, 1
 *             offset = self.n_total_edges_x + self.n_total_edges_y
 */
  __Pyx_TraceLine(5370,0,__PYX_ERR(0, 5370, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_z, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5370, __pyx_L1_error)
  if (likely(__pyx_t_13)) {

    /* "discretize/_extensions/tree_ext.pyx":5371
 *             offset = self.n_total_edges_x
 *         elif direction == 'z':
 *             dir, dir1, dir2 = 2, 0, 1             # <<<<<<<<<<<<<<
 *             offset = self.n_total_edges_x + self.n_total_edges_y
 *         else:
 */
    __Pyx_TraceLine(5371,0,__PYX_ERR(0, 5371, __pyx_L1_error))
    __pyx_t_2 = 2;
    __pyx_t_14 = 0;
    __pyx_t_15 = 1;
    __pyx_v_dir = __pyx_t_2;
    __pyx_v_dir1 = __pyx_t_14;
    __pyx_v_dir2 = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":5372
 *         elif direction == 'z':
 *             dir, dir1, dir2 = 2, 0, 1
 *             offset = self.n_total_edges_x + self.n_total_edges_y             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('Invalid direction, must be x, y, or z')
 */
    __Pyx_TraceLine(5372,0,__PYX_ERR(0, 5372, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyNumber_Add(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5372, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_15 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5372, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_offset = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":5370
 *             dir, dir1, dir2 = 1, 0, 2
 *             offset = self.n_total_edges_x
 *         elif direction == 'z':             # <<<<<<<<<<<<<<
 *             dir, dir1, dir2 = 2, 0, 1
 *             offset = self.n_total_edges_x + self.n_total_edges_y
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5374
 *             offset = self.n_total_edges_x + self.n_total_edges_y
 *         else:
 *             raise ValueError('Invalid direction, must be x, y, or z')             # <<<<<<<<<<<<<<
 * 
 *         for i in range(n_loc):
 */
  __Pyx_TraceLine(5374,0,__PYX_ERR(0, 5374, __pyx_L1_error))
  /*else*/ {
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 5374, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":5376
 *             raise ValueError('Invalid direction, must be x, y, or z')
 * 
 *         for i in range(n_loc):             # <<<<<<<<<<<<<<
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 */
  __Pyx_TraceLine(5376,0,__PYX_ERR(0, 5376, __pyx_L1_error))
  __pyx_t_15 = __pyx_v_n_loc;
  __pyx_t_14 = __pyx_t_15;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_14; __pyx_t_2+=1) {
    __pyx_v_i = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5377
 * 
 *         for i in range(n_loc):
 *             x = locations[i, 0]             # <<<<<<<<<<<<<<
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0
 */
    __Pyx_TraceLine(5377,0,__PYX_ERR(0, 5377, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = 0;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5377, __pyx_L1_error)
    }
    __pyx_v_x = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5378
 *         for i in range(n_loc):
 *             x = locations[i, 0]
 *             y = locations[i, 1]             # <<<<<<<<<<<<<<
 *             z = locations[i, 2] if dim==3 else 0.0
 *             # get containing (or closest) cell
 */
    __Pyx_TraceLine(5378,0,__PYX_ERR(0, 5378, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_16 = 1;
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5378, __pyx_L1_error)
    }
    __pyx_v_y = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5379
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0             # <<<<<<<<<<<<<<
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 */
    __Pyx_TraceLine(5379,0,__PYX_ERR(0, 5379, __pyx_L1_error))
    if (((__pyx_v_dim == 3) != 0)) {
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_17 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5379, __pyx_L1_error)
      }
      __pyx_t_11 = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) )));
    } else {
      __pyx_t_11 = 0.0;
    }
    __pyx_v_z = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5381
 *             z = locations[i, 2] if dim==3 else 0.0
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)             # <<<<<<<<<<<<<<
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 */
    __Pyx_TraceLine(5381,0,__PYX_ERR(0, 5381, __pyx_L1_error))
    __pyx_v_cell = __pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z);

    /* "discretize/_extensions/tree_ext.pyx":5382
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i+1]]             # <<<<<<<<<<<<<<
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 */
    __Pyx_TraceLine(5382,0,__PYX_ERR(0, 5382, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5382, __pyx_L1_error)
    }
    __pyx_t_16 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5382, __pyx_L1_error)
    }
    __pyx_t_9.data = __pyx_v_indices.data;
    __pyx_t_9.memview = __pyx_v_indices.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_indices.shape[0], __pyx_v_indices.strides[0], __pyx_v_indices.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_17 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5382, __pyx_L1_error)
}

__PYX_XDEC_MEMVIEW(&__pyx_v_row_inds, 1);
    __pyx_v_row_inds = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5383
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]             # <<<<<<<<<<<<<<
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 */
    __Pyx_TraceLine(5383,0,__PYX_ERR(0, 5383, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5383, __pyx_L1_error)
    }
    __pyx_t_17 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5383, __pyx_L1_error)
    }
    __pyx_t_10.data = __pyx_v_data.data;
    __pyx_t_10.memview = __pyx_v_data.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_data.shape[0], __pyx_v_data.strides[0], __pyx_v_data.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_17 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5383, __pyx_L1_error)
}

__PYX_XDEC_MEMVIEW(&__pyx_v_row_data, 1);
    __pyx_v_row_data = __pyx_t_10;
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5384
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
    __Pyx_TraceLine(5384,0,__PYX_ERR(0, 5384, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_zeros_out != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":5385
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5385,0,__PYX_ERR(0, 5385, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_x < (((__pyx_v_cell->points[0])->location[0]) - __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5386
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 */
        __Pyx_TraceLine(5386,0,__PYX_ERR(0, 5386, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5387
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5387,0,__PYX_ERR(0, 5387, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5385
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5388
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5388,0,__PYX_ERR(0, 5388, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_x > (((__pyx_v_cell->points[3])->location[0]) + __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5389
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 */
        __Pyx_TraceLine(5389,0,__PYX_ERR(0, 5389, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5390
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5390,0,__PYX_ERR(0, 5390, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5388
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5391
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5391,0,__PYX_ERR(0, 5391, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_y < (((__pyx_v_cell->points[0])->location[1]) - __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5392
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 */
        __Pyx_TraceLine(5392,0,__PYX_ERR(0, 5392, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5393
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5393,0,__PYX_ERR(0, 5393, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5391
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5394
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5394,0,__PYX_ERR(0, 5394, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_y > (((__pyx_v_cell->points[3])->location[1]) + __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5395
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 */
        __Pyx_TraceLine(5395,0,__PYX_ERR(0, 5395, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5396
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5396,0,__PYX_ERR(0, 5396, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5394
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5397
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5397,0,__PYX_ERR(0, 5397, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z < (((__pyx_v_cell->points[0])->location[2]) - __pyx_v_eps)) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L8_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5398
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 */
        __Pyx_TraceLine(5398,0,__PYX_ERR(0, 5398, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5399
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5399,0,__PYX_ERR(0, 5399, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5397
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5400
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5400,0,__PYX_ERR(0, 5400, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L10_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z > (((__pyx_v_cell->points[7])->location[2]) + __pyx_v_eps)) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L10_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5401
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *             else:
 */
        __Pyx_TraceLine(5401,0,__PYX_ERR(0, 5401, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5402
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 # look + dir and - dir away
 */
        __Pyx_TraceLine(5402,0,__PYX_ERR(0, 5402, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5400
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":5384
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":5405
 *             else:
 *                 # look + dir and - dir away
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir] < cell.location[dir]
 *                     and cell.neighbors[2*dir] != NULL
 */
    __Pyx_TraceLine(5405,0,__PYX_ERR(0, 5405, __pyx_L1_error))
    /*else*/ {

      /* "discretize/_extensions/tree_ext.pyx":5406
 *                 # look + dir and - dir away
 *                 if (
 *                     locations[i, dir] < cell.location[dir]             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir] != NULL
 *                     and cell.neighbors[2*dir].is_leaf()
 */
      __Pyx_TraceLine(5406,0,__PYX_ERR(0, 5406, __pyx_L1_error))
      __pyx_t_17 = __pyx_v_i;
      __pyx_t_16 = __pyx_v_dir;
      __pyx_t_12 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5406, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L13_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5407
 *                 if (
 *                     locations[i, dir] < cell.location[dir]
 *                     and cell.neighbors[2*dir] != NULL             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir].is_leaf()
 *                     and cell.neighbors[2*dir].level == cell.level
 */
      __Pyx_TraceLine(5407,0,__PYX_ERR(0, 5407, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L13_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5408
 *                     locations[i, dir] < cell.location[dir]
 *                     and cell.neighbors[2*dir] != NULL
 *                     and cell.neighbors[2*dir].is_leaf()             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir].level == cell.level
 *                 ):
 */
      __Pyx_TraceLine(5408,0,__PYX_ERR(0, 5408, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[(2 * __pyx_v_dir)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L13_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5409
 *                     and cell.neighbors[2*dir] != NULL
 *                     and cell.neighbors[2*dir].is_leaf()
 *                     and cell.neighbors[2*dir].level == cell.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i0 = cell.neighbors[2*dir]
 */
      __Pyx_TraceLine(5409,0,__PYX_ERR(0, 5409, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L13_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5405
 *             else:
 *                 # look + dir and - dir away
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir] < cell.location[dir]
 *                     and cell.neighbors[2*dir] != NULL
 */
      __Pyx_TraceLine(5405,0,__PYX_ERR(0, 5405, __pyx_L1_error))
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5411
 *                     and cell.neighbors[2*dir].level == cell.level
 *                 ):
 *                     i0 = cell.neighbors[2*dir]             # <<<<<<<<<<<<<<
 *                     i1 = cell
 *                 elif(
 */
        __Pyx_TraceLine(5411,0,__PYX_ERR(0, 5411, __pyx_L1_error))
        __pyx_v_i0 = (__pyx_v_cell->neighbors[(2 * __pyx_v_dir)]);

        /* "discretize/_extensions/tree_ext.pyx":5412
 *                 ):
 *                     i0 = cell.neighbors[2*dir]
 *                     i1 = cell             # <<<<<<<<<<<<<<
 *                 elif(
 *                     locations[i, dir] > cell.location[dir]
 */
        __Pyx_TraceLine(5412,0,__PYX_ERR(0, 5412, __pyx_L1_error))
        __pyx_v_i1 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5405
 *             else:
 *                 # look + dir and - dir away
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir] < cell.location[dir]
 *                     and cell.neighbors[2*dir] != NULL
 */
        goto __pyx_L12;
      }

      /* "discretize/_extensions/tree_ext.pyx":5414
 *                     i1 = cell
 *                 elif(
 *                     locations[i, dir] > cell.location[dir]             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir + 1] != NULL
 *                     and cell.neighbors[2*dir + 1].is_leaf()
 */
      __Pyx_TraceLine(5414,0,__PYX_ERR(0, 5414, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_17 = __pyx_v_dir;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5414, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L17_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5415
 *                 elif(
 *                     locations[i, dir] > cell.location[dir]
 *                     and cell.neighbors[2*dir + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir + 1].is_leaf()
 *                     and cell.neighbors[2*dir + 1].level == cell.level
 */
      __Pyx_TraceLine(5415,0,__PYX_ERR(0, 5415, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L17_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5416
 *                     locations[i, dir] > cell.location[dir]
 *                     and cell.neighbors[2*dir + 1] != NULL
 *                     and cell.neighbors[2*dir + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2*dir + 1].level == cell.level
 *                 ):
 */
      __Pyx_TraceLine(5416,0,__PYX_ERR(0, 5416, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[((2 * __pyx_v_dir) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L17_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5417
 *                     and cell.neighbors[2*dir + 1] != NULL
 *                     and cell.neighbors[2*dir + 1].is_leaf()
 *                     and cell.neighbors[2*dir + 1].level == cell.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i0 = cell
 */
      __Pyx_TraceLine(5417,0,__PYX_ERR(0, 5417, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir) + 1)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L17_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5413
 *                     i0 = cell.neighbors[2*dir]
 *                     i1 = cell
 *                 elif(             # <<<<<<<<<<<<<<
 *                     locations[i, dir] > cell.location[dir]
 *                     and cell.neighbors[2*dir + 1] != NULL
 */
      __Pyx_TraceLine(5413,0,__PYX_ERR(0, 5413, __pyx_L1_error))
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5419
 *                     and cell.neighbors[2*dir + 1].level == cell.level
 *                 ):
 *                     i0 = cell             # <<<<<<<<<<<<<<
 *                     i1 = cell.neighbors[2*dir + 1]
 *                 else:
 */
        __Pyx_TraceLine(5419,0,__PYX_ERR(0, 5419, __pyx_L1_error))
        __pyx_v_i0 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5420
 *                 ):
 *                     i0 = cell
 *                     i1 = cell.neighbors[2*dir + 1]             # <<<<<<<<<<<<<<
 *                 else:
 *                     i0 = cell
 */
        __Pyx_TraceLine(5420,0,__PYX_ERR(0, 5420, __pyx_L1_error))
        __pyx_v_i1 = (__pyx_v_cell->neighbors[((2 * __pyx_v_dir) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5413
 *                     i0 = cell.neighbors[2*dir]
 *                     i1 = cell
 *                 elif(             # <<<<<<<<<<<<<<
 *                     locations[i, dir] > cell.location[dir]
 *                     and cell.neighbors[2*dir + 1] != NULL
 */
        goto __pyx_L12;
      }

      /* "discretize/_extensions/tree_ext.pyx":5422
 *                     i1 = cell.neighbors[2*dir + 1]
 *                 else:
 *                     i0 = cell             # <<<<<<<<<<<<<<
 *                     i1 = cell
 * 
 */
      __Pyx_TraceLine(5422,0,__PYX_ERR(0, 5422, __pyx_L1_error))
      /*else*/ {
        __pyx_v_i0 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5423
 *                 else:
 *                     i0 = cell
 *                     i1 = cell             # <<<<<<<<<<<<<<
 * 
 *                 i000 = i0.edges[n_edges * dir]
 */
        __Pyx_TraceLine(5423,0,__PYX_ERR(0, 5423, __pyx_L1_error))
        __pyx_v_i1 = __pyx_v_cell;
      }
      __pyx_L12:;

      /* "discretize/_extensions/tree_ext.pyx":5425
 *                     i1 = cell
 * 
 *                 i000 = i0.edges[n_edges * dir]             # <<<<<<<<<<<<<<
 *                 i001 = i0.edges[n_edges * dir + 1]
 *                 w1 = ((i001.location[dir1] - locations[i, dir1])/
 */
      __Pyx_TraceLine(5425,0,__PYX_ERR(0, 5425, __pyx_L1_error))
      __pyx_v_i000 = (__pyx_v_i0->edges[(__pyx_v_n_edges * __pyx_v_dir)]);

      /* "discretize/_extensions/tree_ext.pyx":5426
 * 
 *                 i000 = i0.edges[n_edges * dir]
 *                 i001 = i0.edges[n_edges * dir + 1]             # <<<<<<<<<<<<<<
 *                 w1 = ((i001.location[dir1] - locations[i, dir1])/
 *                       (i001.location[dir1] - i000.location[dir1]))
 */
      __Pyx_TraceLine(5426,0,__PYX_ERR(0, 5426, __pyx_L1_error))
      __pyx_v_i001 = (__pyx_v_i0->edges[((__pyx_v_n_edges * __pyx_v_dir) + 1)]);

      /* "discretize/_extensions/tree_ext.pyx":5427
 *                 i000 = i0.edges[n_edges * dir]
 *                 i001 = i0.edges[n_edges * dir + 1]
 *                 w1 = ((i001.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                       (i001.location[dir1] - i000.location[dir1]))
 * 
 */
      __Pyx_TraceLine(5427,0,__PYX_ERR(0, 5427, __pyx_L1_error))
      __pyx_t_17 = __pyx_v_i;
      __pyx_t_16 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5427, __pyx_L1_error)
      }
      __pyx_t_11 = ((__pyx_v_i001->location[__pyx_v_dir1]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) ))));

      /* "discretize/_extensions/tree_ext.pyx":5428
 *                 i001 = i0.edges[n_edges * dir + 1]
 *                 w1 = ((i001.location[dir1] - locations[i, dir1])/
 *                       (i001.location[dir1] - i000.location[dir1]))             # <<<<<<<<<<<<<<
 * 
 *                 i010 = i1.edges[n_edges*dir]
 */
      __Pyx_TraceLine(5428,0,__PYX_ERR(0, 5428, __pyx_L1_error))
      __pyx_t_19 = ((__pyx_v_i001->location[__pyx_v_dir1]) - (__pyx_v_i000->location[__pyx_v_dir1]));

      /* "discretize/_extensions/tree_ext.pyx":5427
 *                 i000 = i0.edges[n_edges * dir]
 *                 i001 = i0.edges[n_edges * dir + 1]
 *                 w1 = ((i001.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                       (i001.location[dir1] - i000.location[dir1]))
 * 
 */
      __Pyx_TraceLine(5427,0,__PYX_ERR(0, 5427, __pyx_L1_error))
      if (unlikely(__pyx_t_19 == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 5427, __pyx_L1_error)
      }
      __pyx_v_w1 = (__pyx_t_11 / __pyx_t_19);

      /* "discretize/_extensions/tree_ext.pyx":5430
 *                       (i001.location[dir1] - i000.location[dir1]))
 * 
 *                 i010 = i1.edges[n_edges*dir]             # <<<<<<<<<<<<<<
 *                 i011 = i1.edges[n_edges*dir + 1]
 *                 if i0.index != i1.index:
 */
      __Pyx_TraceLine(5430,0,__PYX_ERR(0, 5430, __pyx_L1_error))
      __pyx_v_i010 = (__pyx_v_i1->edges[(__pyx_v_n_edges * __pyx_v_dir)]);

      /* "discretize/_extensions/tree_ext.pyx":5431
 * 
 *                 i010 = i1.edges[n_edges*dir]
 *                 i011 = i1.edges[n_edges*dir + 1]             # <<<<<<<<<<<<<<
 *                 if i0.index != i1.index:
 *                     w2 = ((i010.location[dir] - locations[i, dir])/
 */
      __Pyx_TraceLine(5431,0,__PYX_ERR(0, 5431, __pyx_L1_error))
      __pyx_v_i011 = (__pyx_v_i1->edges[((__pyx_v_n_edges * __pyx_v_dir) + 1)]);

      /* "discretize/_extensions/tree_ext.pyx":5432
 *                 i010 = i1.edges[n_edges*dir]
 *                 i011 = i1.edges[n_edges*dir + 1]
 *                 if i0.index != i1.index:             # <<<<<<<<<<<<<<
 *                     w2 = ((i010.location[dir] - locations[i, dir])/
 *                           (i010.location[dir] - i000.location[dir]))
 */
      __Pyx_TraceLine(5432,0,__PYX_ERR(0, 5432, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_i0->index != __pyx_v_i1->index) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5433
 *                 i011 = i1.edges[n_edges*dir + 1]
 *                 if i0.index != i1.index:
 *                     w2 = ((i010.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                           (i010.location[dir] - i000.location[dir]))
 *                 else:
 */
        __Pyx_TraceLine(5433,0,__PYX_ERR(0, 5433, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_i;
        __pyx_t_17 = __pyx_v_dir;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5433, __pyx_L1_error)
        }
        __pyx_t_19 = ((__pyx_v_i010->location[__pyx_v_dir]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5434
 *                 if i0.index != i1.index:
 *                     w2 = ((i010.location[dir] - locations[i, dir])/
 *                           (i010.location[dir] - i000.location[dir]))             # <<<<<<<<<<<<<<
 *                 else:
 *                     w2 = 1.0
 */
        __Pyx_TraceLine(5434,0,__PYX_ERR(0, 5434, __pyx_L1_error))
        __pyx_t_11 = ((__pyx_v_i010->location[__pyx_v_dir]) - (__pyx_v_i000->location[__pyx_v_dir]));

        /* "discretize/_extensions/tree_ext.pyx":5433
 *                 i011 = i1.edges[n_edges*dir + 1]
 *                 if i0.index != i1.index:
 *                     w2 = ((i010.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                           (i010.location[dir] - i000.location[dir]))
 *                 else:
 */
        __Pyx_TraceLine(5433,0,__PYX_ERR(0, 5433, __pyx_L1_error))
        if (unlikely(__pyx_t_11 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5433, __pyx_L1_error)
        }
        __pyx_v_w2 = (__pyx_t_19 / __pyx_t_11);

        /* "discretize/_extensions/tree_ext.pyx":5432
 *                 i010 = i1.edges[n_edges*dir]
 *                 i011 = i1.edges[n_edges*dir + 1]
 *                 if i0.index != i1.index:             # <<<<<<<<<<<<<<
 *                     w2 = ((i010.location[dir] - locations[i, dir])/
 *                           (i010.location[dir] - i000.location[dir]))
 */
        goto __pyx_L21;
      }

      /* "discretize/_extensions/tree_ext.pyx":5436
 *                           (i010.location[dir] - i000.location[dir]))
 *                 else:
 *                     w2 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                 if dim == 3:
 */
      __Pyx_TraceLine(5436,0,__PYX_ERR(0, 5436, __pyx_L1_error))
      /*else*/ {
        __pyx_v_w2 = 1.0;
      }
      __pyx_L21:;

      /* "discretize/_extensions/tree_ext.pyx":5438
 *                     w2 = 1.0
 * 
 *                 if dim == 3:             # <<<<<<<<<<<<<<
 *                     i100 = i0.edges[n_edges * dir + 2]
 *                     i101 = i0.edges[n_edges * dir + 3]
 */
      __Pyx_TraceLine(5438,0,__PYX_ERR(0, 5438, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5439
 * 
 *                 if dim == 3:
 *                     i100 = i0.edges[n_edges * dir + 2]             # <<<<<<<<<<<<<<
 *                     i101 = i0.edges[n_edges * dir + 3]
 *                     i110 = i1.edges[n_edges * dir + 2]
 */
        __Pyx_TraceLine(5439,0,__PYX_ERR(0, 5439, __pyx_L1_error))
        __pyx_v_i100 = (__pyx_v_i0->edges[((__pyx_v_n_edges * __pyx_v_dir) + 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5440
 *                 if dim == 3:
 *                     i100 = i0.edges[n_edges * dir + 2]
 *                     i101 = i0.edges[n_edges * dir + 3]             # <<<<<<<<<<<<<<
 *                     i110 = i1.edges[n_edges * dir + 2]
 *                     i111 = i1.edges[n_edges * dir + 3]
 */
        __Pyx_TraceLine(5440,0,__PYX_ERR(0, 5440, __pyx_L1_error))
        __pyx_v_i101 = (__pyx_v_i0->edges[((__pyx_v_n_edges * __pyx_v_dir) + 3)]);

        /* "discretize/_extensions/tree_ext.pyx":5441
 *                     i100 = i0.edges[n_edges * dir + 2]
 *                     i101 = i0.edges[n_edges * dir + 3]
 *                     i110 = i1.edges[n_edges * dir + 2]             # <<<<<<<<<<<<<<
 *                     i111 = i1.edges[n_edges * dir + 3]
 * 
 */
        __Pyx_TraceLine(5441,0,__PYX_ERR(0, 5441, __pyx_L1_error))
        __pyx_v_i110 = (__pyx_v_i1->edges[((__pyx_v_n_edges * __pyx_v_dir) + 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5442
 *                     i101 = i0.edges[n_edges * dir + 3]
 *                     i110 = i1.edges[n_edges * dir + 2]
 *                     i111 = i1.edges[n_edges * dir + 3]             # <<<<<<<<<<<<<<
 * 
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/
 */
        __Pyx_TraceLine(5442,0,__PYX_ERR(0, 5442, __pyx_L1_error))
        __pyx_v_i111 = (__pyx_v_i1->edges[((__pyx_v_n_edges * __pyx_v_dir) + 3)]);

        /* "discretize/_extensions/tree_ext.pyx":5444
 *                     i111 = i1.edges[n_edges * dir + 3]
 * 
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 */
        __Pyx_TraceLine(5444,0,__PYX_ERR(0, 5444, __pyx_L1_error))
        __pyx_t_17 = __pyx_v_i;
        __pyx_t_16 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5444, __pyx_L1_error)
        }
        __pyx_t_11 = ((__pyx_v_i100->location[__pyx_v_dir2]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5445
 * 
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/
 *                           (i100.location[dir2] - i000.location[dir2]))             # <<<<<<<<<<<<<<
 *                 else:
 *                     w3 = 1.0
 */
        __Pyx_TraceLine(5445,0,__PYX_ERR(0, 5445, __pyx_L1_error))
        __pyx_t_19 = ((__pyx_v_i100->location[__pyx_v_dir2]) - (__pyx_v_i000->location[__pyx_v_dir2]));

        /* "discretize/_extensions/tree_ext.pyx":5444
 *                     i111 = i1.edges[n_edges * dir + 3]
 * 
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 */
        __Pyx_TraceLine(5444,0,__PYX_ERR(0, 5444, __pyx_L1_error))
        if (unlikely(__pyx_t_19 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5444, __pyx_L1_error)
        }
        __pyx_v_w3 = (__pyx_t_11 / __pyx_t_19);

        /* "discretize/_extensions/tree_ext.pyx":5438
 *                     w2 = 1.0
 * 
 *                 if dim == 3:             # <<<<<<<<<<<<<<
 *                     i100 = i0.edges[n_edges * dir + 2]
 *                     i101 = i0.edges[n_edges * dir + 3]
 */
        goto __pyx_L22;
      }

      /* "discretize/_extensions/tree_ext.pyx":5447
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 *                     w3 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                 w1 = _clip01(w1)
 */
      __Pyx_TraceLine(5447,0,__PYX_ERR(0, 5447, __pyx_L1_error))
      /*else*/ {
        __pyx_v_w3 = 1.0;
      }
      __pyx_L22:;

      /* "discretize/_extensions/tree_ext.pyx":5449
 *                     w3 = 1.0
 * 
 *                 w1 = _clip01(w1)             # <<<<<<<<<<<<<<
 *                 w2 = _clip01(w2)
 *                 w3 = _clip01(w3)
 */
      __Pyx_TraceLine(5449,0,__PYX_ERR(0, 5449, __pyx_L1_error))
      __pyx_v_w1 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w1);

      /* "discretize/_extensions/tree_ext.pyx":5450
 * 
 *                 w1 = _clip01(w1)
 *                 w2 = _clip01(w2)             # <<<<<<<<<<<<<<
 *                 w3 = _clip01(w3)
 * 
 */
      __Pyx_TraceLine(5450,0,__PYX_ERR(0, 5450, __pyx_L1_error))
      __pyx_v_w2 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w2);

      /* "discretize/_extensions/tree_ext.pyx":5451
 *                 w1 = _clip01(w1)
 *                 w2 = _clip01(w2)
 *                 w3 = _clip01(w3)             # <<<<<<<<<<<<<<
 * 
 *                 row_data[0] = w1 * w2 * w3
 */
      __Pyx_TraceLine(5451,0,__PYX_ERR(0, 5451, __pyx_L1_error))
      __pyx_v_w3 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w3);

      /* "discretize/_extensions/tree_ext.pyx":5453
 *                 w3 = _clip01(w3)
 * 
 *                 row_data[0] = w1 * w2 * w3             # <<<<<<<<<<<<<<
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3
 */
      __Pyx_TraceLine(5453,0,__PYX_ERR(0, 5453, __pyx_L1_error))
      __pyx_t_16 = 0;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5453, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = ((__pyx_v_w1 * __pyx_v_w2) * __pyx_v_w3);

      /* "discretize/_extensions/tree_ext.pyx":5454
 * 
 *                 row_data[0] = w1 * w2 * w3
 *                 row_data[1] = (1 - w1) * w2 * w3             # <<<<<<<<<<<<<<
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 */
      __Pyx_TraceLine(5454,0,__PYX_ERR(0, 5454, __pyx_L1_error))
      __pyx_t_16 = 1;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5454, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = (((1.0 - __pyx_v_w1) * __pyx_v_w2) * __pyx_v_w3);

      /* "discretize/_extensions/tree_ext.pyx":5455
 *                 row_data[0] = w1 * w2 * w3
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index + offset
 */
      __Pyx_TraceLine(5455,0,__PYX_ERR(0, 5455, __pyx_L1_error))
      __pyx_t_16 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5455, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = ((__pyx_v_w1 * (1.0 - __pyx_v_w2)) * __pyx_v_w3);

      /* "discretize/_extensions/tree_ext.pyx":5456
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                 row_inds[0] = i000.index + offset
 *                 row_inds[1] = i001.index + offset
 */
      __Pyx_TraceLine(5456,0,__PYX_ERR(0, 5456, __pyx_L1_error))
      __pyx_t_16 = 3;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5456, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = (((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2)) * __pyx_v_w3);

      /* "discretize/_extensions/tree_ext.pyx":5457
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index + offset             # <<<<<<<<<<<<<<
 *                 row_inds[1] = i001.index + offset
 *                 row_inds[2] = i010.index + offset
 */
      __Pyx_TraceLine(5457,0,__PYX_ERR(0, 5457, __pyx_L1_error))
      __pyx_t_16 = 0;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5457, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i000->index + __pyx_v_offset);

      /* "discretize/_extensions/tree_ext.pyx":5458
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index + offset
 *                 row_inds[1] = i001.index + offset             # <<<<<<<<<<<<<<
 *                 row_inds[2] = i010.index + offset
 *                 row_inds[3] = i011.index + offset
 */
      __Pyx_TraceLine(5458,0,__PYX_ERR(0, 5458, __pyx_L1_error))
      __pyx_t_16 = 1;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5458, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i001->index + __pyx_v_offset);

      /* "discretize/_extensions/tree_ext.pyx":5459
 *                 row_inds[0] = i000.index + offset
 *                 row_inds[1] = i001.index + offset
 *                 row_inds[2] = i010.index + offset             # <<<<<<<<<<<<<<
 *                 row_inds[3] = i011.index + offset
 *                 if dim==3:
 */
      __Pyx_TraceLine(5459,0,__PYX_ERR(0, 5459, __pyx_L1_error))
      __pyx_t_16 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5459, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i010->index + __pyx_v_offset);

      /* "discretize/_extensions/tree_ext.pyx":5460
 *                 row_inds[1] = i001.index + offset
 *                 row_inds[2] = i010.index + offset
 *                 row_inds[3] = i011.index + offset             # <<<<<<<<<<<<<<
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)
 */
      __Pyx_TraceLine(5460,0,__PYX_ERR(0, 5460, __pyx_L1_error))
      __pyx_t_16 = 3;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5460, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i011->index + __pyx_v_offset);

      /* "discretize/_extensions/tree_ext.pyx":5461
 *                 row_inds[2] = i010.index + offset
 *                 row_inds[3] = i011.index + offset
 *                 if dim==3:             # <<<<<<<<<<<<<<
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 */
      __Pyx_TraceLine(5461,0,__PYX_ERR(0, 5461, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5462
 *                 row_inds[3] = i011.index + offset
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5462,0,__PYX_ERR(0, 5462, __pyx_L1_error))
        __pyx_t_16 = 4;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5462, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = ((__pyx_v_w1 * __pyx_v_w2) * (1.0 - __pyx_v_w3));

        /* "discretize/_extensions/tree_ext.pyx":5463
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5463,0,__PYX_ERR(0, 5463, __pyx_L1_error))
        __pyx_t_16 = 5;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5463, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = (((1.0 - __pyx_v_w1) * __pyx_v_w2) * (1.0 - __pyx_v_w3));

        /* "discretize/_extensions/tree_ext.pyx":5464
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index + offset
 */
        __Pyx_TraceLine(5464,0,__PYX_ERR(0, 5464, __pyx_L1_error))
        __pyx_t_16 = 6;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5464, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = ((__pyx_v_w1 * (1.0 - __pyx_v_w2)) * (1.0 - __pyx_v_w3));

        /* "discretize/_extensions/tree_ext.pyx":5465
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_inds[4] = i100.index + offset
 *                     row_inds[5] = i101.index + offset
 */
        __Pyx_TraceLine(5465,0,__PYX_ERR(0, 5465, __pyx_L1_error))
        __pyx_t_16 = 7;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5465, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_16 * __pyx_v_row_data.strides[0]) )) = (((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2)) * (1.0 - __pyx_v_w3));

        /* "discretize/_extensions/tree_ext.pyx":5466
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index + offset             # <<<<<<<<<<<<<<
 *                     row_inds[5] = i101.index + offset
 *                     row_inds[6] = i110.index + offset
 */
        __Pyx_TraceLine(5466,0,__PYX_ERR(0, 5466, __pyx_L1_error))
        __pyx_t_16 = 4;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5466, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i100->index + __pyx_v_offset);

        /* "discretize/_extensions/tree_ext.pyx":5467
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index + offset
 *                     row_inds[5] = i101.index + offset             # <<<<<<<<<<<<<<
 *                     row_inds[6] = i110.index + offset
 *                     row_inds[7] = i111.index + offset
 */
        __Pyx_TraceLine(5467,0,__PYX_ERR(0, 5467, __pyx_L1_error))
        __pyx_t_16 = 5;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5467, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i101->index + __pyx_v_offset);

        /* "discretize/_extensions/tree_ext.pyx":5468
 *                     row_inds[4] = i100.index + offset
 *                     row_inds[5] = i101.index + offset
 *                     row_inds[6] = i110.index + offset             # <<<<<<<<<<<<<<
 *                     row_inds[7] = i111.index + offset
 * 
 */
        __Pyx_TraceLine(5468,0,__PYX_ERR(0, 5468, __pyx_L1_error))
        __pyx_t_16 = 6;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5468, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i110->index + __pyx_v_offset);

        /* "discretize/_extensions/tree_ext.pyx":5469
 *                     row_inds[5] = i101.index + offset
 *                     row_inds[6] = i110.index + offset
 *                     row_inds[7] = i111.index + offset             # <<<<<<<<<<<<<<
 * 
 *         Re = self._deflate_edges()
 */
        __Pyx_TraceLine(5469,0,__PYX_ERR(0, 5469, __pyx_L1_error))
        __pyx_t_16 = 7;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5469, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_16 * __pyx_v_row_inds.strides[0]) )) = (__pyx_v_i111->index + __pyx_v_offset);

        /* "discretize/_extensions/tree_ext.pyx":5461
 *                 row_inds[2] = i010.index + offset
 *                 row_inds[3] = i011.index + offset
 *                 if dim==3:             # <<<<<<<<<<<<<<
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 */
      }
    }
    __pyx_L6:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5471
 *                     row_inds[7] = i111.index + offset
 * 
 *         Re = self._deflate_edges()             # <<<<<<<<<<<<<<
 *         A = sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_edges))
 *         return A*Re
 */
  __Pyx_TraceLine(5471,0,__PYX_ERR(0, 5471, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_edges); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5471, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5471, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_Re = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5472
 * 
 *         Re = self._deflate_edges()
 *         A = sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_edges))             # <<<<<<<<<<<<<<
 *         return A*Re
 * 
 */
  __Pyx_TraceLine(5472,0,__PYX_ERR(0, 5472, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_indices, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_indptr, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_3);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_A = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5473
 *         Re = self._deflate_edges()
 *         A = sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_edges))
 *         return A*Re             # <<<<<<<<<<<<<<
 * 
 *     def _getFaceIntMat(self, locs, zeros_outside, direction):
 */
  __Pyx_TraceLine(5473,0,__PYX_ERR(0, 5473, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = PyNumber_Multiply(__pyx_v_A, __pyx_v_Re); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5341
 *         return Pxxx
 * 
 *     def _getEdgeIntMat(self, locs, zeros_outside, direction):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getEdgeIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_locations, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indptr, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indices, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_data, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_row_inds, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_row_data, 1);
  __Pyx_XDECREF(__pyx_v_Re);
  __Pyx_XDECREF(__pyx_v_A);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5475
 *         return A*Re
 * 
 *     def _getFaceIntMat(self, locs, zeros_outside, direction):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_83_getFaceIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_82_getFaceIntMat[] = "_TreeMesh._getFaceIntMat(self, locs, zeros_outside, direction)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_83_getFaceIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_locs = 0;
  PyObject *__pyx_v_zeros_outside = 0;
  PyObject *__pyx_v_direction = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getFaceIntMat (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_locs,&__pyx_n_s_zeros_outside,&__pyx_n_s_direction,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_locs)) != 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_zeros_outside)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getFaceIntMat", 1, 3, 3, 1); __PYX_ERR(0, 5475, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_direction)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getFaceIntMat", 1, 3, 3, 2); __PYX_ERR(0, 5475, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getFaceIntMat") < 0)) __PYX_ERR(0, 5475, __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_locs = values[0];
    __pyx_v_zeros_outside = values[1];
    __pyx_v_direction = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getFaceIntMat", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5475, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFaceIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_82_getFaceIntMat(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_locs, __pyx_v_zeros_outside, __pyx_v_direction);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_82_getFaceIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside, PyObject *__pyx_v_direction) {
  __Pyx_memviewslice __pyx_v_locations = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_dir;
  int_t __pyx_v_dir1;
  int_t __pyx_v_dir2;
  int_t __pyx_v_temp;
  int_t __pyx_v_dim;
  int_t __pyx_v_n_loc;
  int_t __pyx_v_n_faces;
  __Pyx_memviewslice __pyx_v_indptr = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indices = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_data = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_i;
  int_t __pyx_v_offset;
  Cell *__pyx_v_cell;
  Cell *__pyx_v_i00;
  Cell *__pyx_v_i01;
  Cell *__pyx_v_i10;
  Cell *__pyx_v_i11;
  Face *__pyx_v_f000;
  Face *__pyx_v_f001;
  Face *__pyx_v_f010;
  Face *__pyx_v_f011;
  Face *__pyx_v_f100;
  Face *__pyx_v_f101;
  Face *__pyx_v_f110;
  Face *__pyx_v_f111;
  Edge *__pyx_v_e00;
  Edge *__pyx_v_e01;
  Edge *__pyx_v_e10;
  Edge *__pyx_v_e11;
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  double __pyx_v_w1;
  double __pyx_v_w2;
  double __pyx_v_w3;
  double __pyx_v_eps;
  int __pyx_v_zeros_out;
  PyObject *__pyx_v_row_inds = NULL;
  PyObject *__pyx_v_row_data = NULL;
  PyObject *__pyx_v_Rf = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  double __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int_t __pyx_t_14;
  int_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  int __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  double __pyx_t_21;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getFaceIntMat", 0);
  __Pyx_TraceCall("_getFaceIntMat", __pyx_f[0], 5475, 0, __PYX_ERR(0, 5475, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5477
 *     def _getFaceIntMat(self, locs, zeros_outside, direction):
 *         cdef:
 *             double[:, :] locations = locs             # <<<<<<<<<<<<<<
 *             int_t dir, dir1, dir2, temp
 *             int_t dim = self._dim
 */
  __Pyx_TraceLine(5477,0,__PYX_ERR(0, 5477, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_locs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 5477, __pyx_L1_error)
  __pyx_v_locations = __pyx_t_1;
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5479
 *             double[:, :] locations = locs
 *             int_t dir, dir1, dir2, temp
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             int_t n_loc = locs.shape[0]
 *             int_t n_faces = 4 if dim == 2 else 8
 */
  __Pyx_TraceLine(5479,0,__PYX_ERR(0, 5479, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5480
 *             int_t dir, dir1, dir2, temp
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]             # <<<<<<<<<<<<<<
 *             int_t n_faces = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_faces * np.arange(n_loc + 1, dtype=np.int64)
 */
  __Pyx_TraceLine(5480,0,__PYX_ERR(0, 5480, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_4); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5480, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_n_loc = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5481
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]
 *             int_t n_faces = 4 if dim == 2 else 8             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indptr = n_faces * np.arange(n_loc + 1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc*n_faces, dtype=np.int64)
 */
  __Pyx_TraceLine(5481,0,__PYX_ERR(0, 5481, __pyx_L1_error))
  if (((__pyx_v_dim == 2) != 0)) {
    __pyx_t_2 = 4;
  } else {
    __pyx_t_2 = 8;
  }
  __pyx_v_n_faces = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5482
 *             int_t n_loc = locs.shape[0]
 *             int_t n_faces = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_faces * np.arange(n_loc + 1, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indices = np.empty(n_loc*n_faces, dtype=np.int64)
 *             np.float64_t[:] data = np.empty(n_loc*n_faces, dtype=np.float64)
 */
  __Pyx_TraceLine(5482,0,__PYX_ERR(0, 5482, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyInt_From_int_t(__pyx_v_n_faces); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_arange); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_n_loc + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5482, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_indptr = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5483
 *             int_t n_faces = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_faces * np.arange(n_loc + 1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc*n_faces, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] data = np.empty(n_loc*n_faces, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5483,0,__PYX_ERR(0, 5483, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int_t((__pyx_v_n_loc * __pyx_v_n_faces)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5483, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_indices = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5484
 *             np.int64_t[:] indptr = n_faces * np.arange(n_loc + 1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_loc*n_faces, dtype=np.int64)
 *             np.float64_t[:] data = np.empty(n_loc*n_faces, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             int_t ii, i, offset
 */
  __Pyx_TraceLine(5484,0,__PYX_ERR(0, 5484, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_n_loc * __pyx_v_n_faces)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 5484, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_data = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5493
 *             double x, y, z
 *             double w1, w2, w3
 *             double eps = 100*np.finfo(float).eps             # <<<<<<<<<<<<<<
 *             int zeros_out = zeros_outside
 * 
 */
  __Pyx_TraceLine(5493,0,__PYX_ERR(0, 5493, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_finfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, ((PyObject *)(&PyFloat_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyFloat_Type)));
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_eps); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_100, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5493, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_eps = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":5494
 *             double w1, w2, w3
 *             double eps = 100*np.finfo(float).eps
 *             int zeros_out = zeros_outside             # <<<<<<<<<<<<<<
 * 
 *         if direction == 'x':
 */
  __Pyx_TraceLine(5494,0,__PYX_ERR(0, 5494, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_v_zeros_outside); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5494, __pyx_L1_error)
  __pyx_v_zeros_out = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":5496
 *             int zeros_out = zeros_outside
 * 
 *         if direction == 'x':             # <<<<<<<<<<<<<<
 *             dir = 0
 *             dir1 = 1
 */
  __Pyx_TraceLine(5496,0,__PYX_ERR(0, 5496, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_x, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5496, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":5497
 * 
 *         if direction == 'x':
 *             dir = 0             # <<<<<<<<<<<<<<
 *             dir1 = 1
 *             dir2 = 2
 */
    __Pyx_TraceLine(5497,0,__PYX_ERR(0, 5497, __pyx_L1_error))
    __pyx_v_dir = 0;

    /* "discretize/_extensions/tree_ext.pyx":5498
 *         if direction == 'x':
 *             dir = 0
 *             dir1 = 1             # <<<<<<<<<<<<<<
 *             dir2 = 2
 *             offset = 0
 */
    __Pyx_TraceLine(5498,0,__PYX_ERR(0, 5498, __pyx_L1_error))
    __pyx_v_dir1 = 1;

    /* "discretize/_extensions/tree_ext.pyx":5499
 *             dir = 0
 *             dir1 = 1
 *             dir2 = 2             # <<<<<<<<<<<<<<
 *             offset = 0
 *         elif direction == 'y':
 */
    __Pyx_TraceLine(5499,0,__PYX_ERR(0, 5499, __pyx_L1_error))
    __pyx_v_dir2 = 2;

    /* "discretize/_extensions/tree_ext.pyx":5500
 *             dir1 = 1
 *             dir2 = 2
 *             offset = 0             # <<<<<<<<<<<<<<
 *         elif direction == 'y':
 *             dir = 1
 */
    __Pyx_TraceLine(5500,0,__PYX_ERR(0, 5500, __pyx_L1_error))
    __pyx_v_offset = 0;

    /* "discretize/_extensions/tree_ext.pyx":5496
 *             int zeros_out = zeros_outside
 * 
 *         if direction == 'x':             # <<<<<<<<<<<<<<
 *             dir = 0
 *             dir1 = 1
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5501
 *             dir2 = 2
 *             offset = 0
 *         elif direction == 'y':             # <<<<<<<<<<<<<<
 *             dir = 1
 *             dir1 = 0
 */
  __Pyx_TraceLine(5501,0,__PYX_ERR(0, 5501, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_y, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5501, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":5502
 *             offset = 0
 *         elif direction == 'y':
 *             dir = 1             # <<<<<<<<<<<<<<
 *             dir1 = 0
 *             dir2 = 2
 */
    __Pyx_TraceLine(5502,0,__PYX_ERR(0, 5502, __pyx_L1_error))
    __pyx_v_dir = 1;

    /* "discretize/_extensions/tree_ext.pyx":5503
 *         elif direction == 'y':
 *             dir = 1
 *             dir1 = 0             # <<<<<<<<<<<<<<
 *             dir2 = 2
 *             offset = self.n_total_faces_x
 */
    __Pyx_TraceLine(5503,0,__PYX_ERR(0, 5503, __pyx_L1_error))
    __pyx_v_dir1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5504
 *             dir = 1
 *             dir1 = 0
 *             dir2 = 2             # <<<<<<<<<<<<<<
 *             offset = self.n_total_faces_x
 *         elif direction == 'z':
 */
    __Pyx_TraceLine(5504,0,__PYX_ERR(0, 5504, __pyx_L1_error))
    __pyx_v_dir2 = 2;

    /* "discretize/_extensions/tree_ext.pyx":5505
 *             dir1 = 0
 *             dir2 = 2
 *             offset = self.n_total_faces_x             # <<<<<<<<<<<<<<
 *         elif direction == 'z':
 *             dir = 2
 */
    __Pyx_TraceLine(5505,0,__PYX_ERR(0, 5505, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_6); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5505, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_offset = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5501
 *             dir2 = 2
 *             offset = 0
 *         elif direction == 'y':             # <<<<<<<<<<<<<<
 *             dir = 1
 *             dir1 = 0
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5506
 *             dir2 = 2
 *             offset = self.n_total_faces_x
 *         elif direction == 'z':             # <<<<<<<<<<<<<<
 *             dir = 2
 *             dir1 = 0
 */
  __Pyx_TraceLine(5506,0,__PYX_ERR(0, 5506, __pyx_L1_error))
  __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_v_direction, __pyx_n_u_z, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 5506, __pyx_L1_error)
  if (likely(__pyx_t_13)) {

    /* "discretize/_extensions/tree_ext.pyx":5507
 *             offset = self.n_total_faces_x
 *         elif direction == 'z':
 *             dir = 2             # <<<<<<<<<<<<<<
 *             dir1 = 0
 *             dir2 = 1
 */
    __Pyx_TraceLine(5507,0,__PYX_ERR(0, 5507, __pyx_L1_error))
    __pyx_v_dir = 2;

    /* "discretize/_extensions/tree_ext.pyx":5508
 *         elif direction == 'z':
 *             dir = 2
 *             dir1 = 0             # <<<<<<<<<<<<<<
 *             dir2 = 1
 *             offset = self.n_total_faces_x + self.n_total_faces_y
 */
    __Pyx_TraceLine(5508,0,__PYX_ERR(0, 5508, __pyx_L1_error))
    __pyx_v_dir1 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5509
 *             dir = 2
 *             dir1 = 0
 *             dir2 = 1             # <<<<<<<<<<<<<<
 *             offset = self.n_total_faces_x + self.n_total_faces_y
 *         else:
 */
    __Pyx_TraceLine(5509,0,__PYX_ERR(0, 5509, __pyx_L1_error))
    __pyx_v_dir2 = 1;

    /* "discretize/_extensions/tree_ext.pyx":5510
 *             dir1 = 0
 *             dir2 = 1
 *             offset = self.n_total_faces_x + self.n_total_faces_y             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('Invalid direction, must be x, y, or z')
 */
    __Pyx_TraceLine(5510,0,__PYX_ERR(0, 5510, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyNumber_Add(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5510, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_offset = __pyx_t_2;

    /* "discretize/_extensions/tree_ext.pyx":5506
 *             dir2 = 2
 *             offset = self.n_total_faces_x
 *         elif direction == 'z':             # <<<<<<<<<<<<<<
 *             dir = 2
 *             dir1 = 0
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":5512
 *             offset = self.n_total_faces_x + self.n_total_faces_y
 *         else:
 *             raise ValueError('Invalid direction, must be x, y, or z')             # <<<<<<<<<<<<<<
 * 
 *         for i in range(n_loc):
 */
  __Pyx_TraceLine(5512,0,__PYX_ERR(0, 5512, __pyx_L1_error))
  /*else*/ {
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 5512, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":5514
 *             raise ValueError('Invalid direction, must be x, y, or z')
 * 
 *         for i in range(n_loc):             # <<<<<<<<<<<<<<
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 */
  __Pyx_TraceLine(5514,0,__PYX_ERR(0, 5514, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_n_loc;
  __pyx_t_14 = __pyx_t_2;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "discretize/_extensions/tree_ext.pyx":5515
 * 
 *         for i in range(n_loc):
 *             x = locations[i, 0]             # <<<<<<<<<<<<<<
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0
 */
    __Pyx_TraceLine(5515,0,__PYX_ERR(0, 5515, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = 0;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5515, __pyx_L1_error)
    }
    __pyx_v_x = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5516
 *         for i in range(n_loc):
 *             x = locations[i, 0]
 *             y = locations[i, 1]             # <<<<<<<<<<<<<<
 *             z = locations[i, 2] if dim==3 else 0.0
 *             #get containing (or closest) cell
 */
    __Pyx_TraceLine(5516,0,__PYX_ERR(0, 5516, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_16 = 1;
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5516, __pyx_L1_error)
    }
    __pyx_v_y = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5517
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0             # <<<<<<<<<<<<<<
 *             #get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 */
    __Pyx_TraceLine(5517,0,__PYX_ERR(0, 5517, __pyx_L1_error))
    if (((__pyx_v_dim == 3) != 0)) {
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_17 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5517, __pyx_L1_error)
      }
      __pyx_t_11 = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_17 * __pyx_v_locations.strides[1]) )));
    } else {
      __pyx_t_11 = 0.0;
    }
    __pyx_v_z = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5519
 *             z = locations[i, 2] if dim==3 else 0.0
 *             #get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)             # <<<<<<<<<<<<<<
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 */
    __Pyx_TraceLine(5519,0,__PYX_ERR(0, 5519, __pyx_L1_error))
    __pyx_v_cell = __pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z);

    /* "discretize/_extensions/tree_ext.pyx":5520
 *             #get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i+1]]             # <<<<<<<<<<<<<<
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 */
    __Pyx_TraceLine(5520,0,__PYX_ERR(0, 5520, __pyx_L1_error))
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5520, __pyx_L1_error)
    }
    __pyx_t_16 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5520, __pyx_L1_error)
    }
    __pyx_t_9.data = __pyx_v_indices.data;
    __pyx_t_9.memview = __pyx_v_indices.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_indices.shape[0], __pyx_v_indices.strides[0], __pyx_v_indices.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_17 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5520, __pyx_L1_error)
}

__pyx_t_5 = __pyx_memoryview_fromslice(__pyx_t_9, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
    __Pyx_XDECREF_SET(__pyx_v_row_inds, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5521
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]             # <<<<<<<<<<<<<<
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 */
    __Pyx_TraceLine(5521,0,__PYX_ERR(0, 5521, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5521, __pyx_L1_error)
    }
    __pyx_t_17 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_17 < 0) {
      __pyx_t_17 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_17 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5521, __pyx_L1_error)
    }
    __pyx_t_10.data = __pyx_v_data.data;
    __pyx_t_10.memview = __pyx_v_data.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_data.shape[0], __pyx_v_data.strides[0], __pyx_v_data.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_17 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5521, __pyx_L1_error)
}

__pyx_t_5 = __pyx_memoryview_fromslice(__pyx_t_10, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5521, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;
    __Pyx_XDECREF_SET(__pyx_v_row_data, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":5522
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
    __Pyx_TraceLine(5522,0,__PYX_ERR(0, 5522, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_zeros_out != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":5523
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5523,0,__PYX_ERR(0, 5523, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_x < (((__pyx_v_cell->points[0])->location[0]) - __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5524
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 */
        __Pyx_TraceLine(5524,0,__PYX_ERR(0, 5524, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5524, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5525
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5525,0,__PYX_ERR(0, 5525, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5525, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5523
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5526
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5526,0,__PYX_ERR(0, 5526, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_x > (((__pyx_v_cell->points[3])->location[0]) + __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5527
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 */
        __Pyx_TraceLine(5527,0,__PYX_ERR(0, 5527, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5527, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5528
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5528,0,__PYX_ERR(0, 5528, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5528, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5526
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5529
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5529,0,__PYX_ERR(0, 5529, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_y < (((__pyx_v_cell->points[0])->location[1]) - __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5530
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 */
        __Pyx_TraceLine(5530,0,__PYX_ERR(0, 5530, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5530, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5531
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5531,0,__PYX_ERR(0, 5531, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5531, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5529
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5532
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5532,0,__PYX_ERR(0, 5532, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_y > (((__pyx_v_cell->points[3])->location[1]) + __pyx_v_eps)) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5533
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 */
        __Pyx_TraceLine(5533,0,__PYX_ERR(0, 5533, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5533, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5534
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5534,0,__PYX_ERR(0, 5534, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5534, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5532
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5535
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5535,0,__PYX_ERR(0, 5535, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z < (((__pyx_v_cell->points[0])->location[2]) - __pyx_v_eps)) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L8_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5536
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 */
        __Pyx_TraceLine(5536,0,__PYX_ERR(0, 5536, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5536, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5537
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5537,0,__PYX_ERR(0, 5537, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5537, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5535
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L7;
      }

      /* "discretize/_extensions/tree_ext.pyx":5538
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5538,0,__PYX_ERR(0, 5538, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L10_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z > (((__pyx_v_cell->points[7])->location[2]) + __pyx_v_eps)) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L10_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5539
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *             else:
 */
        __Pyx_TraceLine(5539,0,__PYX_ERR(0, 5539, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_data, __pyx_float_0_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5539, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5540
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *             else:
 *               # Find containing cells
 */
        __Pyx_TraceLine(5540,0,__PYX_ERR(0, 5540, __pyx_L1_error))
        if (__Pyx_PyObject_SetSlice(__pyx_v_row_inds, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 5540, __pyx_L1_error)

        /* "discretize/_extensions/tree_ext.pyx":5538
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      }
      __pyx_L7:;

      /* "discretize/_extensions/tree_ext.pyx":5522
 *             row_inds = indices[indptr[i]:indptr[i+1]]
 *             row_data = data[indptr[i]:indptr[i+1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
      goto __pyx_L6;
    }

    /* "discretize/_extensions/tree_ext.pyx":5544
 *               # Find containing cells
 *               # Decide order to search based on which face it is closest to
 *               if dim == 3:             # <<<<<<<<<<<<<<
 *                   if (
 *                       abs(locations[i, dir1] - cell.location[dir1]) <
 */
    __Pyx_TraceLine(5544,0,__PYX_ERR(0, 5544, __pyx_L1_error))
    /*else*/ {
      __pyx_t_13 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5546
 *               if dim == 3:
 *                   if (
 *                       abs(locations[i, dir1] - cell.location[dir1]) <             # <<<<<<<<<<<<<<
 *                       abs(locations[i, dir2] - cell.location[dir2])
 *                   ):
 */
        __Pyx_TraceLine(5546,0,__PYX_ERR(0, 5546, __pyx_L1_error))
        __pyx_t_17 = __pyx_v_i;
        __pyx_t_16 = __pyx_v_dir1;
        __pyx_t_12 = -1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5546, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5547
 *                   if (
 *                       abs(locations[i, dir1] - cell.location[dir1]) <
 *                       abs(locations[i, dir2] - cell.location[dir2])             # <<<<<<<<<<<<<<
 *                   ):
 *                     temp = dir1
 */
        __Pyx_TraceLine(5547,0,__PYX_ERR(0, 5547, __pyx_L1_error))
        __pyx_t_19 = __pyx_v_i;
        __pyx_t_20 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5547, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5546
 *               if dim == 3:
 *                   if (
 *                       abs(locations[i, dir1] - cell.location[dir1]) <             # <<<<<<<<<<<<<<
 *                       abs(locations[i, dir2] - cell.location[dir2])
 *                   ):
 */
        __Pyx_TraceLine(5546,0,__PYX_ERR(0, 5546, __pyx_L1_error))
        __pyx_t_13 = ((fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_17 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir1]))) < fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir2])))) != 0);

        /* "discretize/_extensions/tree_ext.pyx":5545
 *               # Decide order to search based on which face it is closest to
 *               if dim == 3:
 *                   if (             # <<<<<<<<<<<<<<
 *                       abs(locations[i, dir1] - cell.location[dir1]) <
 *                       abs(locations[i, dir2] - cell.location[dir2])
 */
        __Pyx_TraceLine(5545,0,__PYX_ERR(0, 5545, __pyx_L1_error))
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5549
 *                       abs(locations[i, dir2] - cell.location[dir2])
 *                   ):
 *                     temp = dir1             # <<<<<<<<<<<<<<
 *                     dir1 = dir2
 *                     dir2 = temp
 */
          __Pyx_TraceLine(5549,0,__PYX_ERR(0, 5549, __pyx_L1_error))
          __pyx_v_temp = __pyx_v_dir1;

          /* "discretize/_extensions/tree_ext.pyx":5550
 *                   ):
 *                     temp = dir1
 *                     dir1 = dir2             # <<<<<<<<<<<<<<
 *                     dir2 = temp
 *               # look in dir1 direction
 */
          __Pyx_TraceLine(5550,0,__PYX_ERR(0, 5550, __pyx_L1_error))
          __pyx_v_dir1 = __pyx_v_dir2;

          /* "discretize/_extensions/tree_ext.pyx":5551
 *                     temp = dir1
 *                     dir1 = dir2
 *                     dir2 = temp             # <<<<<<<<<<<<<<
 *               # look in dir1 direction
 *               if (
 */
          __Pyx_TraceLine(5551,0,__PYX_ERR(0, 5551, __pyx_L1_error))
          __pyx_v_dir2 = __pyx_v_temp;

          /* "discretize/_extensions/tree_ext.pyx":5545
 *               # Decide order to search based on which face it is closest to
 *               if dim == 3:
 *                   if (             # <<<<<<<<<<<<<<
 *                       abs(locations[i, dir1] - cell.location[dir1]) <
 *                       abs(locations[i, dir2] - cell.location[dir2])
 */
        }

        /* "discretize/_extensions/tree_ext.pyx":5544
 *               # Find containing cells
 *               # Decide order to search based on which face it is closest to
 *               if dim == 3:             # <<<<<<<<<<<<<<
 *                   if (
 *                       abs(locations[i, dir1] - cell.location[dir1]) <
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":5554
 *               # look in dir1 direction
 *               if (
 *                   locations[i, dir1] < cell.location[dir1]             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1] != NULL
 *                   and cell.neighbors[2*dir1].is_leaf()
 */
      __Pyx_TraceLine(5554,0,__PYX_ERR(0, 5554, __pyx_L1_error))
      __pyx_t_20 = __pyx_v_i;
      __pyx_t_19 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5554, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir1])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L15_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5555
 *               if (
 *                   locations[i, dir1] < cell.location[dir1]
 *                   and cell.neighbors[2*dir1] != NULL             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1].is_leaf()
 *                   and cell.neighbors[2*dir1].level == cell.level
 */
      __Pyx_TraceLine(5555,0,__PYX_ERR(0, 5555, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L15_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5556
 *                   locations[i, dir1] < cell.location[dir1]
 *                   and cell.neighbors[2*dir1] != NULL
 *                   and cell.neighbors[2*dir1].is_leaf()             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1].level == cell.level
 *               ):
 */
      __Pyx_TraceLine(5556,0,__PYX_ERR(0, 5556, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[(2 * __pyx_v_dir1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L15_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5557
 *                   and cell.neighbors[2*dir1] != NULL
 *                   and cell.neighbors[2*dir1].is_leaf()
 *                   and cell.neighbors[2*dir1].level == cell.level             # <<<<<<<<<<<<<<
 *               ):
 *                   i00 = cell.neighbors[2*dir1]
 */
      __Pyx_TraceLine(5557,0,__PYX_ERR(0, 5557, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir1)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L15_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5553
 *                     dir2 = temp
 *               # look in dir1 direction
 *               if (             # <<<<<<<<<<<<<<
 *                   locations[i, dir1] < cell.location[dir1]
 *                   and cell.neighbors[2*dir1] != NULL
 */
      __Pyx_TraceLine(5553,0,__PYX_ERR(0, 5553, __pyx_L1_error))
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5559
 *                   and cell.neighbors[2*dir1].level == cell.level
 *               ):
 *                   i00 = cell.neighbors[2*dir1]             # <<<<<<<<<<<<<<
 *                   i01 = cell
 *               elif (
 */
        __Pyx_TraceLine(5559,0,__PYX_ERR(0, 5559, __pyx_L1_error))
        __pyx_v_i00 = (__pyx_v_cell->neighbors[(2 * __pyx_v_dir1)]);

        /* "discretize/_extensions/tree_ext.pyx":5560
 *               ):
 *                   i00 = cell.neighbors[2*dir1]
 *                   i01 = cell             # <<<<<<<<<<<<<<
 *               elif (
 *                   locations[i, dir1] > cell.location[dir1]
 */
        __Pyx_TraceLine(5560,0,__PYX_ERR(0, 5560, __pyx_L1_error))
        __pyx_v_i01 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5553
 *                     dir2 = temp
 *               # look in dir1 direction
 *               if (             # <<<<<<<<<<<<<<
 *                   locations[i, dir1] < cell.location[dir1]
 *                   and cell.neighbors[2*dir1] != NULL
 */
        goto __pyx_L14;
      }

      /* "discretize/_extensions/tree_ext.pyx":5562
 *                   i01 = cell
 *               elif (
 *                   locations[i, dir1] > cell.location[dir1]             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1 + 1] != NULL
 *                   and cell.neighbors[2*dir1 + 1].is_leaf()
 */
      __Pyx_TraceLine(5562,0,__PYX_ERR(0, 5562, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5562, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir1])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L19_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5563
 *               elif (
 *                   locations[i, dir1] > cell.location[dir1]
 *                   and cell.neighbors[2*dir1 + 1] != NULL             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1 + 1].is_leaf()
 *                   and cell.neighbors[2*dir1 + 1].level == cell.level
 */
      __Pyx_TraceLine(5563,0,__PYX_ERR(0, 5563, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir1) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L19_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5564
 *                   locations[i, dir1] > cell.location[dir1]
 *                   and cell.neighbors[2*dir1 + 1] != NULL
 *                   and cell.neighbors[2*dir1 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                   and cell.neighbors[2*dir1 + 1].level == cell.level
 *               ):
 */
      __Pyx_TraceLine(5564,0,__PYX_ERR(0, 5564, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[((2 * __pyx_v_dir1) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_13 = __pyx_t_18;
        goto __pyx_L19_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5565
 *                   and cell.neighbors[2*dir1 + 1] != NULL
 *                   and cell.neighbors[2*dir1 + 1].is_leaf()
 *                   and cell.neighbors[2*dir1 + 1].level == cell.level             # <<<<<<<<<<<<<<
 *               ):
 *                   i00 = cell
 */
      __Pyx_TraceLine(5565,0,__PYX_ERR(0, 5565, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir1) + 1)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_13 = __pyx_t_18;
      __pyx_L19_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5561
 *                   i00 = cell.neighbors[2*dir1]
 *                   i01 = cell
 *               elif (             # <<<<<<<<<<<<<<
 *                   locations[i, dir1] > cell.location[dir1]
 *                   and cell.neighbors[2*dir1 + 1] != NULL
 */
      __Pyx_TraceLine(5561,0,__PYX_ERR(0, 5561, __pyx_L1_error))
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5567
 *                   and cell.neighbors[2*dir1 + 1].level == cell.level
 *               ):
 *                   i00 = cell             # <<<<<<<<<<<<<<
 *                   i01 = cell.neighbors[2*dir1 + 1]
 *               else:
 */
        __Pyx_TraceLine(5567,0,__PYX_ERR(0, 5567, __pyx_L1_error))
        __pyx_v_i00 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5568
 *               ):
 *                   i00 = cell
 *                   i01 = cell.neighbors[2*dir1 + 1]             # <<<<<<<<<<<<<<
 *               else:
 *                   i00 = i01 = cell
 */
        __Pyx_TraceLine(5568,0,__PYX_ERR(0, 5568, __pyx_L1_error))
        __pyx_v_i01 = (__pyx_v_cell->neighbors[((2 * __pyx_v_dir1) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5561
 *                   i00 = cell.neighbors[2*dir1]
 *                   i01 = cell
 *               elif (             # <<<<<<<<<<<<<<
 *                   locations[i, dir1] > cell.location[dir1]
 *                   and cell.neighbors[2*dir1 + 1] != NULL
 */
        goto __pyx_L14;
      }

      /* "discretize/_extensions/tree_ext.pyx":5570
 *                   i01 = cell.neighbors[2*dir1 + 1]
 *               else:
 *                   i00 = i01 = cell             # <<<<<<<<<<<<<<
 * 
 *               if dim == 2:
 */
      __Pyx_TraceLine(5570,0,__PYX_ERR(0, 5570, __pyx_L1_error))
      /*else*/ {
        __pyx_v_i00 = __pyx_v_cell;
        __pyx_v_i01 = __pyx_v_cell;
      }
      __pyx_L14:;

      /* "discretize/_extensions/tree_ext.pyx":5572
 *                   i00 = i01 = cell
 * 
 *               if dim == 2:             # <<<<<<<<<<<<<<
 *                   e00 = i00.edges[2 * dir1]
 *                   e01 = i00.edges[2 * dir1 + 1]
 */
      __Pyx_TraceLine(5572,0,__PYX_ERR(0, 5572, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_dim == 2) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":5573
 * 
 *               if dim == 2:
 *                   e00 = i00.edges[2 * dir1]             # <<<<<<<<<<<<<<
 *                   e01 = i00.edges[2 * dir1 + 1]
 *                   e10 = i01.edges[2 * dir1]
 */
        __Pyx_TraceLine(5573,0,__PYX_ERR(0, 5573, __pyx_L1_error))
        __pyx_v_e00 = (__pyx_v_i00->edges[(2 * __pyx_v_dir1)]);

        /* "discretize/_extensions/tree_ext.pyx":5574
 *               if dim == 2:
 *                   e00 = i00.edges[2 * dir1]
 *                   e01 = i00.edges[2 * dir1 + 1]             # <<<<<<<<<<<<<<
 *                   e10 = i01.edges[2 * dir1]
 *                   e11 = i01.edges[2 * dir1 + 1]
 */
        __Pyx_TraceLine(5574,0,__PYX_ERR(0, 5574, __pyx_L1_error))
        __pyx_v_e01 = (__pyx_v_i00->edges[((2 * __pyx_v_dir1) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5575
 *                   e00 = i00.edges[2 * dir1]
 *                   e01 = i00.edges[2 * dir1 + 1]
 *                   e10 = i01.edges[2 * dir1]             # <<<<<<<<<<<<<<
 *                   e11 = i01.edges[2 * dir1 + 1]
 *                   w1 = ((e01.location[dir] - locations[i, dir])/
 */
        __Pyx_TraceLine(5575,0,__PYX_ERR(0, 5575, __pyx_L1_error))
        __pyx_v_e10 = (__pyx_v_i01->edges[(2 * __pyx_v_dir1)]);

        /* "discretize/_extensions/tree_ext.pyx":5576
 *                   e01 = i00.edges[2 * dir1 + 1]
 *                   e10 = i01.edges[2 * dir1]
 *                   e11 = i01.edges[2 * dir1 + 1]             # <<<<<<<<<<<<<<
 *                   w1 = ((e01.location[dir] - locations[i, dir])/
 *                         (e01.location[dir] - e00.location[dir]))
 */
        __Pyx_TraceLine(5576,0,__PYX_ERR(0, 5576, __pyx_L1_error))
        __pyx_v_e11 = (__pyx_v_i01->edges[((2 * __pyx_v_dir1) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5577
 *                   e10 = i01.edges[2 * dir1]
 *                   e11 = i01.edges[2 * dir1 + 1]
 *                   w1 = ((e01.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:
 */
        __Pyx_TraceLine(5577,0,__PYX_ERR(0, 5577, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5577, __pyx_L1_error)
        }
        __pyx_t_11 = ((__pyx_v_e01->location[__pyx_v_dir]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5578
 *                   e11 = i01.edges[2 * dir1 + 1]
 *                   w1 = ((e01.location[dir] - locations[i, dir])/
 *                         (e01.location[dir] - e00.location[dir]))             # <<<<<<<<<<<<<<
 *                   if i00.index != i01.index:
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/
 */
        __Pyx_TraceLine(5578,0,__PYX_ERR(0, 5578, __pyx_L1_error))
        __pyx_t_21 = ((__pyx_v_e01->location[__pyx_v_dir]) - (__pyx_v_e00->location[__pyx_v_dir]));

        /* "discretize/_extensions/tree_ext.pyx":5577
 *                   e10 = i01.edges[2 * dir1]
 *                   e11 = i01.edges[2 * dir1 + 1]
 *                   w1 = ((e01.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:
 */
        __Pyx_TraceLine(5577,0,__PYX_ERR(0, 5577, __pyx_L1_error))
        if (unlikely(__pyx_t_21 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5577, __pyx_L1_error)
        }
        __pyx_v_w1 = (__pyx_t_11 / __pyx_t_21);

        /* "discretize/_extensions/tree_ext.pyx":5579
 *                   w1 = ((e01.location[dir] - locations[i, dir])/
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:             # <<<<<<<<<<<<<<
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/
 *                             (e10.location[dir1] - e00.location[dir1]))
 */
        __Pyx_TraceLine(5579,0,__PYX_ERR(0, 5579, __pyx_L1_error))
        __pyx_t_13 = ((__pyx_v_i00->index != __pyx_v_i01->index) != 0);
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5580
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                             (e10.location[dir1] - e00.location[dir1]))
 *                   else:
 */
          __Pyx_TraceLine(5580,0,__PYX_ERR(0, 5580, __pyx_L1_error))
          __pyx_t_19 = __pyx_v_i;
          __pyx_t_20 = __pyx_v_dir1;
          __pyx_t_12 = -1;
          if (__pyx_t_19 < 0) {
            __pyx_t_19 += __pyx_v_locations.shape[0];
            if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
          } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
          if (__pyx_t_20 < 0) {
            __pyx_t_20 += __pyx_v_locations.shape[1];
            if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
          } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
          if (unlikely(__pyx_t_12 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_12);
            __PYX_ERR(0, 5580, __pyx_L1_error)
          }
          __pyx_t_21 = ((__pyx_v_e10->location[__pyx_v_dir1]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))));

          /* "discretize/_extensions/tree_ext.pyx":5581
 *                   if i00.index != i01.index:
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/
 *                             (e10.location[dir1] - e00.location[dir1]))             # <<<<<<<<<<<<<<
 *                   else:
 *                       w2 = 1.0
 */
          __Pyx_TraceLine(5581,0,__PYX_ERR(0, 5581, __pyx_L1_error))
          __pyx_t_11 = ((__pyx_v_e10->location[__pyx_v_dir1]) - (__pyx_v_e00->location[__pyx_v_dir1]));

          /* "discretize/_extensions/tree_ext.pyx":5580
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                             (e10.location[dir1] - e00.location[dir1]))
 *                   else:
 */
          __Pyx_TraceLine(5580,0,__PYX_ERR(0, 5580, __pyx_L1_error))
          if (unlikely(__pyx_t_11 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 5580, __pyx_L1_error)
          }
          __pyx_v_w2 = (__pyx_t_21 / __pyx_t_11);

          /* "discretize/_extensions/tree_ext.pyx":5579
 *                   w1 = ((e01.location[dir] - locations[i, dir])/
 *                         (e01.location[dir] - e00.location[dir]))
 *                   if i00.index != i01.index:             # <<<<<<<<<<<<<<
 *                       w2 = ((e10.location[dir1] - locations[i, dir1])/
 *                             (e10.location[dir1] - e00.location[dir1]))
 */
          goto __pyx_L24;
        }

        /* "discretize/_extensions/tree_ext.pyx":5583
 *                             (e10.location[dir1] - e00.location[dir1]))
 *                   else:
 *                       w2 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                   w1 = _clip01(w1)
 */
        __Pyx_TraceLine(5583,0,__PYX_ERR(0, 5583, __pyx_L1_error))
        /*else*/ {
          __pyx_v_w2 = 1.0;
        }
        __pyx_L24:;

        /* "discretize/_extensions/tree_ext.pyx":5585
 *                       w2 = 1.0
 * 
 *                   w1 = _clip01(w1)             # <<<<<<<<<<<<<<
 *                   w2 = _clip01(w2)
 *                   row_data[0] = w1 * w2
 */
        __Pyx_TraceLine(5585,0,__PYX_ERR(0, 5585, __pyx_L1_error))
        __pyx_v_w1 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w1);

        /* "discretize/_extensions/tree_ext.pyx":5586
 * 
 *                   w1 = _clip01(w1)
 *                   w2 = _clip01(w2)             # <<<<<<<<<<<<<<
 *                   row_data[0] = w1 * w2
 *                   row_data[1] = (1 - w1) * w2
 */
        __Pyx_TraceLine(5586,0,__PYX_ERR(0, 5586, __pyx_L1_error))
        __pyx_v_w2 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w2);

        /* "discretize/_extensions/tree_ext.pyx":5587
 *                   w1 = _clip01(w1)
 *                   w2 = _clip01(w2)
 *                   row_data[0] = w1 * w2             # <<<<<<<<<<<<<<
 *                   row_data[1] = (1 - w1) * w2
 *                   row_data[2] = w1 * (1 - w2)
 */
        __Pyx_TraceLine(5587,0,__PYX_ERR(0, 5587, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((__pyx_v_w1 * __pyx_v_w2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5587, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 0, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5587, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5588
 *                   w2 = _clip01(w2)
 *                   row_data[0] = w1 * w2
 *                   row_data[1] = (1 - w1) * w2             # <<<<<<<<<<<<<<
 *                   row_data[2] = w1 * (1 - w2)
 *                   row_data[3] = (1 - w1) * (1 - w2)
 */
        __Pyx_TraceLine(5588,0,__PYX_ERR(0, 5588, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * __pyx_v_w2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5588, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 1, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5588, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5589
 *                   row_data[0] = w1 * w2
 *                   row_data[1] = (1 - w1) * w2
 *                   row_data[2] = w1 * (1 - w2)             # <<<<<<<<<<<<<<
 *                   row_data[3] = (1 - w1) * (1 - w2)
 *                   row_inds[0] = e00.index + offset
 */
        __Pyx_TraceLine(5589,0,__PYX_ERR(0, 5589, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((__pyx_v_w1 * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5589, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 2, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5589, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5590
 *                   row_data[1] = (1 - w1) * w2
 *                   row_data[2] = w1 * (1 - w2)
 *                   row_data[3] = (1 - w1) * (1 - w2)             # <<<<<<<<<<<<<<
 *                   row_inds[0] = e00.index + offset
 *                   row_inds[1] = e01.index + offset
 */
        __Pyx_TraceLine(5590,0,__PYX_ERR(0, 5590, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5590, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 3, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5590, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5591
 *                   row_data[2] = w1 * (1 - w2)
 *                   row_data[3] = (1 - w1) * (1 - w2)
 *                   row_inds[0] = e00.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[1] = e01.index + offset
 *                   row_inds[2] = e10.index + offset
 */
        __Pyx_TraceLine(5591,0,__PYX_ERR(0, 5591, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_e00->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5591, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 0, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5591, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5592
 *                   row_data[3] = (1 - w1) * (1 - w2)
 *                   row_inds[0] = e00.index + offset
 *                   row_inds[1] = e01.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[2] = e10.index + offset
 *                   row_inds[3] = e11.index + offset
 */
        __Pyx_TraceLine(5592,0,__PYX_ERR(0, 5592, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_e01->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5592, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 1, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5592, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5593
 *                   row_inds[0] = e00.index + offset
 *                   row_inds[1] = e01.index + offset
 *                   row_inds[2] = e10.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[3] = e11.index + offset
 *               else:
 */
        __Pyx_TraceLine(5593,0,__PYX_ERR(0, 5593, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_e10->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5593, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 2, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5593, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5594
 *                   row_inds[1] = e01.index + offset
 *                   row_inds[2] = e10.index + offset
 *                   row_inds[3] = e11.index + offset             # <<<<<<<<<<<<<<
 *               else:
 *                   # Look dir2 from previous two cells
 */
        __Pyx_TraceLine(5594,0,__PYX_ERR(0, 5594, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_e11->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5594, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 3, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5594, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5572
 *                   i00 = i01 = cell
 * 
 *               if dim == 2:             # <<<<<<<<<<<<<<
 *                   e00 = i00.edges[2 * dir1]
 *                   e01 = i00.edges[2 * dir1 + 1]
 */
        goto __pyx_L23;
      }

      /* "discretize/_extensions/tree_ext.pyx":5597
 *               else:
 *                   # Look dir2 from previous two cells
 *                   if (             # <<<<<<<<<<<<<<
 *                       locations[i, dir2] < cell.location[dir2]
 *                       and i00.neighbors[2*dir2] != NULL
 */
      __Pyx_TraceLine(5597,0,__PYX_ERR(0, 5597, __pyx_L1_error))
      /*else*/ {

        /* "discretize/_extensions/tree_ext.pyx":5598
 *                   # Look dir2 from previous two cells
 *                   if (
 *                       locations[i, dir2] < cell.location[dir2]             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2] != NULL
 *                       and i01.neighbors[2*dir2] != NULL
 */
        __Pyx_TraceLine(5598,0,__PYX_ERR(0, 5598, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5598, __pyx_L1_error)
        }
        __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir2])) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5599
 *                   if (
 *                       locations[i, dir2] < cell.location[dir2]
 *                       and i00.neighbors[2*dir2] != NULL             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2] != NULL
 *                       and i00.neighbors[2*dir2].is_leaf()
 */
        __Pyx_TraceLine(5599,0,__PYX_ERR(0, 5599, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i00->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5600
 *                       locations[i, dir2] < cell.location[dir2]
 *                       and i00.neighbors[2*dir2] != NULL
 *                       and i01.neighbors[2*dir2] != NULL             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2].is_leaf()
 *                       and i01.neighbors[2*dir2].is_leaf()
 */
        __Pyx_TraceLine(5600,0,__PYX_ERR(0, 5600, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i01->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5601
 *                       and i00.neighbors[2*dir2] != NULL
 *                       and i01.neighbors[2*dir2] != NULL
 *                       and i00.neighbors[2*dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2].is_leaf()
 *                       and i00.neighbors[2*dir2].level == i00.level
 */
        __Pyx_TraceLine(5601,0,__PYX_ERR(0, 5601, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_i00->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5602
 *                       and i01.neighbors[2*dir2] != NULL
 *                       and i00.neighbors[2*dir2].is_leaf()
 *                       and i01.neighbors[2*dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2].level == i00.level
 *                       and i01.neighbors[2*dir2].level == i01.level
 */
        __Pyx_TraceLine(5602,0,__PYX_ERR(0, 5602, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_i01->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5603
 *                       and i00.neighbors[2*dir2].is_leaf()
 *                       and i01.neighbors[2*dir2].is_leaf()
 *                       and i00.neighbors[2*dir2].level == i00.level             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2].level == i01.level
 *                   ):
 */
        __Pyx_TraceLine(5603,0,__PYX_ERR(0, 5603, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i00->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i00->level) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L26_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5604
 *                       and i01.neighbors[2*dir2].is_leaf()
 *                       and i00.neighbors[2*dir2].level == i00.level
 *                       and i01.neighbors[2*dir2].level == i01.level             # <<<<<<<<<<<<<<
 *                   ):
 *                       i10 = i00
 */
        __Pyx_TraceLine(5604,0,__PYX_ERR(0, 5604, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i01->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i01->level) != 0);
        __pyx_t_13 = __pyx_t_18;
        __pyx_L26_bool_binop_done:;

        /* "discretize/_extensions/tree_ext.pyx":5597
 *               else:
 *                   # Look dir2 from previous two cells
 *                   if (             # <<<<<<<<<<<<<<
 *                       locations[i, dir2] < cell.location[dir2]
 *                       and i00.neighbors[2*dir2] != NULL
 */
        __Pyx_TraceLine(5597,0,__PYX_ERR(0, 5597, __pyx_L1_error))
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5606
 *                       and i01.neighbors[2*dir2].level == i01.level
 *                   ):
 *                       i10 = i00             # <<<<<<<<<<<<<<
 *                       i11 = i01
 *                       i00 = i00.neighbors[2*dir2]
 */
          __Pyx_TraceLine(5606,0,__PYX_ERR(0, 5606, __pyx_L1_error))
          __pyx_v_i10 = __pyx_v_i00;

          /* "discretize/_extensions/tree_ext.pyx":5607
 *                   ):
 *                       i10 = i00
 *                       i11 = i01             # <<<<<<<<<<<<<<
 *                       i00 = i00.neighbors[2*dir2]
 *                       i01 = i01.neighbors[2*dir2]
 */
          __Pyx_TraceLine(5607,0,__PYX_ERR(0, 5607, __pyx_L1_error))
          __pyx_v_i11 = __pyx_v_i01;

          /* "discretize/_extensions/tree_ext.pyx":5608
 *                       i10 = i00
 *                       i11 = i01
 *                       i00 = i00.neighbors[2*dir2]             # <<<<<<<<<<<<<<
 *                       i01 = i01.neighbors[2*dir2]
 *                   elif (
 */
          __Pyx_TraceLine(5608,0,__PYX_ERR(0, 5608, __pyx_L1_error))
          __pyx_v_i00 = (__pyx_v_i00->neighbors[(2 * __pyx_v_dir2)]);

          /* "discretize/_extensions/tree_ext.pyx":5609
 *                       i11 = i01
 *                       i00 = i00.neighbors[2*dir2]
 *                       i01 = i01.neighbors[2*dir2]             # <<<<<<<<<<<<<<
 *                   elif (
 *                       locations[i, dir2] > cell.location[dir2]
 */
          __Pyx_TraceLine(5609,0,__PYX_ERR(0, 5609, __pyx_L1_error))
          __pyx_v_i01 = (__pyx_v_i01->neighbors[(2 * __pyx_v_dir2)]);

          /* "discretize/_extensions/tree_ext.pyx":5597
 *               else:
 *                   # Look dir2 from previous two cells
 *                   if (             # <<<<<<<<<<<<<<
 *                       locations[i, dir2] < cell.location[dir2]
 *                       and i00.neighbors[2*dir2] != NULL
 */
          goto __pyx_L25;
        }

        /* "discretize/_extensions/tree_ext.pyx":5611
 *                       i01 = i01.neighbors[2*dir2]
 *                   elif (
 *                       locations[i, dir2] > cell.location[dir2]             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2 + 1] != NULL
 *                       and i01.neighbors[2*dir2 + 1] != NULL
 */
        __Pyx_TraceLine(5611,0,__PYX_ERR(0, 5611, __pyx_L1_error))
        __pyx_t_19 = __pyx_v_i;
        __pyx_t_20 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5611, __pyx_L1_error)
        }
        __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir2])) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5612
 *                   elif (
 *                       locations[i, dir2] > cell.location[dir2]
 *                       and i00.neighbors[2*dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2 + 1] != NULL
 *                       and i00.neighbors[2*dir2 + 1].is_leaf()
 */
        __Pyx_TraceLine(5612,0,__PYX_ERR(0, 5612, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i00->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5613
 *                       locations[i, dir2] > cell.location[dir2]
 *                       and i00.neighbors[2*dir2 + 1] != NULL
 *                       and i01.neighbors[2*dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2 + 1].is_leaf()
 *                       and i01.neighbors[2*dir2 + 1].is_leaf()
 */
        __Pyx_TraceLine(5613,0,__PYX_ERR(0, 5613, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i01->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5614
 *                       and i00.neighbors[2*dir2 + 1] != NULL
 *                       and i01.neighbors[2*dir2 + 1] != NULL
 *                       and i00.neighbors[2*dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2 + 1].is_leaf()
 *                       and i00.neighbors[2*dir2 + 1].level == i00.level
 */
        __Pyx_TraceLine(5614,0,__PYX_ERR(0, 5614, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_i00->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5615
 *                       and i01.neighbors[2*dir2 + 1] != NULL
 *                       and i00.neighbors[2*dir2 + 1].is_leaf()
 *                       and i01.neighbors[2*dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                       and i00.neighbors[2*dir2 + 1].level == i00.level
 *                       and i01.neighbors[2*dir2 + 1].level == i01.level
 */
        __Pyx_TraceLine(5615,0,__PYX_ERR(0, 5615, __pyx_L1_error))
        __pyx_t_18 = ((__pyx_v_i01->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5616
 *                       and i00.neighbors[2*dir2 + 1].is_leaf()
 *                       and i01.neighbors[2*dir2 + 1].is_leaf()
 *                       and i00.neighbors[2*dir2 + 1].level == i00.level             # <<<<<<<<<<<<<<
 *                       and i01.neighbors[2*dir2 + 1].level == i01.level
 *                   ):
 */
        __Pyx_TraceLine(5616,0,__PYX_ERR(0, 5616, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i00->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i00->level) != 0);
        if (__pyx_t_18) {
        } else {
          __pyx_t_13 = __pyx_t_18;
          goto __pyx_L33_bool_binop_done;
        }

        /* "discretize/_extensions/tree_ext.pyx":5617
 *                       and i01.neighbors[2*dir2 + 1].is_leaf()
 *                       and i00.neighbors[2*dir2 + 1].level == i00.level
 *                       and i01.neighbors[2*dir2 + 1].level == i01.level             # <<<<<<<<<<<<<<
 *                   ):
 *                       i10 = i00.neighbors[2*dir2 + 1]
 */
        __Pyx_TraceLine(5617,0,__PYX_ERR(0, 5617, __pyx_L1_error))
        __pyx_t_18 = (((__pyx_v_i01->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i01->level) != 0);
        __pyx_t_13 = __pyx_t_18;
        __pyx_L33_bool_binop_done:;

        /* "discretize/_extensions/tree_ext.pyx":5610
 *                       i00 = i00.neighbors[2*dir2]
 *                       i01 = i01.neighbors[2*dir2]
 *                   elif (             # <<<<<<<<<<<<<<
 *                       locations[i, dir2] > cell.location[dir2]
 *                       and i00.neighbors[2*dir2 + 1] != NULL
 */
        __Pyx_TraceLine(5610,0,__PYX_ERR(0, 5610, __pyx_L1_error))
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5619
 *                       and i01.neighbors[2*dir2 + 1].level == i01.level
 *                   ):
 *                       i10 = i00.neighbors[2*dir2 + 1]             # <<<<<<<<<<<<<<
 *                       i11 = i01.neighbors[2*dir2 + 1]
 *                   else:
 */
          __Pyx_TraceLine(5619,0,__PYX_ERR(0, 5619, __pyx_L1_error))
          __pyx_v_i10 = (__pyx_v_i00->neighbors[((2 * __pyx_v_dir2) + 1)]);

          /* "discretize/_extensions/tree_ext.pyx":5620
 *                   ):
 *                       i10 = i00.neighbors[2*dir2 + 1]
 *                       i11 = i01.neighbors[2*dir2 + 1]             # <<<<<<<<<<<<<<
 *                   else:
 *                       i10 = i00
 */
          __Pyx_TraceLine(5620,0,__PYX_ERR(0, 5620, __pyx_L1_error))
          __pyx_v_i11 = (__pyx_v_i01->neighbors[((2 * __pyx_v_dir2) + 1)]);

          /* "discretize/_extensions/tree_ext.pyx":5610
 *                       i00 = i00.neighbors[2*dir2]
 *                       i01 = i01.neighbors[2*dir2]
 *                   elif (             # <<<<<<<<<<<<<<
 *                       locations[i, dir2] > cell.location[dir2]
 *                       and i00.neighbors[2*dir2 + 1] != NULL
 */
          goto __pyx_L25;
        }

        /* "discretize/_extensions/tree_ext.pyx":5622
 *                       i11 = i01.neighbors[2*dir2 + 1]
 *                   else:
 *                       i10 = i00             # <<<<<<<<<<<<<<
 *                       i11 = i01
 * 
 */
        __Pyx_TraceLine(5622,0,__PYX_ERR(0, 5622, __pyx_L1_error))
        /*else*/ {
          __pyx_v_i10 = __pyx_v_i00;

          /* "discretize/_extensions/tree_ext.pyx":5623
 *                   else:
 *                       i10 = i00
 *                       i11 = i01             # <<<<<<<<<<<<<<
 * 
 *                   f000 = i00.faces[dir * 2]
 */
          __Pyx_TraceLine(5623,0,__PYX_ERR(0, 5623, __pyx_L1_error))
          __pyx_v_i11 = __pyx_v_i01;
        }
        __pyx_L25:;

        /* "discretize/_extensions/tree_ext.pyx":5625
 *                       i11 = i01
 * 
 *                   f000 = i00.faces[dir * 2]             # <<<<<<<<<<<<<<
 *                   f001 = i00.faces[dir * 2 + 1]
 *                   f010 = i01.faces[dir * 2]
 */
        __Pyx_TraceLine(5625,0,__PYX_ERR(0, 5625, __pyx_L1_error))
        __pyx_v_f000 = (__pyx_v_i00->faces[(__pyx_v_dir * 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5626
 * 
 *                   f000 = i00.faces[dir * 2]
 *                   f001 = i00.faces[dir * 2 + 1]             # <<<<<<<<<<<<<<
 *                   f010 = i01.faces[dir * 2]
 *                   f011 = i01.faces[dir * 2 + 1]
 */
        __Pyx_TraceLine(5626,0,__PYX_ERR(0, 5626, __pyx_L1_error))
        __pyx_v_f001 = (__pyx_v_i00->faces[((__pyx_v_dir * 2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5627
 *                   f000 = i00.faces[dir * 2]
 *                   f001 = i00.faces[dir * 2 + 1]
 *                   f010 = i01.faces[dir * 2]             # <<<<<<<<<<<<<<
 *                   f011 = i01.faces[dir * 2 + 1]
 *                   f100 = i10.faces[dir * 2]
 */
        __Pyx_TraceLine(5627,0,__PYX_ERR(0, 5627, __pyx_L1_error))
        __pyx_v_f010 = (__pyx_v_i01->faces[(__pyx_v_dir * 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5628
 *                   f001 = i00.faces[dir * 2 + 1]
 *                   f010 = i01.faces[dir * 2]
 *                   f011 = i01.faces[dir * 2 + 1]             # <<<<<<<<<<<<<<
 *                   f100 = i10.faces[dir * 2]
 *                   f101 = i10.faces[dir * 2 + 1]
 */
        __Pyx_TraceLine(5628,0,__PYX_ERR(0, 5628, __pyx_L1_error))
        __pyx_v_f011 = (__pyx_v_i01->faces[((__pyx_v_dir * 2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5629
 *                   f010 = i01.faces[dir * 2]
 *                   f011 = i01.faces[dir * 2 + 1]
 *                   f100 = i10.faces[dir * 2]             # <<<<<<<<<<<<<<
 *                   f101 = i10.faces[dir * 2 + 1]
 *                   f110 = i11.faces[dir * 2]
 */
        __Pyx_TraceLine(5629,0,__PYX_ERR(0, 5629, __pyx_L1_error))
        __pyx_v_f100 = (__pyx_v_i10->faces[(__pyx_v_dir * 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5630
 *                   f011 = i01.faces[dir * 2 + 1]
 *                   f100 = i10.faces[dir * 2]
 *                   f101 = i10.faces[dir * 2 + 1]             # <<<<<<<<<<<<<<
 *                   f110 = i11.faces[dir * 2]
 *                   f111 = i11.faces[dir * 2 + 1]
 */
        __Pyx_TraceLine(5630,0,__PYX_ERR(0, 5630, __pyx_L1_error))
        __pyx_v_f101 = (__pyx_v_i10->faces[((__pyx_v_dir * 2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5631
 *                   f100 = i10.faces[dir * 2]
 *                   f101 = i10.faces[dir * 2 + 1]
 *                   f110 = i11.faces[dir * 2]             # <<<<<<<<<<<<<<
 *                   f111 = i11.faces[dir * 2 + 1]
 * 
 */
        __Pyx_TraceLine(5631,0,__PYX_ERR(0, 5631, __pyx_L1_error))
        __pyx_v_f110 = (__pyx_v_i11->faces[(__pyx_v_dir * 2)]);

        /* "discretize/_extensions/tree_ext.pyx":5632
 *                   f101 = i10.faces[dir * 2 + 1]
 *                   f110 = i11.faces[dir * 2]
 *                   f111 = i11.faces[dir * 2 + 1]             # <<<<<<<<<<<<<<
 * 
 *                   w1 = ((f001.location[dir] - locations[i, dir])/
 */
        __Pyx_TraceLine(5632,0,__PYX_ERR(0, 5632, __pyx_L1_error))
        __pyx_v_f111 = (__pyx_v_i11->faces[((__pyx_v_dir * 2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5634
 *                   f111 = i11.faces[dir * 2 + 1]
 * 
 *                   w1 = ((f001.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:
 */
        __Pyx_TraceLine(5634,0,__PYX_ERR(0, 5634, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5634, __pyx_L1_error)
        }
        __pyx_t_11 = ((__pyx_v_f001->location[__pyx_v_dir]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5635
 * 
 *                   w1 = ((f001.location[dir] - locations[i, dir])/
 *                         (f001.location[dir] - f000.location[dir]))             # <<<<<<<<<<<<<<
 *                   if i00.index != i01.index:
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/
 */
        __Pyx_TraceLine(5635,0,__PYX_ERR(0, 5635, __pyx_L1_error))
        __pyx_t_21 = ((__pyx_v_f001->location[__pyx_v_dir]) - (__pyx_v_f000->location[__pyx_v_dir]));

        /* "discretize/_extensions/tree_ext.pyx":5634
 *                   f111 = i11.faces[dir * 2 + 1]
 * 
 *                   w1 = ((f001.location[dir] - locations[i, dir])/             # <<<<<<<<<<<<<<
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:
 */
        __Pyx_TraceLine(5634,0,__PYX_ERR(0, 5634, __pyx_L1_error))
        if (unlikely(__pyx_t_21 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5634, __pyx_L1_error)
        }
        __pyx_v_w1 = (__pyx_t_11 / __pyx_t_21);

        /* "discretize/_extensions/tree_ext.pyx":5636
 *                   w1 = ((f001.location[dir] - locations[i, dir])/
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:             # <<<<<<<<<<<<<<
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/
 *                             (f010.location[dir1] - f000.location[dir1]))
 */
        __Pyx_TraceLine(5636,0,__PYX_ERR(0, 5636, __pyx_L1_error))
        __pyx_t_13 = ((__pyx_v_i00->index != __pyx_v_i01->index) != 0);
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5637
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                             (f010.location[dir1] - f000.location[dir1]))
 *                   else:
 */
          __Pyx_TraceLine(5637,0,__PYX_ERR(0, 5637, __pyx_L1_error))
          __pyx_t_19 = __pyx_v_i;
          __pyx_t_20 = __pyx_v_dir1;
          __pyx_t_12 = -1;
          if (__pyx_t_19 < 0) {
            __pyx_t_19 += __pyx_v_locations.shape[0];
            if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
          } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
          if (__pyx_t_20 < 0) {
            __pyx_t_20 += __pyx_v_locations.shape[1];
            if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
          } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
          if (unlikely(__pyx_t_12 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_12);
            __PYX_ERR(0, 5637, __pyx_L1_error)
          }
          __pyx_t_21 = ((__pyx_v_f010->location[__pyx_v_dir1]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))));

          /* "discretize/_extensions/tree_ext.pyx":5638
 *                   if i00.index != i01.index:
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/
 *                             (f010.location[dir1] - f000.location[dir1]))             # <<<<<<<<<<<<<<
 *                   else:
 *                       w2 = 1.0
 */
          __Pyx_TraceLine(5638,0,__PYX_ERR(0, 5638, __pyx_L1_error))
          __pyx_t_11 = ((__pyx_v_f010->location[__pyx_v_dir1]) - (__pyx_v_f000->location[__pyx_v_dir1]));

          /* "discretize/_extensions/tree_ext.pyx":5637
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                             (f010.location[dir1] - f000.location[dir1]))
 *                   else:
 */
          __Pyx_TraceLine(5637,0,__PYX_ERR(0, 5637, __pyx_L1_error))
          if (unlikely(__pyx_t_11 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 5637, __pyx_L1_error)
          }
          __pyx_v_w2 = (__pyx_t_21 / __pyx_t_11);

          /* "discretize/_extensions/tree_ext.pyx":5636
 *                   w1 = ((f001.location[dir] - locations[i, dir])/
 *                         (f001.location[dir] - f000.location[dir]))
 *                   if i00.index != i01.index:             # <<<<<<<<<<<<<<
 *                       w2 = ((f010.location[dir1] - locations[i, dir1])/
 *                             (f010.location[dir1] - f000.location[dir1]))
 */
          goto __pyx_L40;
        }

        /* "discretize/_extensions/tree_ext.pyx":5640
 *                             (f010.location[dir1] - f000.location[dir1]))
 *                   else:
 *                       w2 = 1.0             # <<<<<<<<<<<<<<
 *                   if i10.index != i00.index:
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/
 */
        __Pyx_TraceLine(5640,0,__PYX_ERR(0, 5640, __pyx_L1_error))
        /*else*/ {
          __pyx_v_w2 = 1.0;
        }
        __pyx_L40:;

        /* "discretize/_extensions/tree_ext.pyx":5641
 *                   else:
 *                       w2 = 1.0
 *                   if i10.index != i00.index:             # <<<<<<<<<<<<<<
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/
 *                             (f100.location[dir2] - f000.location[dir2]))
 */
        __Pyx_TraceLine(5641,0,__PYX_ERR(0, 5641, __pyx_L1_error))
        __pyx_t_13 = ((__pyx_v_i10->index != __pyx_v_i00->index) != 0);
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":5642
 *                       w2 = 1.0
 *                   if i10.index != i00.index:
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                             (f100.location[dir2] - f000.location[dir2]))
 *                   else:
 */
          __Pyx_TraceLine(5642,0,__PYX_ERR(0, 5642, __pyx_L1_error))
          __pyx_t_20 = __pyx_v_i;
          __pyx_t_19 = __pyx_v_dir2;
          __pyx_t_12 = -1;
          if (__pyx_t_20 < 0) {
            __pyx_t_20 += __pyx_v_locations.shape[0];
            if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
          } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
          if (__pyx_t_19 < 0) {
            __pyx_t_19 += __pyx_v_locations.shape[1];
            if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
          } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
          if (unlikely(__pyx_t_12 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_12);
            __PYX_ERR(0, 5642, __pyx_L1_error)
          }
          __pyx_t_11 = ((__pyx_v_f100->location[__pyx_v_dir2]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))));

          /* "discretize/_extensions/tree_ext.pyx":5643
 *                   if i10.index != i00.index:
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/
 *                             (f100.location[dir2] - f000.location[dir2]))             # <<<<<<<<<<<<<<
 *                   else:
 *                       w3 = 1.0
 */
          __Pyx_TraceLine(5643,0,__PYX_ERR(0, 5643, __pyx_L1_error))
          __pyx_t_21 = ((__pyx_v_f100->location[__pyx_v_dir2]) - (__pyx_v_f000->location[__pyx_v_dir2]));

          /* "discretize/_extensions/tree_ext.pyx":5642
 *                       w2 = 1.0
 *                   if i10.index != i00.index:
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                             (f100.location[dir2] - f000.location[dir2]))
 *                   else:
 */
          __Pyx_TraceLine(5642,0,__PYX_ERR(0, 5642, __pyx_L1_error))
          if (unlikely(__pyx_t_21 == 0)) {
            PyErr_SetString(PyExc_ZeroDivisionError, "float division");
            __PYX_ERR(0, 5642, __pyx_L1_error)
          }
          __pyx_v_w3 = (__pyx_t_11 / __pyx_t_21);

          /* "discretize/_extensions/tree_ext.pyx":5641
 *                   else:
 *                       w2 = 1.0
 *                   if i10.index != i00.index:             # <<<<<<<<<<<<<<
 *                       w3 = ((f100.location[dir2] - locations[i, dir2])/
 *                             (f100.location[dir2] - f000.location[dir2]))
 */
          goto __pyx_L41;
        }

        /* "discretize/_extensions/tree_ext.pyx":5645
 *                             (f100.location[dir2] - f000.location[dir2]))
 *                   else:
 *                       w3 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                   w1 = _clip01(w1)
 */
        __Pyx_TraceLine(5645,0,__PYX_ERR(0, 5645, __pyx_L1_error))
        /*else*/ {
          __pyx_v_w3 = 1.0;
        }
        __pyx_L41:;

        /* "discretize/_extensions/tree_ext.pyx":5647
 *                       w3 = 1.0
 * 
 *                   w1 = _clip01(w1)             # <<<<<<<<<<<<<<
 *                   w2 = _clip01(w2)
 *                   w3 = _clip01(w3)
 */
        __Pyx_TraceLine(5647,0,__PYX_ERR(0, 5647, __pyx_L1_error))
        __pyx_v_w1 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w1);

        /* "discretize/_extensions/tree_ext.pyx":5648
 * 
 *                   w1 = _clip01(w1)
 *                   w2 = _clip01(w2)             # <<<<<<<<<<<<<<
 *                   w3 = _clip01(w3)
 * 
 */
        __Pyx_TraceLine(5648,0,__PYX_ERR(0, 5648, __pyx_L1_error))
        __pyx_v_w2 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w2);

        /* "discretize/_extensions/tree_ext.pyx":5649
 *                   w1 = _clip01(w1)
 *                   w2 = _clip01(w2)
 *                   w3 = _clip01(w3)             # <<<<<<<<<<<<<<
 * 
 *                   row_data[0] = w1 * w2 * w3
 */
        __Pyx_TraceLine(5649,0,__PYX_ERR(0, 5649, __pyx_L1_error))
        __pyx_v_w3 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w3);

        /* "discretize/_extensions/tree_ext.pyx":5651
 *                   w3 = _clip01(w3)
 * 
 *                   row_data[0] = w1 * w2 * w3             # <<<<<<<<<<<<<<
 *                   row_data[1] = (1 - w1) * w2 * w3
 *                   row_data[2] = w1 * (1 - w2) * w3
 */
        __Pyx_TraceLine(5651,0,__PYX_ERR(0, 5651, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((__pyx_v_w1 * __pyx_v_w2) * __pyx_v_w3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5651, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 0, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5651, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5652
 * 
 *                   row_data[0] = w1 * w2 * w3
 *                   row_data[1] = (1 - w1) * w2 * w3             # <<<<<<<<<<<<<<
 *                   row_data[2] = w1 * (1 - w2) * w3
 *                   row_data[3] = (1 - w1) * (1 - w2) * w3
 */
        __Pyx_TraceLine(5652,0,__PYX_ERR(0, 5652, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((((1.0 - __pyx_v_w1) * __pyx_v_w2) * __pyx_v_w3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5652, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 1, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5652, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5653
 *                   row_data[0] = w1 * w2 * w3
 *                   row_data[1] = (1 - w1) * w2 * w3
 *                   row_data[2] = w1 * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                   row_data[3] = (1 - w1) * (1 - w2) * w3
 *                   row_data[4] = w1 * w2 * (1 - w3)
 */
        __Pyx_TraceLine(5653,0,__PYX_ERR(0, 5653, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((__pyx_v_w1 * (1.0 - __pyx_v_w2)) * __pyx_v_w3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5653, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 2, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5653, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5654
 *                   row_data[1] = (1 - w1) * w2 * w3
 *                   row_data[2] = w1 * (1 - w2) * w3
 *                   row_data[3] = (1 - w1) * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                   row_data[4] = w1 * w2 * (1 - w3)
 *                   row_data[5] = (1 - w1) * w2 * (1 - w3)
 */
        __Pyx_TraceLine(5654,0,__PYX_ERR(0, 5654, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2)) * __pyx_v_w3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5654, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 3, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5654, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5655
 *                   row_data[2] = w1 * (1 - w2) * w3
 *                   row_data[3] = (1 - w1) * (1 - w2) * w3
 *                   row_data[4] = w1 * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                   row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                   row_data[6] = w1 * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5655,0,__PYX_ERR(0, 5655, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((__pyx_v_w1 * __pyx_v_w2) * (1.0 - __pyx_v_w3))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5655, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 4, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5655, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5656
 *                   row_data[3] = (1 - w1) * (1 - w2) * w3
 *                   row_data[4] = w1 * w2 * (1 - w3)
 *                   row_data[5] = (1 - w1) * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                   row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                   row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5656,0,__PYX_ERR(0, 5656, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((((1.0 - __pyx_v_w1) * __pyx_v_w2) * (1.0 - __pyx_v_w3))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 5, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5656, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5657
 *                   row_data[4] = w1 * w2 * (1 - w3)
 *                   row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                   row_data[6] = w1 * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                   row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                   row_inds[0] = f000.index + offset
 */
        __Pyx_TraceLine(5657,0,__PYX_ERR(0, 5657, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((__pyx_v_w1 * (1.0 - __pyx_v_w2)) * (1.0 - __pyx_v_w3))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5657, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 6, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5657, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5658
 *                   row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                   row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                   row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                   row_inds[0] = f000.index + offset
 *                   row_inds[1] = f001.index + offset
 */
        __Pyx_TraceLine(5658,0,__PYX_ERR(0, 5658, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble((((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2)) * (1.0 - __pyx_v_w3))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5658, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_data, 7, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5658, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5659
 *                   row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                   row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                   row_inds[0] = f000.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[1] = f001.index + offset
 *                   row_inds[2] = f010.index + offset
 */
        __Pyx_TraceLine(5659,0,__PYX_ERR(0, 5659, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f000->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 0, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5659, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5660
 *                   row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                   row_inds[0] = f000.index + offset
 *                   row_inds[1] = f001.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[2] = f010.index + offset
 *                   row_inds[3] = f011.index + offset
 */
        __Pyx_TraceLine(5660,0,__PYX_ERR(0, 5660, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f001->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5660, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 1, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5660, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5661
 *                   row_inds[0] = f000.index + offset
 *                   row_inds[1] = f001.index + offset
 *                   row_inds[2] = f010.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[3] = f011.index + offset
 *                   row_inds[4] = f100.index + offset
 */
        __Pyx_TraceLine(5661,0,__PYX_ERR(0, 5661, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f010->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5661, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 2, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5661, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5662
 *                   row_inds[1] = f001.index + offset
 *                   row_inds[2] = f010.index + offset
 *                   row_inds[3] = f011.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[4] = f100.index + offset
 *                   row_inds[5] = f101.index + offset
 */
        __Pyx_TraceLine(5662,0,__PYX_ERR(0, 5662, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f011->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5662, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 3, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5662, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5663
 *                   row_inds[2] = f010.index + offset
 *                   row_inds[3] = f011.index + offset
 *                   row_inds[4] = f100.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[5] = f101.index + offset
 *                   row_inds[6] = f110.index + offset
 */
        __Pyx_TraceLine(5663,0,__PYX_ERR(0, 5663, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f100->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 4, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5663, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5664
 *                   row_inds[3] = f011.index + offset
 *                   row_inds[4] = f100.index + offset
 *                   row_inds[5] = f101.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[6] = f110.index + offset
 *                   row_inds[7] = f111.index + offset
 */
        __Pyx_TraceLine(5664,0,__PYX_ERR(0, 5664, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f101->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5664, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 5, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5664, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5665
 *                   row_inds[4] = f100.index + offset
 *                   row_inds[5] = f101.index + offset
 *                   row_inds[6] = f110.index + offset             # <<<<<<<<<<<<<<
 *                   row_inds[7] = f111.index + offset
 * 
 */
        __Pyx_TraceLine(5665,0,__PYX_ERR(0, 5665, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f110->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5665, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 6, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5665, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5666
 *                   row_inds[5] = f101.index + offset
 *                   row_inds[6] = f110.index + offset
 *                   row_inds[7] = f111.index + offset             # <<<<<<<<<<<<<<
 * 
 *         Rf = self._deflate_faces()
 */
        __Pyx_TraceLine(5666,0,__PYX_ERR(0, 5666, __pyx_L1_error))
        __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_f111->index + __pyx_v_offset)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5666, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_row_inds, 7, __pyx_t_5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) __PYX_ERR(0, 5666, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_L23:;
    }
    __pyx_L6:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5668
 *                   row_inds[7] = f111.index + offset
 * 
 *         Rf = self._deflate_faces()             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_faces))*Rf
 * 
 */
  __Pyx_TraceLine(5668,0,__PYX_ERR(0, 5668, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_faces); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_Rf = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5669
 * 
 *         Rf = self._deflate_faces()
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_faces))*Rf             # <<<<<<<<<<<<<<
 * 
 *     def _getNodeIntMat(self, locs, zeros_outside):
 */
  __Pyx_TraceLine(5669,0,__PYX_ERR(0, 5669, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_indices, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_indptr, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_3);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_faces); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyNumber_Multiply(__pyx_t_7, __pyx_v_Rf); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5475
 *         return A*Re
 * 
 *     def _getFaceIntMat(self, locs, zeros_outside, direction):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getFaceIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_locations, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indptr, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indices, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_data, 1);
  __Pyx_XDECREF(__pyx_v_row_inds);
  __Pyx_XDECREF(__pyx_v_row_data);
  __Pyx_XDECREF(__pyx_v_Rf);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5671
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_faces))*Rf
 * 
 *     def _getNodeIntMat(self, locs, zeros_outside):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_85_getNodeIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_84_getNodeIntMat[] = "_TreeMesh._getNodeIntMat(self, locs, zeros_outside)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_85_getNodeIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_locs = 0;
  PyObject *__pyx_v_zeros_outside = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getNodeIntMat (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_locs,&__pyx_n_s_zeros_outside,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_locs)) != 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_zeros_outside)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getNodeIntMat", 1, 2, 2, 1); __PYX_ERR(0, 5671, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getNodeIntMat") < 0)) __PYX_ERR(0, 5671, __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_locs = values[0];
    __pyx_v_zeros_outside = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getNodeIntMat", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5671, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getNodeIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_84_getNodeIntMat(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_locs, __pyx_v_zeros_outside);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_84_getNodeIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside) {
  __Pyx_memviewslice __pyx_v_locations = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_dim;
  int_t __pyx_v_n_loc;
  int_t __pyx_v_n_nodes;
  __Pyx_memviewslice __pyx_v_I = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_J = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_V = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_ii;
  int_t __pyx_v_i;
  Cell *__pyx_v_cell;
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  double __pyx_v_wx;
  double __pyx_v_wy;
  double __pyx_v_wz;
  double __pyx_v_eps;
  int __pyx_v_zeros_out;
  PyObject *__pyx_v_Rn = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  double __pyx_t_10;
  int __pyx_t_11;
  int_t __pyx_t_12;
  int_t __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  double __pyx_t_16;
  int __pyx_t_17;
  int __pyx_t_18;
  int_t __pyx_t_19;
  int_t __pyx_t_20;
  int_t __pyx_t_21;
  int_t __pyx_t_22;
  PyObject *__pyx_t_23 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getNodeIntMat", 0);
  __Pyx_TraceCall("_getNodeIntMat", __pyx_f[0], 5671, 0, __PYX_ERR(0, 5671, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5673
 *     def _getNodeIntMat(self, locs, zeros_outside):
 *         cdef:
 *             double[:, :] locations = locs             # <<<<<<<<<<<<<<
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]
 */
  __Pyx_TraceLine(5673,0,__PYX_ERR(0, 5673, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_locs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 5673, __pyx_L1_error)
  __pyx_v_locations = __pyx_t_1;
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5674
 *         cdef:
 *             double[:, :] locations = locs
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             int_t n_loc = locs.shape[0]
 *             int_t n_nodes = 1<<dim
 */
  __Pyx_TraceLine(5674,0,__PYX_ERR(0, 5674, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5675
 *             double[:, :] locations = locs
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]             # <<<<<<<<<<<<<<
 *             int_t n_nodes = 1<<dim
 *             np.int64_t[:] I = np.empty(n_loc*n_nodes, dtype=np.int64)
 */
  __Pyx_TraceLine(5675,0,__PYX_ERR(0, 5675, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5675, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5675, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyInt_As_int_t(__pyx_t_4); if (unlikely((__pyx_t_2 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5675, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_n_loc = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5676
 *             int_t dim = self._dim
 *             int_t n_loc = locs.shape[0]
 *             int_t n_nodes = 1<<dim             # <<<<<<<<<<<<<<
 *             np.int64_t[:] I = np.empty(n_loc*n_nodes, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(n_loc*n_nodes, dtype=np.int64)
 */
  __Pyx_TraceLine(5676,0,__PYX_ERR(0, 5676, __pyx_L1_error))
  __pyx_v_n_nodes = (1 << __pyx_v_dim);

  /* "discretize/_extensions/tree_ext.pyx":5677
 *             int_t n_loc = locs.shape[0]
 *             int_t n_nodes = 1<<dim
 *             np.int64_t[:] I = np.empty(n_loc*n_nodes, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] J = np.empty(n_loc*n_nodes, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(n_loc*n_nodes, dtype=np.float64)
 */
  __Pyx_TraceLine(5677,0,__PYX_ERR(0, 5677, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_n_loc * __pyx_v_n_nodes)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 5677, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_I = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5678
 *             int_t n_nodes = 1<<dim
 *             np.int64_t[:] I = np.empty(n_loc*n_nodes, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(n_loc*n_nodes, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] V = np.empty(n_loc*n_nodes, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5678,0,__PYX_ERR(0, 5678, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From_int_t((__pyx_v_n_loc * __pyx_v_n_nodes)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 5678, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_J = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5679
 *             np.int64_t[:] I = np.empty(n_loc*n_nodes, dtype=np.int64)
 *             np.int64_t[:] J = np.empty(n_loc*n_nodes, dtype=np.int64)
 *             np.float64_t[:] V = np.empty(n_loc*n_nodes, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             int_t ii, i
 */
  __Pyx_TraceLine(5679,0,__PYX_ERR(0, 5679, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int_t((__pyx_v_n_loc * __pyx_v_n_nodes)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5679, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_V = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5685
 *             double x, y, z
 *             double wx, wy, wz
 *             double eps = 100*np.finfo(float).eps             # <<<<<<<<<<<<<<
 *             int zeros_out = zeros_outside
 * 
 */
  __Pyx_TraceLine(5685,0,__PYX_ERR(0, 5685, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_finfo); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, ((PyObject *)(&PyFloat_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)(&PyFloat_Type)));
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_eps); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_int_100, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5685, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_eps = __pyx_t_10;

  /* "discretize/_extensions/tree_ext.pyx":5686
 *             double wx, wy, wz
 *             double eps = 100*np.finfo(float).eps
 *             int zeros_out = zeros_outside             # <<<<<<<<<<<<<<
 * 
 *         for i in range(n_loc):
 */
  __Pyx_TraceLine(5686,0,__PYX_ERR(0, 5686, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_zeros_outside); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5686, __pyx_L1_error)
  __pyx_v_zeros_out = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":5688
 *             int zeros_out = zeros_outside
 * 
 *         for i in range(n_loc):             # <<<<<<<<<<<<<<
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 */
  __Pyx_TraceLine(5688,0,__PYX_ERR(0, 5688, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_n_loc;
  __pyx_t_12 = __pyx_t_2;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_i = __pyx_t_13;

    /* "discretize/_extensions/tree_ext.pyx":5689
 * 
 *         for i in range(n_loc):
 *             x = locations[i, 0]             # <<<<<<<<<<<<<<
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0
 */
    __Pyx_TraceLine(5689,0,__PYX_ERR(0, 5689, __pyx_L1_error))
    __pyx_t_14 = __pyx_v_i;
    __pyx_t_15 = 0;
    __pyx_t_11 = -1;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_locations.shape[0])) __pyx_t_11 = 0;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 1;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[1])) __pyx_t_11 = 1;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5689, __pyx_L1_error)
    }
    __pyx_v_x = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_14 * __pyx_v_locations.strides[0]) ) + __pyx_t_15 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5690
 *         for i in range(n_loc):
 *             x = locations[i, 0]
 *             y = locations[i, 1]             # <<<<<<<<<<<<<<
 *             z = locations[i, 2] if dim==3 else 0.0
 *             #get containing (or closest) cell
 */
    __Pyx_TraceLine(5690,0,__PYX_ERR(0, 5690, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_14 = 1;
    __pyx_t_11 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[0])) __pyx_t_11 = 0;
    if (__pyx_t_14 < 0) {
      __pyx_t_14 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __pyx_t_11 = 1;
    } else if (unlikely(__pyx_t_14 >= __pyx_v_locations.shape[1])) __pyx_t_11 = 1;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5690, __pyx_L1_error)
    }
    __pyx_v_y = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_15 * __pyx_v_locations.strides[0]) ) + __pyx_t_14 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5691
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0             # <<<<<<<<<<<<<<
 *             #get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 */
    __Pyx_TraceLine(5691,0,__PYX_ERR(0, 5691, __pyx_L1_error))
    if (((__pyx_v_dim == 3) != 0)) {
      __pyx_t_14 = __pyx_v_i;
      __pyx_t_15 = 2;
      __pyx_t_11 = -1;
      if (__pyx_t_14 < 0) {
        __pyx_t_14 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_14 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_14 >= __pyx_v_locations.shape[0])) __pyx_t_11 = 0;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 1;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[1])) __pyx_t_11 = 1;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5691, __pyx_L1_error)
      }
      __pyx_t_10 = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_14 * __pyx_v_locations.strides[0]) ) + __pyx_t_15 * __pyx_v_locations.strides[1]) )));
    } else {
      __pyx_t_10 = 0.0;
    }
    __pyx_v_z = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":5693
 *             z = locations[i, 2] if dim==3 else 0.0
 *             #get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)             # <<<<<<<<<<<<<<
 *             #calculate weights
 *             wx = ((cell.points[3].location[0] - x)/
 */
    __Pyx_TraceLine(5693,0,__PYX_ERR(0, 5693, __pyx_L1_error))
    __pyx_v_cell = __pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z);

    /* "discretize/_extensions/tree_ext.pyx":5695
 *             cell = self.tree.containing_cell(x, y, z)
 *             #calculate weights
 *             wx = ((cell.points[3].location[0] - x)/             # <<<<<<<<<<<<<<
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))
 *             wy = ((cell.points[3].location[1] - y)/
 */
    __Pyx_TraceLine(5695,0,__PYX_ERR(0, 5695, __pyx_L1_error))
    __pyx_t_10 = (((__pyx_v_cell->points[3])->location[0]) - __pyx_v_x);

    /* "discretize/_extensions/tree_ext.pyx":5696
 *             #calculate weights
 *             wx = ((cell.points[3].location[0] - x)/
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))             # <<<<<<<<<<<<<<
 *             wy = ((cell.points[3].location[1] - y)/
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 */
    __Pyx_TraceLine(5696,0,__PYX_ERR(0, 5696, __pyx_L1_error))
    __pyx_t_16 = (((__pyx_v_cell->points[3])->location[0]) - ((__pyx_v_cell->points[0])->location[0]));

    /* "discretize/_extensions/tree_ext.pyx":5695
 *             cell = self.tree.containing_cell(x, y, z)
 *             #calculate weights
 *             wx = ((cell.points[3].location[0] - x)/             # <<<<<<<<<<<<<<
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))
 *             wy = ((cell.points[3].location[1] - y)/
 */
    __Pyx_TraceLine(5695,0,__PYX_ERR(0, 5695, __pyx_L1_error))
    if (unlikely(__pyx_t_16 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 5695, __pyx_L1_error)
    }
    __pyx_v_wx = (__pyx_t_10 / __pyx_t_16);

    /* "discretize/_extensions/tree_ext.pyx":5697
 *             wx = ((cell.points[3].location[0] - x)/
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))
 *             wy = ((cell.points[3].location[1] - y)/             # <<<<<<<<<<<<<<
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:
 */
    __Pyx_TraceLine(5697,0,__PYX_ERR(0, 5697, __pyx_L1_error))
    __pyx_t_16 = (((__pyx_v_cell->points[3])->location[1]) - __pyx_v_y);

    /* "discretize/_extensions/tree_ext.pyx":5698
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))
 *             wy = ((cell.points[3].location[1] - y)/
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))             # <<<<<<<<<<<<<<
 *             if dim == 3:
 *                 wz = ((cell.points[7].location[2] - z)/
 */
    __Pyx_TraceLine(5698,0,__PYX_ERR(0, 5698, __pyx_L1_error))
    __pyx_t_10 = (((__pyx_v_cell->points[3])->location[1]) - ((__pyx_v_cell->points[0])->location[1]));

    /* "discretize/_extensions/tree_ext.pyx":5697
 *             wx = ((cell.points[3].location[0] - x)/
 *                   (cell.points[3].location[0] - cell.points[0].location[0]))
 *             wy = ((cell.points[3].location[1] - y)/             # <<<<<<<<<<<<<<
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:
 */
    __Pyx_TraceLine(5697,0,__PYX_ERR(0, 5697, __pyx_L1_error))
    if (unlikely(__pyx_t_10 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 5697, __pyx_L1_error)
    }
    __pyx_v_wy = (__pyx_t_16 / __pyx_t_10);

    /* "discretize/_extensions/tree_ext.pyx":5699
 *             wy = ((cell.points[3].location[1] - y)/
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 wz = ((cell.points[7].location[2] - z)/
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))
 */
    __Pyx_TraceLine(5699,0,__PYX_ERR(0, 5699, __pyx_L1_error))
    __pyx_t_17 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_17) {

      /* "discretize/_extensions/tree_ext.pyx":5700
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:
 *                 wz = ((cell.points[7].location[2] - z)/             # <<<<<<<<<<<<<<
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))
 *             else:
 */
      __Pyx_TraceLine(5700,0,__PYX_ERR(0, 5700, __pyx_L1_error))
      __pyx_t_10 = (((__pyx_v_cell->points[7])->location[2]) - __pyx_v_z);

      /* "discretize/_extensions/tree_ext.pyx":5701
 *             if dim == 3:
 *                 wz = ((cell.points[7].location[2] - z)/
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))             # <<<<<<<<<<<<<<
 *             else:
 *                 wz = 1.0
 */
      __Pyx_TraceLine(5701,0,__PYX_ERR(0, 5701, __pyx_L1_error))
      __pyx_t_16 = (((__pyx_v_cell->points[7])->location[2]) - ((__pyx_v_cell->points[0])->location[2]));

      /* "discretize/_extensions/tree_ext.pyx":5700
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:
 *                 wz = ((cell.points[7].location[2] - z)/             # <<<<<<<<<<<<<<
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))
 *             else:
 */
      __Pyx_TraceLine(5700,0,__PYX_ERR(0, 5700, __pyx_L1_error))
      if (unlikely(__pyx_t_16 == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 5700, __pyx_L1_error)
      }
      __pyx_v_wz = (__pyx_t_10 / __pyx_t_16);

      /* "discretize/_extensions/tree_ext.pyx":5699
 *             wy = ((cell.points[3].location[1] - y)/
 *                   (cell.points[3].location[1] - cell.points[0].location[1]))
 *             if dim == 3:             # <<<<<<<<<<<<<<
 *                 wz = ((cell.points[7].location[2] - z)/
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":5703
 *                       (cell.points[7].location[2] - cell.points[0].location[2]))
 *             else:
 *                 wz = 1.0             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(5703,0,__PYX_ERR(0, 5703, __pyx_L1_error))
    /*else*/ {
      __pyx_v_wz = 1.0;
    }
    __pyx_L5:;

    /* "discretize/_extensions/tree_ext.pyx":5706
 * 
 * 
 *             I[n_nodes*i:n_nodes*i + n_nodes] = i             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(5706,0,__PYX_ERR(0, 5706, __pyx_L1_error))
    __pyx_t_8.data = __pyx_v_I.data;
    __pyx_t_8.memview = __pyx_v_I.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_8, 0);
    __pyx_t_11 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_8,
    __pyx_v_I.shape[0], __pyx_v_I.strides[0], __pyx_v_I.suboffsets[0],
    0,
    0,
    &__pyx_t_11,
    (__pyx_v_n_nodes * __pyx_v_i),
    ((__pyx_v_n_nodes * __pyx_v_i) + __pyx_v_n_nodes),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5706, __pyx_L1_error)
}

{
        __pyx_t_5numpy_int64_t __pyx_temp_scalar = __pyx_v_i;
        {
            Py_ssize_t __pyx_temp_extent_0 = __pyx_t_8.shape[0];
            Py_ssize_t __pyx_temp_stride_0 = __pyx_t_8.strides[0];
            char *__pyx_temp_pointer_0;
            Py_ssize_t __pyx_temp_idx_0;
            __pyx_temp_pointer_0 = __pyx_t_8.data;
            for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
              *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
              __pyx_temp_pointer_0 += __pyx_temp_stride_0;
            }
        }
    }
    __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
    __pyx_t_8.memview = NULL;
    __pyx_t_8.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5709
 * 
 * 
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if (wx < -eps or wy < -eps or wz < -eps or
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 */
    __Pyx_TraceLine(5709,0,__PYX_ERR(0, 5709, __pyx_L1_error))
    __pyx_t_17 = (__pyx_v_zeros_out != 0);
    if (__pyx_t_17) {

      /* "discretize/_extensions/tree_ext.pyx":5710
 * 
 *             if zeros_out:
 *                 if (wx < -eps or wy < -eps or wz < -eps or             # <<<<<<<<<<<<<<
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 *                     for ii in range(n_nodes):
 */
      __Pyx_TraceLine(5710,0,__PYX_ERR(0, 5710, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_wx < (-__pyx_v_eps)) != 0);
      if (!__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_wy < (-__pyx_v_eps)) != 0);
      if (!__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_wz < (-__pyx_v_eps)) != 0);
      if (!__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5711
 *             if zeros_out:
 *                 if (wx < -eps or wy < -eps or wz < -eps or
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):             # <<<<<<<<<<<<<<
 *                     for ii in range(n_nodes):
 *                         J[n_nodes*i + ii] = 0
 */
      __Pyx_TraceLine(5711,0,__PYX_ERR(0, 5711, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_wx > (1.0 + __pyx_v_eps)) != 0);
      if (!__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_wy > (1.0 + __pyx_v_eps)) != 0);
      if (!__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L8_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_wz > (1.0 + __pyx_v_eps)) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L8_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5710
 * 
 *             if zeros_out:
 *                 if (wx < -eps or wy < -eps or wz < -eps or             # <<<<<<<<<<<<<<
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 *                     for ii in range(n_nodes):
 */
      __Pyx_TraceLine(5710,0,__PYX_ERR(0, 5710, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5712
 *                 if (wx < -eps or wy < -eps or wz < -eps or
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 *                     for ii in range(n_nodes):             # <<<<<<<<<<<<<<
 *                         J[n_nodes*i + ii] = 0
 *                         V[n_nodes*i + ii] = 0.0
 */
        __Pyx_TraceLine(5712,0,__PYX_ERR(0, 5712, __pyx_L1_error))
        __pyx_t_19 = __pyx_v_n_nodes;
        __pyx_t_20 = __pyx_t_19;
        for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) {
          __pyx_v_ii = __pyx_t_21;

          /* "discretize/_extensions/tree_ext.pyx":5713
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 *                     for ii in range(n_nodes):
 *                         J[n_nodes*i + ii] = 0             # <<<<<<<<<<<<<<
 *                         V[n_nodes*i + ii] = 0.0
 *                     continue
 */
          __Pyx_TraceLine(5713,0,__PYX_ERR(0, 5713, __pyx_L1_error))
          __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + __pyx_v_ii);
          __pyx_t_11 = -1;
          if (__pyx_t_15 < 0) {
            __pyx_t_15 += __pyx_v_J.shape[0];
            if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_15 >= __pyx_v_J.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 5713, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = 0;

          /* "discretize/_extensions/tree_ext.pyx":5714
 *                     for ii in range(n_nodes):
 *                         J[n_nodes*i + ii] = 0
 *                         V[n_nodes*i + ii] = 0.0             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
          __Pyx_TraceLine(5714,0,__PYX_ERR(0, 5714, __pyx_L1_error))
          __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + __pyx_v_ii);
          __pyx_t_11 = -1;
          if (__pyx_t_15 < 0) {
            __pyx_t_15 += __pyx_v_V.shape[0];
            if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
          } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
          if (unlikely(__pyx_t_11 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_11);
            __PYX_ERR(0, 5714, __pyx_L1_error)
          }
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = 0.0;
        }

        /* "discretize/_extensions/tree_ext.pyx":5715
 *                         J[n_nodes*i + ii] = 0
 *                         V[n_nodes*i + ii] = 0.0
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *             wx = _clip01(wx)
 */
        __Pyx_TraceLine(5715,0,__PYX_ERR(0, 5715, __pyx_L1_error))
        goto __pyx_L3_continue;

        /* "discretize/_extensions/tree_ext.pyx":5710
 * 
 *             if zeros_out:
 *                 if (wx < -eps or wy < -eps or wz < -eps or             # <<<<<<<<<<<<<<
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 *                     for ii in range(n_nodes):
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":5709
 * 
 * 
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if (wx < -eps or wy < -eps or wz < -eps or
 *                     wx>1 + eps or wy > 1 + eps or wz > 1 + eps):
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":5717
 *                     continue
 * 
 *             wx = _clip01(wx)             # <<<<<<<<<<<<<<
 *             wy = _clip01(wy)
 *             wz = _clip01(wz)
 */
    __Pyx_TraceLine(5717,0,__PYX_ERR(0, 5717, __pyx_L1_error))
    __pyx_v_wx = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_wx);

    /* "discretize/_extensions/tree_ext.pyx":5718
 * 
 *             wx = _clip01(wx)
 *             wy = _clip01(wy)             # <<<<<<<<<<<<<<
 *             wz = _clip01(wz)
 *             for ii in range(n_nodes):
 */
    __Pyx_TraceLine(5718,0,__PYX_ERR(0, 5718, __pyx_L1_error))
    __pyx_v_wy = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_wy);

    /* "discretize/_extensions/tree_ext.pyx":5719
 *             wx = _clip01(wx)
 *             wy = _clip01(wy)
 *             wz = _clip01(wz)             # <<<<<<<<<<<<<<
 *             for ii in range(n_nodes):
 *                 J[n_nodes*i + ii] = cell.points[ii].index
 */
    __Pyx_TraceLine(5719,0,__PYX_ERR(0, 5719, __pyx_L1_error))
    __pyx_v_wz = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_wz);

    /* "discretize/_extensions/tree_ext.pyx":5720
 *             wy = _clip01(wy)
 *             wz = _clip01(wz)
 *             for ii in range(n_nodes):             # <<<<<<<<<<<<<<
 *                 J[n_nodes*i + ii] = cell.points[ii].index
 * 
 */
    __Pyx_TraceLine(5720,0,__PYX_ERR(0, 5720, __pyx_L1_error))
    __pyx_t_19 = __pyx_v_n_nodes;
    __pyx_t_20 = __pyx_t_19;
    for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) {
      __pyx_v_ii = __pyx_t_21;

      /* "discretize/_extensions/tree_ext.pyx":5721
 *             wz = _clip01(wz)
 *             for ii in range(n_nodes):
 *                 J[n_nodes*i + ii] = cell.points[ii].index             # <<<<<<<<<<<<<<
 * 
 *             V[n_nodes*i    ] = wx*wy*wz
 */
      __Pyx_TraceLine(5721,0,__PYX_ERR(0, 5721, __pyx_L1_error))
      __pyx_t_22 = (__pyx_v_cell->points[__pyx_v_ii])->index;
      __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + __pyx_v_ii);
      __pyx_t_11 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_J.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_J.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5721, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_J.data + __pyx_t_15 * __pyx_v_J.strides[0]) )) = __pyx_t_22;
    }

    /* "discretize/_extensions/tree_ext.pyx":5723
 *                 J[n_nodes*i + ii] = cell.points[ii].index
 * 
 *             V[n_nodes*i    ] = wx*wy*wz             # <<<<<<<<<<<<<<
 *             V[n_nodes*i + 1] = (1 - wx)*wy*wz
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz
 */
    __Pyx_TraceLine(5723,0,__PYX_ERR(0, 5723, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_n_nodes * __pyx_v_i);
    __pyx_t_11 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_V.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5723, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((__pyx_v_wx * __pyx_v_wy) * __pyx_v_wz);

    /* "discretize/_extensions/tree_ext.pyx":5724
 * 
 *             V[n_nodes*i    ] = wx*wy*wz
 *             V[n_nodes*i + 1] = (1 - wx)*wy*wz             # <<<<<<<<<<<<<<
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz
 */
    __Pyx_TraceLine(5724,0,__PYX_ERR(0, 5724, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 1);
    __pyx_t_11 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_V.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5724, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (((1.0 - __pyx_v_wx) * __pyx_v_wy) * __pyx_v_wz);

    /* "discretize/_extensions/tree_ext.pyx":5725
 *             V[n_nodes*i    ] = wx*wy*wz
 *             V[n_nodes*i + 1] = (1 - wx)*wy*wz
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz             # <<<<<<<<<<<<<<
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz
 *             if dim==3:
 */
    __Pyx_TraceLine(5725,0,__PYX_ERR(0, 5725, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 2);
    __pyx_t_11 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_V.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5725, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((__pyx_v_wx * (1.0 - __pyx_v_wy)) * __pyx_v_wz);

    /* "discretize/_extensions/tree_ext.pyx":5726
 *             V[n_nodes*i + 1] = (1 - wx)*wy*wz
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz             # <<<<<<<<<<<<<<
 *             if dim==3:
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)
 */
    __Pyx_TraceLine(5726,0,__PYX_ERR(0, 5726, __pyx_L1_error))
    __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 3);
    __pyx_t_11 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_V.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
    if (unlikely(__pyx_t_11 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_11);
      __PYX_ERR(0, 5726, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (((1.0 - __pyx_v_wx) * (1.0 - __pyx_v_wy)) * __pyx_v_wz);

    /* "discretize/_extensions/tree_ext.pyx":5727
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz
 *             if dim==3:             # <<<<<<<<<<<<<<
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)
 */
    __Pyx_TraceLine(5727,0,__PYX_ERR(0, 5727, __pyx_L1_error))
    __pyx_t_17 = ((__pyx_v_dim == 3) != 0);
    if (__pyx_t_17) {

      /* "discretize/_extensions/tree_ext.pyx":5728
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz
 *             if dim==3:
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)             # <<<<<<<<<<<<<<
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)
 *                 V[n_nodes*i + 6] = wx*(1 - wy)*(1 - wz)
 */
      __Pyx_TraceLine(5728,0,__PYX_ERR(0, 5728, __pyx_L1_error))
      __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 4);
      __pyx_t_11 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5728, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((__pyx_v_wx * __pyx_v_wy) * (1.0 - __pyx_v_wz));

      /* "discretize/_extensions/tree_ext.pyx":5729
 *             if dim==3:
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)             # <<<<<<<<<<<<<<
 *                 V[n_nodes*i + 6] = wx*(1 - wy)*(1 - wz)
 *                 V[n_nodes*i + 7] = (1 - wx)*(1 - wy)*(1 - wz)
 */
      __Pyx_TraceLine(5729,0,__PYX_ERR(0, 5729, __pyx_L1_error))
      __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 5);
      __pyx_t_11 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5729, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (((1.0 - __pyx_v_wx) * __pyx_v_wy) * (1.0 - __pyx_v_wz));

      /* "discretize/_extensions/tree_ext.pyx":5730
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)
 *                 V[n_nodes*i + 6] = wx*(1 - wy)*(1 - wz)             # <<<<<<<<<<<<<<
 *                 V[n_nodes*i + 7] = (1 - wx)*(1 - wy)*(1 - wz)
 * 
 */
      __Pyx_TraceLine(5730,0,__PYX_ERR(0, 5730, __pyx_L1_error))
      __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 6);
      __pyx_t_11 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5730, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = ((__pyx_v_wx * (1.0 - __pyx_v_wy)) * (1.0 - __pyx_v_wz));

      /* "discretize/_extensions/tree_ext.pyx":5731
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)
 *                 V[n_nodes*i + 6] = wx*(1 - wy)*(1 - wz)
 *                 V[n_nodes*i + 7] = (1 - wx)*(1 - wy)*(1 - wz)             # <<<<<<<<<<<<<<
 * 
 *         Rn = self._deflate_nodes()
 */
      __Pyx_TraceLine(5731,0,__PYX_ERR(0, 5731, __pyx_L1_error))
      __pyx_t_15 = ((__pyx_v_n_nodes * __pyx_v_i) + 7);
      __pyx_t_11 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_V.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_11 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_V.shape[0])) __pyx_t_11 = 0;
      if (unlikely(__pyx_t_11 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_11);
        __PYX_ERR(0, 5731, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_V.data + __pyx_t_15 * __pyx_v_V.strides[0]) )) = (((1.0 - __pyx_v_wx) * (1.0 - __pyx_v_wy)) * (1.0 - __pyx_v_wz));

      /* "discretize/_extensions/tree_ext.pyx":5727
 *             V[n_nodes*i + 2] = wx*(1 - wy)*wz
 *             V[n_nodes*i + 3] = (1 - wx)*(1 - wy)*wz
 *             if dim==3:             # <<<<<<<<<<<<<<
 *                 V[n_nodes*i + 4] = wx*wy*(1 - wz)
 *                 V[n_nodes*i + 5] = (1 - wx)*wy*(1 - wz)
 */
    }
    __pyx_L3_continue:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5733
 *                 V[n_nodes*i + 7] = (1 - wx)*(1 - wy)*(1 - wz)
 * 
 *         Rn = self._deflate_nodes()             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((V, (I, J)), shape=(locs.shape[0],self.n_total_nodes))*Rn
 * 
 */
  __Pyx_TraceLine(5733,0,__PYX_ERR(0, 5733, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_deflate_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5733, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5733, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_Rn = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5734
 * 
 *         Rn = self._deflate_nodes()
 *         return sp.csr_matrix((V, (I, J)), shape=(locs.shape[0],self.n_total_nodes))*Rn             # <<<<<<<<<<<<<<
 * 
 *     def _getCellIntMat(self, locs, zeros_outside):
 */
  __Pyx_TraceLine(5734,0,__PYX_ERR(0, 5734, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_sp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_V, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_I, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __pyx_memoryview_fromslice(__pyx_v_J, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_nodes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_23 = PyTuple_New(2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_23);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_23, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_23, 1, __pyx_t_3);
  __pyx_t_6 = 0;
  __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_shape, __pyx_t_23) < 0) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
  __pyx_t_23 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_23);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Multiply(__pyx_t_23, __pyx_v_Rn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5734, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5671
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0], self.n_total_faces))*Rf
 * 
 *     def _getNodeIntMat(self, locs, zeros_outside):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_23);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getNodeIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_locations, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_I, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_J, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_V, 1);
  __Pyx_XDECREF(__pyx_v_Rn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5736
 *         return sp.csr_matrix((V, (I, J)), shape=(locs.shape[0],self.n_total_nodes))*Rn
 * 
 *     def _getCellIntMat(self, locs, zeros_outside):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_87_getCellIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_86_getCellIntMat[] = "_TreeMesh._getCellIntMat(self, locs, zeros_outside)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_87_getCellIntMat(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_locs = 0;
  PyObject *__pyx_v_zeros_outside = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getCellIntMat (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_locs,&__pyx_n_s_zeros_outside,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_locs)) != 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_zeros_outside)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getCellIntMat", 1, 2, 2, 1); __PYX_ERR(0, 5736, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getCellIntMat") < 0)) __PYX_ERR(0, 5736, __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_locs = values[0];
    __pyx_v_zeros_outside = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getCellIntMat", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 5736, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getCellIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_86_getCellIntMat(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_locs, __pyx_v_zeros_outside);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_86_getCellIntMat(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_locs, PyObject *__pyx_v_zeros_outside) {
  __Pyx_memviewslice __pyx_v_locations = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_dim;
  int_t __pyx_v_dir0;
  int_t __pyx_v_dir1;
  int_t __pyx_v_dir2;
  int_t __pyx_v_temp;
  int_t __pyx_v_n_loc;
  int_t __pyx_v_n_cells;
  __Pyx_memviewslice __pyx_v_indptr = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_indices = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_data = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_row_inds = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_row_data = { 0, 0, { 0 }, { 0 }, { 0 } };
  __pyx_t_5numpy_float64_t __pyx_v_w1;
  __pyx_t_5numpy_float64_t __pyx_v_w2;
  int_t __pyx_v_i;
  Cell *__pyx_v_i000;
  Cell *__pyx_v_i001;
  Cell *__pyx_v_i010;
  Cell *__pyx_v_i011;
  Cell *__pyx_v_i100;
  Cell *__pyx_v_i101;
  Cell *__pyx_v_i110;
  Cell *__pyx_v_i111;
  Cell *__pyx_v_cell;
  double __pyx_v_x;
  double __pyx_v_y;
  double __pyx_v_z;
  double __pyx_v_eps;
  int __pyx_v_zeros_out;
  PyObject *__pyx_v_w3 = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } };
  double __pyx_t_11;
  int __pyx_t_12;
  int_t __pyx_t_13;
  int_t __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  int __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  Py_ssize_t __pyx_t_20;
  double __pyx_t_21;
  __pyx_t_5numpy_float64_t __pyx_t_22;
  PY_LONG_LONG __pyx_t_23;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getCellIntMat", 0);
  __Pyx_TraceCall("_getCellIntMat", __pyx_f[0], 5736, 0, __PYX_ERR(0, 5736, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5738
 *     def _getCellIntMat(self, locs, zeros_outside):
 *         cdef:
 *             double[:, :] locations = locs             # <<<<<<<<<<<<<<
 *             int_t dim = self._dim
 *             int_t dir0, dir1, dir2, temp
 */
  __Pyx_TraceLine(5738,0,__PYX_ERR(0, 5738, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_locs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 5738, __pyx_L1_error)
  __pyx_v_locations = __pyx_t_1;
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5739
 *         cdef:
 *             double[:, :] locations = locs
 *             int_t dim = self._dim             # <<<<<<<<<<<<<<
 *             int_t dir0, dir1, dir2, temp
 *             int_t n_loc = locations.shape[0]
 */
  __Pyx_TraceLine(5739,0,__PYX_ERR(0, 5739, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5741
 *             int_t dim = self._dim
 *             int_t dir0, dir1, dir2, temp
 *             int_t n_loc = locations.shape[0]             # <<<<<<<<<<<<<<
 *             int_t n_cells = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_cells * np.arange(n_loc+1, dtype=np.int64)
 */
  __Pyx_TraceLine(5741,0,__PYX_ERR(0, 5741, __pyx_L1_error))
  __pyx_v_n_loc = (__pyx_v_locations.shape[0]);

  /* "discretize/_extensions/tree_ext.pyx":5742
 *             int_t dir0, dir1, dir2, temp
 *             int_t n_loc = locations.shape[0]
 *             int_t n_cells = 4 if dim == 2 else 8             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indptr = n_cells * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_cells * n_loc, dtype=np.int64)
 */
  __Pyx_TraceLine(5742,0,__PYX_ERR(0, 5742, __pyx_L1_error))
  if (((__pyx_v_dim == 2) != 0)) {
    __pyx_t_2 = 4;
  } else {
    __pyx_t_2 = 8;
  }
  __pyx_v_n_cells = __pyx_t_2;

  /* "discretize/_extensions/tree_ext.pyx":5743
 *             int_t n_loc = locations.shape[0]
 *             int_t n_cells = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_cells * np.arange(n_loc+1, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.int64_t[:] indices = np.empty(n_cells * n_loc, dtype=np.int64)
 *             np.float64_t[:] data = np.ones(n_cells * n_loc, dtype=np.float64)
 */
  __Pyx_TraceLine(5743,0,__PYX_ERR(0, 5743, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyInt_From_int_t(__pyx_v_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_arange); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_n_loc + 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5743, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_indptr = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5744
 *             int_t n_cells = 4 if dim == 2 else 8
 *             np.int64_t[:] indptr = n_cells * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_cells * n_loc, dtype=np.int64)             # <<<<<<<<<<<<<<
 *             np.float64_t[:] data = np.ones(n_cells * n_loc, dtype=np.float64)
 * 
 */
  __Pyx_TraceLine(5744,0,__PYX_ERR(0, 5744, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_int_t((__pyx_v_n_cells * __pyx_v_n_loc)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 5744, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_indices = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5745
 *             np.int64_t[:] indptr = n_cells * np.arange(n_loc+1, dtype=np.int64)
 *             np.int64_t[:] indices = np.empty(n_cells * n_loc, dtype=np.int64)
 *             np.float64_t[:] data = np.ones(n_cells * n_loc, dtype=np.float64)             # <<<<<<<<<<<<<<
 * 
 *             np.int64_t[:] row_inds
 */
  __Pyx_TraceLine(5745,0,__PYX_ERR(0, 5745, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ones); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_n_cells * __pyx_v_n_loc)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 5745, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_data = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5755
 *             c_Cell *cell
 *             double x, y, z
 *             double eps = 100*np.finfo(float).eps             # <<<<<<<<<<<<<<
 *             int zeros_out = zeros_outside
 * 
 */
  __Pyx_TraceLine(5755,0,__PYX_ERR(0, 5755, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_finfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, ((PyObject *)(&PyFloat_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)(&PyFloat_Type)));
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_eps); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Multiply(__pyx_int_100, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5755, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_eps = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":5756
 *             double x, y, z
 *             double eps = 100*np.finfo(float).eps
 *             int zeros_out = zeros_outside             # <<<<<<<<<<<<<<
 * 
 *         dir0 = 0
 */
  __Pyx_TraceLine(5756,0,__PYX_ERR(0, 5756, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_v_zeros_outside); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 5756, __pyx_L1_error)
  __pyx_v_zeros_out = __pyx_t_12;

  /* "discretize/_extensions/tree_ext.pyx":5758
 *             int zeros_out = zeros_outside
 * 
 *         dir0 = 0             # <<<<<<<<<<<<<<
 *         dir1 = 1
 *         dir2 = 2
 */
  __Pyx_TraceLine(5758,0,__PYX_ERR(0, 5758, __pyx_L1_error))
  __pyx_v_dir0 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5759
 * 
 *         dir0 = 0
 *         dir1 = 1             # <<<<<<<<<<<<<<
 *         dir2 = 2
 * 
 */
  __Pyx_TraceLine(5759,0,__PYX_ERR(0, 5759, __pyx_L1_error))
  __pyx_v_dir1 = 1;

  /* "discretize/_extensions/tree_ext.pyx":5760
 *         dir0 = 0
 *         dir1 = 1
 *         dir2 = 2             # <<<<<<<<<<<<<<
 * 
 *         for i in range(n_loc):
 */
  __Pyx_TraceLine(5760,0,__PYX_ERR(0, 5760, __pyx_L1_error))
  __pyx_v_dir2 = 2;

  /* "discretize/_extensions/tree_ext.pyx":5762
 *         dir2 = 2
 * 
 *         for i in range(n_loc):             # <<<<<<<<<<<<<<
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 */
  __Pyx_TraceLine(5762,0,__PYX_ERR(0, 5762, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_n_loc;
  __pyx_t_13 = __pyx_t_2;
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_i = __pyx_t_14;

    /* "discretize/_extensions/tree_ext.pyx":5763
 * 
 *         for i in range(n_loc):
 *             x = locations[i, 0]             # <<<<<<<<<<<<<<
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0
 */
    __Pyx_TraceLine(5763,0,__PYX_ERR(0, 5763, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_16 = 0;
    __pyx_t_12 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5763, __pyx_L1_error)
    }
    __pyx_v_x = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_15 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5764
 *         for i in range(n_loc):
 *             x = locations[i, 0]
 *             y = locations[i, 1]             # <<<<<<<<<<<<<<
 *             z = locations[i, 2] if dim==3 else 0.0
 *             # get containing (or closest) cell
 */
    __Pyx_TraceLine(5764,0,__PYX_ERR(0, 5764, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_15 = 1;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_locations.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_locations.shape[1];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 1;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5764, __pyx_L1_error)
    }
    __pyx_v_y = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_15 * __pyx_v_locations.strides[1]) )));

    /* "discretize/_extensions/tree_ext.pyx":5765
 *             x = locations[i, 0]
 *             y = locations[i, 1]
 *             z = locations[i, 2] if dim==3 else 0.0             # <<<<<<<<<<<<<<
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 */
    __Pyx_TraceLine(5765,0,__PYX_ERR(0, 5765, __pyx_L1_error))
    if (((__pyx_v_dim == 3) != 0)) {
      __pyx_t_15 = __pyx_v_i;
      __pyx_t_16 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5765, __pyx_L1_error)
      }
      __pyx_t_11 = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_15 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) )));
    } else {
      __pyx_t_11 = 0.0;
    }
    __pyx_v_z = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5767
 *             z = locations[i, 2] if dim==3 else 0.0
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)             # <<<<<<<<<<<<<<
 *             row_inds = indices[indptr[i]:indptr[i + 1]]
 *             row_data = data[indptr[i]:indptr[i + 1]]
 */
    __Pyx_TraceLine(5767,0,__PYX_ERR(0, 5767, __pyx_L1_error))
    __pyx_v_cell = __pyx_v_self->tree->containing_cell(__pyx_v_x, __pyx_v_y, __pyx_v_z);

    /* "discretize/_extensions/tree_ext.pyx":5768
 *             # get containing (or closest) cell
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i + 1]]             # <<<<<<<<<<<<<<
 *             row_data = data[indptr[i]:indptr[i + 1]]
 *             if zeros_out:
 */
    __Pyx_TraceLine(5768,0,__PYX_ERR(0, 5768, __pyx_L1_error))
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5768, __pyx_L1_error)
    }
    __pyx_t_15 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5768, __pyx_L1_error)
    }
    __pyx_t_9.data = __pyx_v_indices.data;
    __pyx_t_9.memview = __pyx_v_indices.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_9,
    __pyx_v_indices.shape[0], __pyx_v_indices.strides[0], __pyx_v_indices.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_15 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5768, __pyx_L1_error)
}

__PYX_XDEC_MEMVIEW(&__pyx_v_row_inds, 1);
    __pyx_v_row_inds = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5769
 *             cell = self.tree.containing_cell(x, y, z)
 *             row_inds = indices[indptr[i]:indptr[i + 1]]
 *             row_data = data[indptr[i]:indptr[i + 1]]             # <<<<<<<<<<<<<<
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 */
    __Pyx_TraceLine(5769,0,__PYX_ERR(0, 5769, __pyx_L1_error))
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_12 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5769, __pyx_L1_error)
    }
    __pyx_t_16 = (__pyx_v_i + 1);
    __pyx_t_12 = -1;
    if (__pyx_t_16 < 0) {
      __pyx_t_16 += __pyx_v_indptr.shape[0];
      if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_16 >= __pyx_v_indptr.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 5769, __pyx_L1_error)
    }
    __pyx_t_10.data = __pyx_v_data.data;
    __pyx_t_10.memview = __pyx_v_data.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_10, 0);
    __pyx_t_12 = -1;
    if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_10,
    __pyx_v_data.shape[0], __pyx_v_data.strides[0], __pyx_v_data.suboffsets[0],
    0,
    0,
    &__pyx_t_12,
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_15 * __pyx_v_indptr.strides[0]) ))),
    (*((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_16 * __pyx_v_indptr.strides[0]) ))),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 5769, __pyx_L1_error)
}

__PYX_XDEC_MEMVIEW(&__pyx_v_row_data, 1);
    __pyx_v_row_data = __pyx_t_10;
    __pyx_t_10.memview = NULL;
    __pyx_t_10.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":5770
 *             row_inds = indices[indptr[i]:indptr[i + 1]]
 *             row_data = data[indptr[i]:indptr[i + 1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
    __Pyx_TraceLine(5770,0,__PYX_ERR(0, 5770, __pyx_L1_error))
    __pyx_t_17 = (__pyx_v_zeros_out != 0);
    if (__pyx_t_17) {

      /* "discretize/_extensions/tree_ext.pyx":5771
 *             row_data = data[indptr[i]:indptr[i + 1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5771,0,__PYX_ERR(0, 5771, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_x < (((__pyx_v_cell->points[0])->location[0]) - __pyx_v_eps)) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5772
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 */
        __Pyx_TraceLine(5772,0,__PYX_ERR(0, 5772, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5773
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5773,0,__PYX_ERR(0, 5773, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5771
 *             row_data = data[indptr[i]:indptr[i + 1]]
 *             if zeros_out:
 *                 if x < cell.points[0].location[0]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":5774
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5774,0,__PYX_ERR(0, 5774, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_x > (((__pyx_v_cell->points[3])->location[0]) + __pyx_v_eps)) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5775
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 */
        __Pyx_TraceLine(5775,0,__PYX_ERR(0, 5775, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5776
 *                 elif x > cell.points[3].location[0]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5776,0,__PYX_ERR(0, 5776, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5774
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif x > cell.points[3].location[0]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":5777
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5777,0,__PYX_ERR(0, 5777, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_y < (((__pyx_v_cell->points[0])->location[1]) - __pyx_v_eps)) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5778
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 */
        __Pyx_TraceLine(5778,0,__PYX_ERR(0, 5778, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5779
 *                 elif y < cell.points[0].location[1]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5779,0,__PYX_ERR(0, 5779, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5777
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y < cell.points[0].location[1]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":5780
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5780,0,__PYX_ERR(0, 5780, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_y > (((__pyx_v_cell->points[3])->location[1]) + __pyx_v_eps)) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5781
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 */
        __Pyx_TraceLine(5781,0,__PYX_ERR(0, 5781, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5782
 *                 elif y > cell.points[3].location[1]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5782,0,__PYX_ERR(0, 5782, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5780
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif y > cell.points[3].location[1]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":5783
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5783,0,__PYX_ERR(0, 5783, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z < (((__pyx_v_cell->points[0])->location[2]) - __pyx_v_eps)) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L7_bool_binop_done:;
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5784
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 */
        __Pyx_TraceLine(5784,0,__PYX_ERR(0, 5784, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5785
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 */
        __Pyx_TraceLine(5785,0,__PYX_ERR(0, 5785, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5783
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z < cell.points[0].location[2]-eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
        goto __pyx_L6;
      }

      /* "discretize/_extensions/tree_ext.pyx":5786
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      __Pyx_TraceLine(5786,0,__PYX_ERR(0, 5786, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_z > (((__pyx_v_cell->points[7])->location[2]) + __pyx_v_eps)) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L9_bool_binop_done:;
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5787
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0             # <<<<<<<<<<<<<<
 *                     row_inds[:] = 0
 *             else:
 */
        __Pyx_TraceLine(5787,0,__PYX_ERR(0, 5787, __pyx_L1_error))
        {
            __pyx_t_5numpy_float64_t __pyx_temp_scalar = 0.0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_data.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_data.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_data.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_float64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5788
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 # decide order to search based on distance to each faces
 */
        __Pyx_TraceLine(5788,0,__PYX_ERR(0, 5788, __pyx_L1_error))
        {
            __pyx_t_5numpy_int64_t __pyx_temp_scalar = 0;
            {
                Py_ssize_t __pyx_temp_extent_0 = __pyx_v_row_inds.shape[0];
                Py_ssize_t __pyx_temp_stride_0 = __pyx_v_row_inds.strides[0];
                char *__pyx_temp_pointer_0;
                Py_ssize_t __pyx_temp_idx_0;
                __pyx_temp_pointer_0 = __pyx_v_row_inds.data;
                for (__pyx_temp_idx_0 = 0; __pyx_temp_idx_0 < __pyx_temp_extent_0; __pyx_temp_idx_0++) {
                  *((__pyx_t_5numpy_int64_t *) __pyx_temp_pointer_0) = __pyx_temp_scalar;
                  __pyx_temp_pointer_0 += __pyx_temp_stride_0;
                }
            }
        }

        /* "discretize/_extensions/tree_ext.pyx":5786
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 *                 elif dim == 3 and z > cell.points[7].location[2]+eps:             # <<<<<<<<<<<<<<
 *                     row_data[:] = 0.0
 *                     row_inds[:] = 0
 */
      }
      __pyx_L6:;

      /* "discretize/_extensions/tree_ext.pyx":5770
 *             row_inds = indices[indptr[i]:indptr[i + 1]]
 *             row_data = data[indptr[i]:indptr[i + 1]]
 *             if zeros_out:             # <<<<<<<<<<<<<<
 *                 if x < cell.points[0].location[0]-eps:
 *                     row_data[:] = 0.0
 */
      goto __pyx_L5;
    }

    /* "discretize/_extensions/tree_ext.pyx":5792
 *                 # decide order to search based on distance to each faces
 *                 #
 *                 if (             # <<<<<<<<<<<<<<
 *                     abs(locations[i, dir0] - cell.location[dir0]) <
 *                     abs(locations[i, dir1] - cell.location[dir1])
 */
    __Pyx_TraceLine(5792,0,__PYX_ERR(0, 5792, __pyx_L1_error))
    /*else*/ {

      /* "discretize/_extensions/tree_ext.pyx":5793
 *                 #
 *                 if (
 *                     abs(locations[i, dir0] - cell.location[dir0]) <             # <<<<<<<<<<<<<<
 *                     abs(locations[i, dir1] - cell.location[dir1])
 *                 ):
 */
      __Pyx_TraceLine(5793,0,__PYX_ERR(0, 5793, __pyx_L1_error))
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_15 = __pyx_v_dir0;
      __pyx_t_12 = -1;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5793, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":5794
 *                 if (
 *                     abs(locations[i, dir0] - cell.location[dir0]) <
 *                     abs(locations[i, dir1] - cell.location[dir1])             # <<<<<<<<<<<<<<
 *                 ):
 *                     temp = dir0
 */
      __Pyx_TraceLine(5794,0,__PYX_ERR(0, 5794, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5794, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":5793
 *                 #
 *                 if (
 *                     abs(locations[i, dir0] - cell.location[dir0]) <             # <<<<<<<<<<<<<<
 *                     abs(locations[i, dir1] - cell.location[dir1])
 *                 ):
 */
      __Pyx_TraceLine(5793,0,__PYX_ERR(0, 5793, __pyx_L1_error))
      __pyx_t_17 = ((fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_15 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir0]))) < fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir1])))) != 0);

      /* "discretize/_extensions/tree_ext.pyx":5792
 *                 # decide order to search based on distance to each faces
 *                 #
 *                 if (             # <<<<<<<<<<<<<<
 *                     abs(locations[i, dir0] - cell.location[dir0]) <
 *                     abs(locations[i, dir1] - cell.location[dir1])
 */
      __Pyx_TraceLine(5792,0,__PYX_ERR(0, 5792, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5796
 *                     abs(locations[i, dir1] - cell.location[dir1])
 *                 ):
 *                     temp = dir0             # <<<<<<<<<<<<<<
 *                     dir0 = dir1
 *                     dir1 = temp
 */
        __Pyx_TraceLine(5796,0,__PYX_ERR(0, 5796, __pyx_L1_error))
        __pyx_v_temp = __pyx_v_dir0;

        /* "discretize/_extensions/tree_ext.pyx":5797
 *                 ):
 *                     temp = dir0
 *                     dir0 = dir1             # <<<<<<<<<<<<<<
 *                     dir1 = temp
 *                 if dim == 3:
 */
        __Pyx_TraceLine(5797,0,__PYX_ERR(0, 5797, __pyx_L1_error))
        __pyx_v_dir0 = __pyx_v_dir1;

        /* "discretize/_extensions/tree_ext.pyx":5798
 *                     temp = dir0
 *                     dir0 = dir1
 *                     dir1 = temp             # <<<<<<<<<<<<<<
 *                 if dim == 3:
 *                     if (
 */
        __Pyx_TraceLine(5798,0,__PYX_ERR(0, 5798, __pyx_L1_error))
        __pyx_v_dir1 = __pyx_v_temp;

        /* "discretize/_extensions/tree_ext.pyx":5792
 *                 # decide order to search based on distance to each faces
 *                 #
 *                 if (             # <<<<<<<<<<<<<<
 *                     abs(locations[i, dir0] - cell.location[dir0]) <
 *                     abs(locations[i, dir1] - cell.location[dir1])
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":5799
 *                     dir0 = dir1
 *                     dir1 = temp
 *                 if dim == 3:             # <<<<<<<<<<<<<<
 *                     if (
 *                         abs(locations[i, dir1] - cell.location[dir1]) <
 */
      __Pyx_TraceLine(5799,0,__PYX_ERR(0, 5799, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5801
 *                 if dim == 3:
 *                     if (
 *                         abs(locations[i, dir1] - cell.location[dir1]) <             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir2] - cell.location[dir2])
 *                     ):
 */
        __Pyx_TraceLine(5801,0,__PYX_ERR(0, 5801, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir1;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5801, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5802
 *                     if (
 *                         abs(locations[i, dir1] - cell.location[dir1]) <
 *                         abs(locations[i, dir2] - cell.location[dir2])             # <<<<<<<<<<<<<<
 *                     ):
 *                         temp = dir1
 */
        __Pyx_TraceLine(5802,0,__PYX_ERR(0, 5802, __pyx_L1_error))
        __pyx_t_15 = __pyx_v_i;
        __pyx_t_16 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_15 < 0) {
          __pyx_t_15 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5802, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5801
 *                 if dim == 3:
 *                     if (
 *                         abs(locations[i, dir1] - cell.location[dir1]) <             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir2] - cell.location[dir2])
 *                     ):
 */
        __Pyx_TraceLine(5801,0,__PYX_ERR(0, 5801, __pyx_L1_error))
        __pyx_t_17 = ((fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir1]))) < fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_15 * __pyx_v_locations.strides[0]) ) + __pyx_t_16 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir2])))) != 0);

        /* "discretize/_extensions/tree_ext.pyx":5800
 *                     dir1 = temp
 *                 if dim == 3:
 *                     if (             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir1] - cell.location[dir1]) <
 *                         abs(locations[i, dir2] - cell.location[dir2])
 */
        __Pyx_TraceLine(5800,0,__PYX_ERR(0, 5800, __pyx_L1_error))
        if (__pyx_t_17) {

          /* "discretize/_extensions/tree_ext.pyx":5804
 *                         abs(locations[i, dir2] - cell.location[dir2])
 *                     ):
 *                         temp = dir1             # <<<<<<<<<<<<<<
 *                         dir1 = dir2
 *                         dir2 = temp
 */
          __Pyx_TraceLine(5804,0,__PYX_ERR(0, 5804, __pyx_L1_error))
          __pyx_v_temp = __pyx_v_dir1;

          /* "discretize/_extensions/tree_ext.pyx":5805
 *                     ):
 *                         temp = dir1
 *                         dir1 = dir2             # <<<<<<<<<<<<<<
 *                         dir2 = temp
 *                     if (
 */
          __Pyx_TraceLine(5805,0,__PYX_ERR(0, 5805, __pyx_L1_error))
          __pyx_v_dir1 = __pyx_v_dir2;

          /* "discretize/_extensions/tree_ext.pyx":5806
 *                         temp = dir1
 *                         dir1 = dir2
 *                         dir2 = temp             # <<<<<<<<<<<<<<
 *                     if (
 *                         abs(locations[i, dir0] - cell.location[dir0]) <
 */
          __Pyx_TraceLine(5806,0,__PYX_ERR(0, 5806, __pyx_L1_error))
          __pyx_v_dir2 = __pyx_v_temp;

          /* "discretize/_extensions/tree_ext.pyx":5800
 *                     dir1 = temp
 *                 if dim == 3:
 *                     if (             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir1] - cell.location[dir1]) <
 *                         abs(locations[i, dir2] - cell.location[dir2])
 */
        }

        /* "discretize/_extensions/tree_ext.pyx":5808
 *                         dir2 = temp
 *                     if (
 *                         abs(locations[i, dir0] - cell.location[dir0]) <             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir1] - cell.location[dir1])
 *                     ):
 */
        __Pyx_TraceLine(5808,0,__PYX_ERR(0, 5808, __pyx_L1_error))
        __pyx_t_16 = __pyx_v_i;
        __pyx_t_15 = __pyx_v_dir0;
        __pyx_t_12 = -1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_15 < 0) {
          __pyx_t_15 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_15 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5808, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5809
 *                     if (
 *                         abs(locations[i, dir0] - cell.location[dir0]) <
 *                         abs(locations[i, dir1] - cell.location[dir1])             # <<<<<<<<<<<<<<
 *                     ):
 *                         temp = dir0
 */
        __Pyx_TraceLine(5809,0,__PYX_ERR(0, 5809, __pyx_L1_error))
        __pyx_t_19 = __pyx_v_i;
        __pyx_t_20 = __pyx_v_dir1;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5809, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":5808
 *                         dir2 = temp
 *                     if (
 *                         abs(locations[i, dir0] - cell.location[dir0]) <             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir1] - cell.location[dir1])
 *                     ):
 */
        __Pyx_TraceLine(5808,0,__PYX_ERR(0, 5808, __pyx_L1_error))
        __pyx_t_17 = ((fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_16 * __pyx_v_locations.strides[0]) ) + __pyx_t_15 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir0]))) < fabs(((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) - (__pyx_v_cell->location[__pyx_v_dir1])))) != 0);

        /* "discretize/_extensions/tree_ext.pyx":5807
 *                         dir1 = dir2
 *                         dir2 = temp
 *                     if (             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir0] - cell.location[dir0]) <
 *                         abs(locations[i, dir1] - cell.location[dir1])
 */
        __Pyx_TraceLine(5807,0,__PYX_ERR(0, 5807, __pyx_L1_error))
        if (__pyx_t_17) {

          /* "discretize/_extensions/tree_ext.pyx":5811
 *                         abs(locations[i, dir1] - cell.location[dir1])
 *                     ):
 *                         temp = dir0             # <<<<<<<<<<<<<<
 *                         dir0 = dir1
 *                         dir0 = temp
 */
          __Pyx_TraceLine(5811,0,__PYX_ERR(0, 5811, __pyx_L1_error))
          __pyx_v_temp = __pyx_v_dir0;

          /* "discretize/_extensions/tree_ext.pyx":5812
 *                     ):
 *                         temp = dir0
 *                         dir0 = dir1             # <<<<<<<<<<<<<<
 *                         dir0 = temp
 *                 # Look -dir0 and +dir0 from current cell
 */
          __Pyx_TraceLine(5812,0,__PYX_ERR(0, 5812, __pyx_L1_error))
          __pyx_v_dir0 = __pyx_v_dir1;

          /* "discretize/_extensions/tree_ext.pyx":5813
 *                         temp = dir0
 *                         dir0 = dir1
 *                         dir0 = temp             # <<<<<<<<<<<<<<
 *                 # Look -dir0 and +dir0 from current cell
 *                 if (
 */
          __Pyx_TraceLine(5813,0,__PYX_ERR(0, 5813, __pyx_L1_error))
          __pyx_v_dir0 = __pyx_v_temp;

          /* "discretize/_extensions/tree_ext.pyx":5807
 *                         dir1 = dir2
 *                         dir2 = temp
 *                     if (             # <<<<<<<<<<<<<<
 *                         abs(locations[i, dir0] - cell.location[dir0]) <
 *                         abs(locations[i, dir1] - cell.location[dir1])
 */
        }

        /* "discretize/_extensions/tree_ext.pyx":5799
 *                     dir0 = dir1
 *                     dir1 = temp
 *                 if dim == 3:             # <<<<<<<<<<<<<<
 *                     if (
 *                         abs(locations[i, dir1] - cell.location[dir1]) <
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":5816
 *                 # Look -dir0 and +dir0 from current cell
 *                 if (
 *                     locations[i, dir0] < cell.location[dir0]             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0] != NULL
 *                     and cell.neighbors[2 * dir0].is_leaf()
 */
      __Pyx_TraceLine(5816,0,__PYX_ERR(0, 5816, __pyx_L1_error))
      __pyx_t_20 = __pyx_v_i;
      __pyx_t_19 = __pyx_v_dir0;
      __pyx_t_12 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5816, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir0])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L16_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5817
 *                 if (
 *                     locations[i, dir0] < cell.location[dir0]
 *                     and cell.neighbors[2 * dir0] != NULL             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0].is_leaf()
 *                     and cell.neighbors[2 * dir0].level == cell.level
 */
      __Pyx_TraceLine(5817,0,__PYX_ERR(0, 5817, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir0)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L16_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5818
 *                     locations[i, dir0] < cell.location[dir0]
 *                     and cell.neighbors[2 * dir0] != NULL
 *                     and cell.neighbors[2 * dir0].is_leaf()             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0].level == cell.level
 *                 ):
 */
      __Pyx_TraceLine(5818,0,__PYX_ERR(0, 5818, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[(2 * __pyx_v_dir0)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L16_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5819
 *                     and cell.neighbors[2 * dir0] != NULL
 *                     and cell.neighbors[2 * dir0].is_leaf()
 *                     and cell.neighbors[2 * dir0].level == cell.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i000 = cell.neighbors[2 * dir0]
 */
      __Pyx_TraceLine(5819,0,__PYX_ERR(0, 5819, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[(2 * __pyx_v_dir0)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L16_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5815
 *                         dir0 = temp
 *                 # Look -dir0 and +dir0 from current cell
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir0] < cell.location[dir0]
 *                     and cell.neighbors[2 * dir0] != NULL
 */
      __Pyx_TraceLine(5815,0,__PYX_ERR(0, 5815, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5821
 *                     and cell.neighbors[2 * dir0].level == cell.level
 *                 ):
 *                     i000 = cell.neighbors[2 * dir0]             # <<<<<<<<<<<<<<
 *                     i001 = cell
 *                 elif (
 */
        __Pyx_TraceLine(5821,0,__PYX_ERR(0, 5821, __pyx_L1_error))
        __pyx_v_i000 = (__pyx_v_cell->neighbors[(2 * __pyx_v_dir0)]);

        /* "discretize/_extensions/tree_ext.pyx":5822
 *                 ):
 *                     i000 = cell.neighbors[2 * dir0]
 *                     i001 = cell             # <<<<<<<<<<<<<<
 *                 elif (
 *                     locations[i, dir0] > cell.location[dir0]
 */
        __Pyx_TraceLine(5822,0,__PYX_ERR(0, 5822, __pyx_L1_error))
        __pyx_v_i001 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5815
 *                         dir0 = temp
 *                 # Look -dir0 and +dir0 from current cell
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir0] < cell.location[dir0]
 *                     and cell.neighbors[2 * dir0] != NULL
 */
        goto __pyx_L15;
      }

      /* "discretize/_extensions/tree_ext.pyx":5824
 *                     i001 = cell
 *                 elif (
 *                     locations[i, dir0] > cell.location[dir0]             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0 + 1] != NULL
 *                     and cell.neighbors[2 * dir0 + 1].is_leaf()
 */
      __Pyx_TraceLine(5824,0,__PYX_ERR(0, 5824, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = __pyx_v_dir0;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5824, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir0])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L20_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5825
 *                 elif (
 *                     locations[i, dir0] > cell.location[dir0]
 *                     and cell.neighbors[2 * dir0 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0 + 1].is_leaf()
 *                     and cell.neighbors[2 * dir0 + 1].level == cell.level
 */
      __Pyx_TraceLine(5825,0,__PYX_ERR(0, 5825, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir0) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L20_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5826
 *                     locations[i, dir0] > cell.location[dir0]
 *                     and cell.neighbors[2 * dir0 + 1] != NULL
 *                     and cell.neighbors[2 * dir0 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and cell.neighbors[2 * dir0 + 1].level == cell.level
 *                 ):
 */
      __Pyx_TraceLine(5826,0,__PYX_ERR(0, 5826, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_cell->neighbors[((2 * __pyx_v_dir0) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L20_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5827
 *                     and cell.neighbors[2 * dir0 + 1] != NULL
 *                     and cell.neighbors[2 * dir0 + 1].is_leaf()
 *                     and cell.neighbors[2 * dir0 + 1].level == cell.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i000 = cell
 */
      __Pyx_TraceLine(5827,0,__PYX_ERR(0, 5827, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_cell->neighbors[((2 * __pyx_v_dir0) + 1)])->level == __pyx_v_cell->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L20_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5823
 *                     i000 = cell.neighbors[2 * dir0]
 *                     i001 = cell
 *                 elif (             # <<<<<<<<<<<<<<
 *                     locations[i, dir0] > cell.location[dir0]
 *                     and cell.neighbors[2 * dir0 + 1] != NULL
 */
      __Pyx_TraceLine(5823,0,__PYX_ERR(0, 5823, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5829
 *                     and cell.neighbors[2 * dir0 + 1].level == cell.level
 *                 ):
 *                     i000 = cell             # <<<<<<<<<<<<<<
 *                     i001 = cell.neighbors[2 * dir0 + 1]
 *                 else:
 */
        __Pyx_TraceLine(5829,0,__PYX_ERR(0, 5829, __pyx_L1_error))
        __pyx_v_i000 = __pyx_v_cell;

        /* "discretize/_extensions/tree_ext.pyx":5830
 *                 ):
 *                     i000 = cell
 *                     i001 = cell.neighbors[2 * dir0 + 1]             # <<<<<<<<<<<<<<
 *                 else:
 *                     i000 = i001 = cell
 */
        __Pyx_TraceLine(5830,0,__PYX_ERR(0, 5830, __pyx_L1_error))
        __pyx_v_i001 = (__pyx_v_cell->neighbors[((2 * __pyx_v_dir0) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5823
 *                     i000 = cell.neighbors[2 * dir0]
 *                     i001 = cell
 *                 elif (             # <<<<<<<<<<<<<<
 *                     locations[i, dir0] > cell.location[dir0]
 *                     and cell.neighbors[2 * dir0 + 1] != NULL
 */
        goto __pyx_L15;
      }

      /* "discretize/_extensions/tree_ext.pyx":5832
 *                     i001 = cell.neighbors[2 * dir0 + 1]
 *                 else:
 *                     i000 = i001 = cell             # <<<<<<<<<<<<<<
 *                 # Look -y and +y from previous two cells
 *                 if (
 */
      __Pyx_TraceLine(5832,0,__PYX_ERR(0, 5832, __pyx_L1_error))
      /*else*/ {
        __pyx_v_i000 = __pyx_v_cell;
        __pyx_v_i001 = __pyx_v_cell;
      }
      __pyx_L15:;

      /* "discretize/_extensions/tree_ext.pyx":5835
 *                 # Look -y and +y from previous two cells
 *                 if (
 *                     locations[i, dir1] < cell.location[dir1]             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1] != NULL
 *                     and i001.neighbors[2 * dir1] != NULL
 */
      __Pyx_TraceLine(5835,0,__PYX_ERR(0, 5835, __pyx_L1_error))
      __pyx_t_20 = __pyx_v_i;
      __pyx_t_19 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5835, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir1])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5836
 *                 if (
 *                     locations[i, dir1] < cell.location[dir1]
 *                     and i000.neighbors[2 * dir1] != NULL             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1] != NULL
 *                     and i000.neighbors[2 * dir1].is_leaf()
 */
      __Pyx_TraceLine(5836,0,__PYX_ERR(0, 5836, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[(2 * __pyx_v_dir1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5837
 *                     locations[i, dir1] < cell.location[dir1]
 *                     and i000.neighbors[2 * dir1] != NULL
 *                     and i001.neighbors[2 * dir1] != NULL             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1].is_leaf()
 *                     and i001.neighbors[2 * dir1].is_leaf()
 */
      __Pyx_TraceLine(5837,0,__PYX_ERR(0, 5837, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[(2 * __pyx_v_dir1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5838
 *                     and i000.neighbors[2 * dir1] != NULL
 *                     and i001.neighbors[2 * dir1] != NULL
 *                     and i000.neighbors[2 * dir1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1].is_leaf()
 *                     and i000.neighbors[2 * dir1].level == i000.level
 */
      __Pyx_TraceLine(5838,0,__PYX_ERR(0, 5838, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i000->neighbors[(2 * __pyx_v_dir1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5839
 *                     and i001.neighbors[2 * dir1] != NULL
 *                     and i000.neighbors[2 * dir1].is_leaf()
 *                     and i001.neighbors[2 * dir1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1].level == i000.level
 *                     and i001.neighbors[2 * dir1].level == i001.level
 */
      __Pyx_TraceLine(5839,0,__PYX_ERR(0, 5839, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i001->neighbors[(2 * __pyx_v_dir1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5840
 *                     and i000.neighbors[2 * dir1].is_leaf()
 *                     and i001.neighbors[2 * dir1].is_leaf()
 *                     and i000.neighbors[2 * dir1].level == i000.level             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1].level == i001.level
 *                 ):
 */
      __Pyx_TraceLine(5840,0,__PYX_ERR(0, 5840, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[(2 * __pyx_v_dir1)])->level == __pyx_v_i000->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L25_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5841
 *                     and i001.neighbors[2 * dir1].is_leaf()
 *                     and i000.neighbors[2 * dir1].level == i000.level
 *                     and i001.neighbors[2 * dir1].level == i001.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i010 = i000
 */
      __Pyx_TraceLine(5841,0,__PYX_ERR(0, 5841, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[(2 * __pyx_v_dir1)])->level == __pyx_v_i001->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L25_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5834
 *                     i000 = i001 = cell
 *                 # Look -y and +y from previous two cells
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir1] < cell.location[dir1]
 *                     and i000.neighbors[2 * dir1] != NULL
 */
      __Pyx_TraceLine(5834,0,__PYX_ERR(0, 5834, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5843
 *                     and i001.neighbors[2 * dir1].level == i001.level
 *                 ):
 *                     i010 = i000             # <<<<<<<<<<<<<<
 *                     i011 = i001
 *                     i000 = i000.neighbors[2 * dir1]
 */
        __Pyx_TraceLine(5843,0,__PYX_ERR(0, 5843, __pyx_L1_error))
        __pyx_v_i010 = __pyx_v_i000;

        /* "discretize/_extensions/tree_ext.pyx":5844
 *                 ):
 *                     i010 = i000
 *                     i011 = i001             # <<<<<<<<<<<<<<
 *                     i000 = i000.neighbors[2 * dir1]
 *                     i001 = i001.neighbors[2 * dir1]
 */
        __Pyx_TraceLine(5844,0,__PYX_ERR(0, 5844, __pyx_L1_error))
        __pyx_v_i011 = __pyx_v_i001;

        /* "discretize/_extensions/tree_ext.pyx":5845
 *                     i010 = i000
 *                     i011 = i001
 *                     i000 = i000.neighbors[2 * dir1]             # <<<<<<<<<<<<<<
 *                     i001 = i001.neighbors[2 * dir1]
 *                 elif (
 */
        __Pyx_TraceLine(5845,0,__PYX_ERR(0, 5845, __pyx_L1_error))
        __pyx_v_i000 = (__pyx_v_i000->neighbors[(2 * __pyx_v_dir1)]);

        /* "discretize/_extensions/tree_ext.pyx":5846
 *                     i011 = i001
 *                     i000 = i000.neighbors[2 * dir1]
 *                     i001 = i001.neighbors[2 * dir1]             # <<<<<<<<<<<<<<
 *                 elif (
 *                     locations[i, dir1] > cell.location[dir1]
 */
        __Pyx_TraceLine(5846,0,__PYX_ERR(0, 5846, __pyx_L1_error))
        __pyx_v_i001 = (__pyx_v_i001->neighbors[(2 * __pyx_v_dir1)]);

        /* "discretize/_extensions/tree_ext.pyx":5834
 *                     i000 = i001 = cell
 *                 # Look -y and +y from previous two cells
 *                 if (             # <<<<<<<<<<<<<<
 *                     locations[i, dir1] < cell.location[dir1]
 *                     and i000.neighbors[2 * dir1] != NULL
 */
        goto __pyx_L24;
      }

      /* "discretize/_extensions/tree_ext.pyx":5848
 *                     i001 = i001.neighbors[2 * dir1]
 *                 elif (
 *                     locations[i, dir1] > cell.location[dir1]             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1 + 1] != NULL
 *                     and i001.neighbors[2 * dir1 + 1] != NULL
 */
      __Pyx_TraceLine(5848,0,__PYX_ERR(0, 5848, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = __pyx_v_dir1;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5848, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir1])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5849
 *                 elif (
 *                     locations[i, dir1] > cell.location[dir1]
 *                     and i000.neighbors[2 * dir1 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1 + 1] != NULL
 *                     and i000.neighbors[2 * dir1 + 1].is_leaf()
 */
      __Pyx_TraceLine(5849,0,__PYX_ERR(0, 5849, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[((2 * __pyx_v_dir1) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5850
 *                     locations[i, dir1] > cell.location[dir1]
 *                     and i000.neighbors[2 * dir1 + 1] != NULL
 *                     and i001.neighbors[2 * dir1 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir1 + 1].is_leaf()
 */
      __Pyx_TraceLine(5850,0,__PYX_ERR(0, 5850, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[((2 * __pyx_v_dir1) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5851
 *                     and i000.neighbors[2 * dir1 + 1] != NULL
 *                     and i001.neighbors[2 * dir1 + 1] != NULL
 *                     and i000.neighbors[2 * dir1 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir1 + 1].level == i000.level
 */
      __Pyx_TraceLine(5851,0,__PYX_ERR(0, 5851, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i000->neighbors[((2 * __pyx_v_dir1) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5852
 *                     and i001.neighbors[2 * dir1 + 1] != NULL
 *                     and i000.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir1 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir1 + 1].level == i000.level
 *                     and i001.neighbors[2 * dir1 + 1].level == i001.level
 */
      __Pyx_TraceLine(5852,0,__PYX_ERR(0, 5852, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i001->neighbors[((2 * __pyx_v_dir1) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5853
 *                     and i000.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir1 + 1].level == i000.level             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir1 + 1].level == i001.level
 *                 ):
 */
      __Pyx_TraceLine(5853,0,__PYX_ERR(0, 5853, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[((2 * __pyx_v_dir1) + 1)])->level == __pyx_v_i000->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L32_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5854
 *                     and i001.neighbors[2 * dir1 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir1 + 1].level == i000.level
 *                     and i001.neighbors[2 * dir1 + 1].level == i001.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i010 = i000.neighbors[2 * dir1 + 1]
 */
      __Pyx_TraceLine(5854,0,__PYX_ERR(0, 5854, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[((2 * __pyx_v_dir1) + 1)])->level == __pyx_v_i001->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L32_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5847
 *                     i000 = i000.neighbors[2 * dir1]
 *                     i001 = i001.neighbors[2 * dir1]
 *                 elif (             # <<<<<<<<<<<<<<
 *                     locations[i, dir1] > cell.location[dir1]
 *                     and i000.neighbors[2 * dir1 + 1] != NULL
 */
      __Pyx_TraceLine(5847,0,__PYX_ERR(0, 5847, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5856
 *                     and i001.neighbors[2 * dir1 + 1].level == i001.level
 *                 ):
 *                     i010 = i000.neighbors[2 * dir1 + 1]             # <<<<<<<<<<<<<<
 *                     i011 = i001.neighbors[2 * dir1 + 1]
 *                 else:
 */
        __Pyx_TraceLine(5856,0,__PYX_ERR(0, 5856, __pyx_L1_error))
        __pyx_v_i010 = (__pyx_v_i000->neighbors[((2 * __pyx_v_dir1) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5857
 *                 ):
 *                     i010 = i000.neighbors[2 * dir1 + 1]
 *                     i011 = i001.neighbors[2 * dir1 + 1]             # <<<<<<<<<<<<<<
 *                 else:
 *                     i010 = i000
 */
        __Pyx_TraceLine(5857,0,__PYX_ERR(0, 5857, __pyx_L1_error))
        __pyx_v_i011 = (__pyx_v_i001->neighbors[((2 * __pyx_v_dir1) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5847
 *                     i000 = i000.neighbors[2 * dir1]
 *                     i001 = i001.neighbors[2 * dir1]
 *                 elif (             # <<<<<<<<<<<<<<
 *                     locations[i, dir1] > cell.location[dir1]
 *                     and i000.neighbors[2 * dir1 + 1] != NULL
 */
        goto __pyx_L24;
      }

      /* "discretize/_extensions/tree_ext.pyx":5859
 *                     i011 = i001.neighbors[2 * dir1 + 1]
 *                 else:
 *                     i010 = i000             # <<<<<<<<<<<<<<
 *                     i011 = i001
 *                     w1 = 1.0
 */
      __Pyx_TraceLine(5859,0,__PYX_ERR(0, 5859, __pyx_L1_error))
      /*else*/ {
        __pyx_v_i010 = __pyx_v_i000;

        /* "discretize/_extensions/tree_ext.pyx":5860
 *                 else:
 *                     i010 = i000
 *                     i011 = i001             # <<<<<<<<<<<<<<
 *                     w1 = 1.0
 *                 # Look -z and +z from previous four cells
 */
        __Pyx_TraceLine(5860,0,__PYX_ERR(0, 5860, __pyx_L1_error))
        __pyx_v_i011 = __pyx_v_i001;

        /* "discretize/_extensions/tree_ext.pyx":5861
 *                     i010 = i000
 *                     i011 = i001
 *                     w1 = 1.0             # <<<<<<<<<<<<<<
 *                 # Look -z and +z from previous four cells
 *                 if (
 */
        __Pyx_TraceLine(5861,0,__PYX_ERR(0, 5861, __pyx_L1_error))
        __pyx_v_w1 = 1.0;
      }
      __pyx_L24:;

      /* "discretize/_extensions/tree_ext.pyx":5864
 *                 # Look -z and +z from previous four cells
 *                 if (
 *                     dim == 3             # <<<<<<<<<<<<<<
 *                     and locations[i, dir2] < cell.location[dir2]
 *                     and i000.neighbors[2 * dir2] != NULL
 */
      __Pyx_TraceLine(5864,0,__PYX_ERR(0, 5864, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5865
 *                 if (
 *                     dim == 3
 *                     and locations[i, dir2] < cell.location[dir2]             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2] != NULL
 *                     and i001.neighbors[2 * dir2] != NULL
 */
      __Pyx_TraceLine(5865,0,__PYX_ERR(0, 5865, __pyx_L1_error))
      __pyx_t_20 = __pyx_v_i;
      __pyx_t_19 = __pyx_v_dir2;
      __pyx_t_12 = -1;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5865, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))) < (__pyx_v_cell->location[__pyx_v_dir2])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5866
 *                     dim == 3
 *                     and locations[i, dir2] < cell.location[dir2]
 *                     and i000.neighbors[2 * dir2] != NULL             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2] != NULL
 *                     and i010.neighbors[2 * dir2] != NULL
 */
      __Pyx_TraceLine(5866,0,__PYX_ERR(0, 5866, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5867
 *                     and locations[i, dir2] < cell.location[dir2]
 *                     and i000.neighbors[2 * dir2] != NULL
 *                     and i001.neighbors[2 * dir2] != NULL             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2] != NULL
 *                     and i011.neighbors[2 * dir2] != NULL
 */
      __Pyx_TraceLine(5867,0,__PYX_ERR(0, 5867, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5868
 *                     and i000.neighbors[2 * dir2] != NULL
 *                     and i001.neighbors[2 * dir2] != NULL
 *                     and i010.neighbors[2 * dir2] != NULL             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2] != NULL
 *                     and i000.neighbors[2 * dir2].is_leaf()
 */
      __Pyx_TraceLine(5868,0,__PYX_ERR(0, 5868, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i010->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5869
 *                     and i001.neighbors[2 * dir2] != NULL
 *                     and i010.neighbors[2 * dir2] != NULL
 *                     and i011.neighbors[2 * dir2] != NULL             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2].is_leaf()
 *                     and i001.neighbors[2 * dir2].is_leaf()
 */
      __Pyx_TraceLine(5869,0,__PYX_ERR(0, 5869, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i011->neighbors[(2 * __pyx_v_dir2)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5870
 *                     and i010.neighbors[2 * dir2] != NULL
 *                     and i011.neighbors[2 * dir2] != NULL
 *                     and i000.neighbors[2 * dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2].is_leaf()
 *                     and i010.neighbors[2 * dir2].is_leaf()
 */
      __Pyx_TraceLine(5870,0,__PYX_ERR(0, 5870, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i000->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5871
 *                     and i011.neighbors[2 * dir2] != NULL
 *                     and i000.neighbors[2 * dir2].is_leaf()
 *                     and i001.neighbors[2 * dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2].is_leaf()
 *                     and i011.neighbors[2 * dir2].is_leaf()
 */
      __Pyx_TraceLine(5871,0,__PYX_ERR(0, 5871, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i001->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5872
 *                     and i000.neighbors[2 * dir2].is_leaf()
 *                     and i001.neighbors[2 * dir2].is_leaf()
 *                     and i010.neighbors[2 * dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2].is_leaf()
 *                     and i000.neighbors[2 * dir2].level == i000.level
 */
      __Pyx_TraceLine(5872,0,__PYX_ERR(0, 5872, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i010->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5873
 *                     and i001.neighbors[2 * dir2].is_leaf()
 *                     and i010.neighbors[2 * dir2].is_leaf()
 *                     and i011.neighbors[2 * dir2].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2].level == i000.level
 *                     and i001.neighbors[2 * dir2].level == i001.level
 */
      __Pyx_TraceLine(5873,0,__PYX_ERR(0, 5873, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i011->neighbors[(2 * __pyx_v_dir2)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5874
 *                     and i010.neighbors[2 * dir2].is_leaf()
 *                     and i011.neighbors[2 * dir2].is_leaf()
 *                     and i000.neighbors[2 * dir2].level == i000.level             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2].level == i001.level
 *                     and i010.neighbors[2 * dir2].level == i010.level
 */
      __Pyx_TraceLine(5874,0,__PYX_ERR(0, 5874, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i000->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5875
 *                     and i011.neighbors[2 * dir2].is_leaf()
 *                     and i000.neighbors[2 * dir2].level == i000.level
 *                     and i001.neighbors[2 * dir2].level == i001.level             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2].level == i010.level
 *                     and i011.neighbors[2 * dir2].level == i011.level
 */
      __Pyx_TraceLine(5875,0,__PYX_ERR(0, 5875, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i001->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5876
 *                     and i000.neighbors[2 * dir2].level == i000.level
 *                     and i001.neighbors[2 * dir2].level == i001.level
 *                     and i010.neighbors[2 * dir2].level == i010.level             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2].level == i011.level
 *                 ):
 */
      __Pyx_TraceLine(5876,0,__PYX_ERR(0, 5876, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i010->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i010->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L40_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5877
 *                     and i001.neighbors[2 * dir2].level == i001.level
 *                     and i010.neighbors[2 * dir2].level == i010.level
 *                     and i011.neighbors[2 * dir2].level == i011.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i100 = i000
 */
      __Pyx_TraceLine(5877,0,__PYX_ERR(0, 5877, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i011->neighbors[(2 * __pyx_v_dir2)])->level == __pyx_v_i011->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L40_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5863
 *                     w1 = 1.0
 *                 # Look -z and +z from previous four cells
 *                 if (             # <<<<<<<<<<<<<<
 *                     dim == 3
 *                     and locations[i, dir2] < cell.location[dir2]
 */
      __Pyx_TraceLine(5863,0,__PYX_ERR(0, 5863, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5879
 *                     and i011.neighbors[2 * dir2].level == i011.level
 *                 ):
 *                     i100 = i000             # <<<<<<<<<<<<<<
 *                     i101 = i001
 *                     i110 = i010
 */
        __Pyx_TraceLine(5879,0,__PYX_ERR(0, 5879, __pyx_L1_error))
        __pyx_v_i100 = __pyx_v_i000;

        /* "discretize/_extensions/tree_ext.pyx":5880
 *                 ):
 *                     i100 = i000
 *                     i101 = i001             # <<<<<<<<<<<<<<
 *                     i110 = i010
 *                     i111 = i011
 */
        __Pyx_TraceLine(5880,0,__PYX_ERR(0, 5880, __pyx_L1_error))
        __pyx_v_i101 = __pyx_v_i001;

        /* "discretize/_extensions/tree_ext.pyx":5881
 *                     i100 = i000
 *                     i101 = i001
 *                     i110 = i010             # <<<<<<<<<<<<<<
 *                     i111 = i011
 *                     i000 = i000.neighbors[2 * dir2]
 */
        __Pyx_TraceLine(5881,0,__PYX_ERR(0, 5881, __pyx_L1_error))
        __pyx_v_i110 = __pyx_v_i010;

        /* "discretize/_extensions/tree_ext.pyx":5882
 *                     i101 = i001
 *                     i110 = i010
 *                     i111 = i011             # <<<<<<<<<<<<<<
 *                     i000 = i000.neighbors[2 * dir2]
 *                     i001 = i001.neighbors[2 * dir2]
 */
        __Pyx_TraceLine(5882,0,__PYX_ERR(0, 5882, __pyx_L1_error))
        __pyx_v_i111 = __pyx_v_i011;

        /* "discretize/_extensions/tree_ext.pyx":5883
 *                     i110 = i010
 *                     i111 = i011
 *                     i000 = i000.neighbors[2 * dir2]             # <<<<<<<<<<<<<<
 *                     i001 = i001.neighbors[2 * dir2]
 *                     i010 = i010.neighbors[2 * dir2]
 */
        __Pyx_TraceLine(5883,0,__PYX_ERR(0, 5883, __pyx_L1_error))
        __pyx_v_i000 = (__pyx_v_i000->neighbors[(2 * __pyx_v_dir2)]);

        /* "discretize/_extensions/tree_ext.pyx":5884
 *                     i111 = i011
 *                     i000 = i000.neighbors[2 * dir2]
 *                     i001 = i001.neighbors[2 * dir2]             # <<<<<<<<<<<<<<
 *                     i010 = i010.neighbors[2 * dir2]
 *                     i011 = i011.neighbors[2 * dir2]
 */
        __Pyx_TraceLine(5884,0,__PYX_ERR(0, 5884, __pyx_L1_error))
        __pyx_v_i001 = (__pyx_v_i001->neighbors[(2 * __pyx_v_dir2)]);

        /* "discretize/_extensions/tree_ext.pyx":5885
 *                     i000 = i000.neighbors[2 * dir2]
 *                     i001 = i001.neighbors[2 * dir2]
 *                     i010 = i010.neighbors[2 * dir2]             # <<<<<<<<<<<<<<
 *                     i011 = i011.neighbors[2 * dir2]
 *                 elif (
 */
        __Pyx_TraceLine(5885,0,__PYX_ERR(0, 5885, __pyx_L1_error))
        __pyx_v_i010 = (__pyx_v_i010->neighbors[(2 * __pyx_v_dir2)]);

        /* "discretize/_extensions/tree_ext.pyx":5886
 *                     i001 = i001.neighbors[2 * dir2]
 *                     i010 = i010.neighbors[2 * dir2]
 *                     i011 = i011.neighbors[2 * dir2]             # <<<<<<<<<<<<<<
 *                 elif (
 *                     dim == 3
 */
        __Pyx_TraceLine(5886,0,__PYX_ERR(0, 5886, __pyx_L1_error))
        __pyx_v_i011 = (__pyx_v_i011->neighbors[(2 * __pyx_v_dir2)]);

        /* "discretize/_extensions/tree_ext.pyx":5863
 *                     w1 = 1.0
 *                 # Look -z and +z from previous four cells
 *                 if (             # <<<<<<<<<<<<<<
 *                     dim == 3
 *                     and locations[i, dir2] < cell.location[dir2]
 */
        goto __pyx_L39;
      }

      /* "discretize/_extensions/tree_ext.pyx":5888
 *                     i011 = i011.neighbors[2 * dir2]
 *                 elif (
 *                     dim == 3             # <<<<<<<<<<<<<<
 *                     and locations[i, dir2] > cell.location[dir2]
 *                     and i000.neighbors[2 * dir2 + 1] != NULL
 */
      __Pyx_TraceLine(5888,0,__PYX_ERR(0, 5888, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5889
 *                 elif (
 *                     dim == 3
 *                     and locations[i, dir2] > cell.location[dir2]             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2 + 1] != NULL
 *                     and i001.neighbors[2 * dir2 + 1] != NULL
 */
      __Pyx_TraceLine(5889,0,__PYX_ERR(0, 5889, __pyx_L1_error))
      __pyx_t_19 = __pyx_v_i;
      __pyx_t_20 = __pyx_v_dir2;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_locations.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_20 < 0) {
        __pyx_t_20 += __pyx_v_locations.shape[1];
        if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5889, __pyx_L1_error)
      }
      __pyx_t_18 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))) > (__pyx_v_cell->location[__pyx_v_dir2])) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5890
 *                     dim == 3
 *                     and locations[i, dir2] > cell.location[dir2]
 *                     and i000.neighbors[2 * dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2 + 1] != NULL
 *                     and i010.neighbors[2 * dir2 + 1] != NULL
 */
      __Pyx_TraceLine(5890,0,__PYX_ERR(0, 5890, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5891
 *                     and locations[i, dir2] > cell.location[dir2]
 *                     and i000.neighbors[2 * dir2 + 1] != NULL
 *                     and i001.neighbors[2 * dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2 + 1] != NULL
 *                     and i011.neighbors[2 * dir2 + 1] != NULL
 */
      __Pyx_TraceLine(5891,0,__PYX_ERR(0, 5891, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5892
 *                     and i000.neighbors[2 * dir2 + 1] != NULL
 *                     and i001.neighbors[2 * dir2 + 1] != NULL
 *                     and i010.neighbors[2 * dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2 + 1] != NULL
 *                     and i000.neighbors[2 * dir2 + 1].is_leaf()
 */
      __Pyx_TraceLine(5892,0,__PYX_ERR(0, 5892, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i010->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5893
 *                     and i001.neighbors[2 * dir2 + 1] != NULL
 *                     and i010.neighbors[2 * dir2 + 1] != NULL
 *                     and i011.neighbors[2 * dir2 + 1] != NULL             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir2 + 1].is_leaf()
 */
      __Pyx_TraceLine(5893,0,__PYX_ERR(0, 5893, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i011->neighbors[((2 * __pyx_v_dir2) + 1)]) != NULL) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5894
 *                     and i010.neighbors[2 * dir2 + 1] != NULL
 *                     and i011.neighbors[2 * dir2 + 1] != NULL
 *                     and i000.neighbors[2 * dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i010.neighbors[2 * dir2 + 1].is_leaf()
 */
      __Pyx_TraceLine(5894,0,__PYX_ERR(0, 5894, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i000->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5895
 *                     and i011.neighbors[2 * dir2 + 1] != NULL
 *                     and i000.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i011.neighbors[2 * dir2 + 1].is_leaf()
 */
      __Pyx_TraceLine(5895,0,__PYX_ERR(0, 5895, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i001->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5896
 *                     and i000.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i001.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i010.neighbors[2 * dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir2 + 1].level == i000.level
 */
      __Pyx_TraceLine(5896,0,__PYX_ERR(0, 5896, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i010->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5897
 *                     and i001.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i010.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i011.neighbors[2 * dir2 + 1].is_leaf()             # <<<<<<<<<<<<<<
 *                     and i000.neighbors[2 * dir2 + 1].level == i000.level
 *                     and i001.neighbors[2 * dir2 + 1].level == i001.level
 */
      __Pyx_TraceLine(5897,0,__PYX_ERR(0, 5897, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_i011->neighbors[((2 * __pyx_v_dir2) + 1)])->is_leaf() != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5898
 *                     and i010.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i011.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir2 + 1].level == i000.level             # <<<<<<<<<<<<<<
 *                     and i001.neighbors[2 * dir2 + 1].level == i001.level
 *                     and i010.neighbors[2 * dir2 + 1].level == i010.level
 */
      __Pyx_TraceLine(5898,0,__PYX_ERR(0, 5898, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i000->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i000->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5899
 *                     and i011.neighbors[2 * dir2 + 1].is_leaf()
 *                     and i000.neighbors[2 * dir2 + 1].level == i000.level
 *                     and i001.neighbors[2 * dir2 + 1].level == i001.level             # <<<<<<<<<<<<<<
 *                     and i010.neighbors[2 * dir2 + 1].level == i010.level
 *                     and i011.neighbors[2 * dir2 + 1].level == i011.level
 */
      __Pyx_TraceLine(5899,0,__PYX_ERR(0, 5899, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i001->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i001->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5900
 *                     and i000.neighbors[2 * dir2 + 1].level == i000.level
 *                     and i001.neighbors[2 * dir2 + 1].level == i001.level
 *                     and i010.neighbors[2 * dir2 + 1].level == i010.level             # <<<<<<<<<<<<<<
 *                     and i011.neighbors[2 * dir2 + 1].level == i011.level
 *                 ):
 */
      __Pyx_TraceLine(5900,0,__PYX_ERR(0, 5900, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i010->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i010->level) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L54_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":5901
 *                     and i001.neighbors[2 * dir2 + 1].level == i001.level
 *                     and i010.neighbors[2 * dir2 + 1].level == i010.level
 *                     and i011.neighbors[2 * dir2 + 1].level == i011.level             # <<<<<<<<<<<<<<
 *                 ):
 *                     i100 = i000.neighbors[2 * dir2 + 1]
 */
      __Pyx_TraceLine(5901,0,__PYX_ERR(0, 5901, __pyx_L1_error))
      __pyx_t_18 = (((__pyx_v_i011->neighbors[((2 * __pyx_v_dir2) + 1)])->level == __pyx_v_i011->level) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L54_bool_binop_done:;

      /* "discretize/_extensions/tree_ext.pyx":5887
 *                     i010 = i010.neighbors[2 * dir2]
 *                     i011 = i011.neighbors[2 * dir2]
 *                 elif (             # <<<<<<<<<<<<<<
 *                     dim == 3
 *                     and locations[i, dir2] > cell.location[dir2]
 */
      __Pyx_TraceLine(5887,0,__PYX_ERR(0, 5887, __pyx_L1_error))
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5903
 *                     and i011.neighbors[2 * dir2 + 1].level == i011.level
 *                 ):
 *                     i100 = i000.neighbors[2 * dir2 + 1]             # <<<<<<<<<<<<<<
 *                     i101 = i001.neighbors[2 * dir2 + 1]
 *                     i110 = i010.neighbors[2 * dir2 + 1]
 */
        __Pyx_TraceLine(5903,0,__PYX_ERR(0, 5903, __pyx_L1_error))
        __pyx_v_i100 = (__pyx_v_i000->neighbors[((2 * __pyx_v_dir2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5904
 *                 ):
 *                     i100 = i000.neighbors[2 * dir2 + 1]
 *                     i101 = i001.neighbors[2 * dir2 + 1]             # <<<<<<<<<<<<<<
 *                     i110 = i010.neighbors[2 * dir2 + 1]
 *                     i111 = i011.neighbors[2 * dir2 + 1]
 */
        __Pyx_TraceLine(5904,0,__PYX_ERR(0, 5904, __pyx_L1_error))
        __pyx_v_i101 = (__pyx_v_i001->neighbors[((2 * __pyx_v_dir2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5905
 *                     i100 = i000.neighbors[2 * dir2 + 1]
 *                     i101 = i001.neighbors[2 * dir2 + 1]
 *                     i110 = i010.neighbors[2 * dir2 + 1]             # <<<<<<<<<<<<<<
 *                     i111 = i011.neighbors[2 * dir2 + 1]
 *                 else:
 */
        __Pyx_TraceLine(5905,0,__PYX_ERR(0, 5905, __pyx_L1_error))
        __pyx_v_i110 = (__pyx_v_i010->neighbors[((2 * __pyx_v_dir2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5906
 *                     i101 = i001.neighbors[2 * dir2 + 1]
 *                     i110 = i010.neighbors[2 * dir2 + 1]
 *                     i111 = i011.neighbors[2 * dir2 + 1]             # <<<<<<<<<<<<<<
 *                 else:
 *                     i100 = i000
 */
        __Pyx_TraceLine(5906,0,__PYX_ERR(0, 5906, __pyx_L1_error))
        __pyx_v_i111 = (__pyx_v_i011->neighbors[((2 * __pyx_v_dir2) + 1)]);

        /* "discretize/_extensions/tree_ext.pyx":5887
 *                     i010 = i010.neighbors[2 * dir2]
 *                     i011 = i011.neighbors[2 * dir2]
 *                 elif (             # <<<<<<<<<<<<<<
 *                     dim == 3
 *                     and locations[i, dir2] > cell.location[dir2]
 */
        goto __pyx_L39;
      }

      /* "discretize/_extensions/tree_ext.pyx":5908
 *                     i111 = i011.neighbors[2 * dir2 + 1]
 *                 else:
 *                     i100 = i000             # <<<<<<<<<<<<<<
 *                     i101 = i001
 *                     i110 = i010
 */
      __Pyx_TraceLine(5908,0,__PYX_ERR(0, 5908, __pyx_L1_error))
      /*else*/ {
        __pyx_v_i100 = __pyx_v_i000;

        /* "discretize/_extensions/tree_ext.pyx":5909
 *                 else:
 *                     i100 = i000
 *                     i101 = i001             # <<<<<<<<<<<<<<
 *                     i110 = i010
 *                     i111 = i011
 */
        __Pyx_TraceLine(5909,0,__PYX_ERR(0, 5909, __pyx_L1_error))
        __pyx_v_i101 = __pyx_v_i001;

        /* "discretize/_extensions/tree_ext.pyx":5910
 *                     i100 = i000
 *                     i101 = i001
 *                     i110 = i010             # <<<<<<<<<<<<<<
 *                     i111 = i011
 * 
 */
        __Pyx_TraceLine(5910,0,__PYX_ERR(0, 5910, __pyx_L1_error))
        __pyx_v_i110 = __pyx_v_i010;

        /* "discretize/_extensions/tree_ext.pyx":5911
 *                     i101 = i001
 *                     i110 = i010
 *                     i111 = i011             # <<<<<<<<<<<<<<
 * 
 *                 if i001.index != i000.index:
 */
        __Pyx_TraceLine(5911,0,__PYX_ERR(0, 5911, __pyx_L1_error))
        __pyx_v_i111 = __pyx_v_i011;
      }
      __pyx_L39:;

      /* "discretize/_extensions/tree_ext.pyx":5913
 *                     i111 = i011
 * 
 *                 if i001.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w1 = ((i001.location[dir0] - locations[i, dir0])/
 *                           (i001.location[dir0] - i000.location[dir0]))
 */
      __Pyx_TraceLine(5913,0,__PYX_ERR(0, 5913, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_i001->index != __pyx_v_i000->index) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5914
 * 
 *                 if i001.index != i000.index:
 *                     w1 = ((i001.location[dir0] - locations[i, dir0])/             # <<<<<<<<<<<<<<
 *                           (i001.location[dir0] - i000.location[dir0]))
 *                 else:
 */
        __Pyx_TraceLine(5914,0,__PYX_ERR(0, 5914, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir0;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5914, __pyx_L1_error)
        }
        __pyx_t_11 = ((__pyx_v_i001->location[__pyx_v_dir0]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5915
 *                 if i001.index != i000.index:
 *                     w1 = ((i001.location[dir0] - locations[i, dir0])/
 *                           (i001.location[dir0] - i000.location[dir0]))             # <<<<<<<<<<<<<<
 *                 else:
 *                    w1 = 1.0
 */
        __Pyx_TraceLine(5915,0,__PYX_ERR(0, 5915, __pyx_L1_error))
        __pyx_t_21 = ((__pyx_v_i001->location[__pyx_v_dir0]) - (__pyx_v_i000->location[__pyx_v_dir0]));

        /* "discretize/_extensions/tree_ext.pyx":5914
 * 
 *                 if i001.index != i000.index:
 *                     w1 = ((i001.location[dir0] - locations[i, dir0])/             # <<<<<<<<<<<<<<
 *                           (i001.location[dir0] - i000.location[dir0]))
 *                 else:
 */
        __Pyx_TraceLine(5914,0,__PYX_ERR(0, 5914, __pyx_L1_error))
        if (unlikely(__pyx_t_21 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5914, __pyx_L1_error)
        }
        __pyx_v_w1 = (__pyx_t_11 / __pyx_t_21);

        /* "discretize/_extensions/tree_ext.pyx":5913
 *                     i111 = i011
 * 
 *                 if i001.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w1 = ((i001.location[dir0] - locations[i, dir0])/
 *                           (i001.location[dir0] - i000.location[dir0]))
 */
        goto __pyx_L68;
      }

      /* "discretize/_extensions/tree_ext.pyx":5917
 *                           (i001.location[dir0] - i000.location[dir0]))
 *                 else:
 *                    w1 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                 if i010.index != i000.index:
 */
      __Pyx_TraceLine(5917,0,__PYX_ERR(0, 5917, __pyx_L1_error))
      /*else*/ {
        __pyx_v_w1 = 1.0;
      }
      __pyx_L68:;

      /* "discretize/_extensions/tree_ext.pyx":5919
 *                    w1 = 1.0
 * 
 *                 if i010.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w2 = ((i010.location[dir1] - locations[i, dir1])/
 *                           (i010.location[dir1] - i000.location[dir1]))
 */
      __Pyx_TraceLine(5919,0,__PYX_ERR(0, 5919, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_i010->index != __pyx_v_i000->index) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5920
 * 
 *                 if i010.index != i000.index:
 *                     w2 = ((i010.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                           (i010.location[dir1] - i000.location[dir1]))
 *                 else:
 */
        __Pyx_TraceLine(5920,0,__PYX_ERR(0, 5920, __pyx_L1_error))
        __pyx_t_19 = __pyx_v_i;
        __pyx_t_20 = __pyx_v_dir1;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5920, __pyx_L1_error)
        }
        __pyx_t_21 = ((__pyx_v_i010->location[__pyx_v_dir1]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_19 * __pyx_v_locations.strides[0]) ) + __pyx_t_20 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5921
 *                 if i010.index != i000.index:
 *                     w2 = ((i010.location[dir1] - locations[i, dir1])/
 *                           (i010.location[dir1] - i000.location[dir1]))             # <<<<<<<<<<<<<<
 *                 else:
 *                     w2 = 1.0
 */
        __Pyx_TraceLine(5921,0,__PYX_ERR(0, 5921, __pyx_L1_error))
        __pyx_t_11 = ((__pyx_v_i010->location[__pyx_v_dir1]) - (__pyx_v_i000->location[__pyx_v_dir1]));

        /* "discretize/_extensions/tree_ext.pyx":5920
 * 
 *                 if i010.index != i000.index:
 *                     w2 = ((i010.location[dir1] - locations[i, dir1])/             # <<<<<<<<<<<<<<
 *                           (i010.location[dir1] - i000.location[dir1]))
 *                 else:
 */
        __Pyx_TraceLine(5920,0,__PYX_ERR(0, 5920, __pyx_L1_error))
        if (unlikely(__pyx_t_11 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5920, __pyx_L1_error)
        }
        __pyx_v_w2 = (__pyx_t_21 / __pyx_t_11);

        /* "discretize/_extensions/tree_ext.pyx":5919
 *                    w1 = 1.0
 * 
 *                 if i010.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w2 = ((i010.location[dir1] - locations[i, dir1])/
 *                           (i010.location[dir1] - i000.location[dir1]))
 */
        goto __pyx_L69;
      }

      /* "discretize/_extensions/tree_ext.pyx":5923
 *                           (i010.location[dir1] - i000.location[dir1]))
 *                 else:
 *                     w2 = 1.0             # <<<<<<<<<<<<<<
 * 
 *                 if dim == 3 and i100.index != i000.index:
 */
      __Pyx_TraceLine(5923,0,__PYX_ERR(0, 5923, __pyx_L1_error))
      /*else*/ {
        __pyx_v_w2 = 1.0;
      }
      __pyx_L69:;

      /* "discretize/_extensions/tree_ext.pyx":5925
 *                     w2 = 1.0
 * 
 *                 if dim == 3 and i100.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/
 *                           (i100.location[dir2] - i000.location[dir2]))
 */
      __Pyx_TraceLine(5925,0,__PYX_ERR(0, 5925, __pyx_L1_error))
      __pyx_t_18 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_18) {
      } else {
        __pyx_t_17 = __pyx_t_18;
        goto __pyx_L71_bool_binop_done;
      }
      __pyx_t_18 = ((__pyx_v_i100->index != __pyx_v_i000->index) != 0);
      __pyx_t_17 = __pyx_t_18;
      __pyx_L71_bool_binop_done:;
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5926
 * 
 *                 if dim == 3 and i100.index != i000.index:
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 */
        __Pyx_TraceLine(5926,0,__PYX_ERR(0, 5926, __pyx_L1_error))
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_19 = __pyx_v_dir2;
        __pyx_t_12 = -1;
        if (__pyx_t_20 < 0) {
          __pyx_t_20 += __pyx_v_locations.shape[0];
          if (unlikely(__pyx_t_20 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_20 >= __pyx_v_locations.shape[0])) __pyx_t_12 = 0;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_locations.shape[1];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 1;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_locations.shape[1])) __pyx_t_12 = 1;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5926, __pyx_L1_error)
        }
        __pyx_t_11 = ((__pyx_v_i100->location[__pyx_v_dir2]) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_locations.data + __pyx_t_20 * __pyx_v_locations.strides[0]) ) + __pyx_t_19 * __pyx_v_locations.strides[1]) ))));

        /* "discretize/_extensions/tree_ext.pyx":5927
 *                 if dim == 3 and i100.index != i000.index:
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/
 *                           (i100.location[dir2] - i000.location[dir2]))             # <<<<<<<<<<<<<<
 *                 else:
 *                     w3 = 1.0
 */
        __Pyx_TraceLine(5927,0,__PYX_ERR(0, 5927, __pyx_L1_error))
        __pyx_t_21 = ((__pyx_v_i100->location[__pyx_v_dir2]) - (__pyx_v_i000->location[__pyx_v_dir2]));

        /* "discretize/_extensions/tree_ext.pyx":5926
 * 
 *                 if dim == 3 and i100.index != i000.index:
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/             # <<<<<<<<<<<<<<
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 */
        __Pyx_TraceLine(5926,0,__PYX_ERR(0, 5926, __pyx_L1_error))
        if (unlikely(__pyx_t_21 == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "float division");
          __PYX_ERR(0, 5926, __pyx_L1_error)
        }
        __pyx_t_6 = PyFloat_FromDouble((__pyx_t_11 / __pyx_t_21)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5926, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_XDECREF_SET(__pyx_v_w3, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "discretize/_extensions/tree_ext.pyx":5925
 *                     w2 = 1.0
 * 
 *                 if dim == 3 and i100.index != i000.index:             # <<<<<<<<<<<<<<
 *                     w3 = ((i100.location[dir2] - locations[i, dir2])/
 *                           (i100.location[dir2] - i000.location[dir2]))
 */
        goto __pyx_L70;
      }

      /* "discretize/_extensions/tree_ext.pyx":5929
 *                           (i100.location[dir2] - i000.location[dir2]))
 *                 else:
 *                     w3 = 1.0             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(5929,0,__PYX_ERR(0, 5929, __pyx_L1_error))
      /*else*/ {
        __Pyx_INCREF(__pyx_float_1_0);
        __Pyx_XDECREF_SET(__pyx_v_w3, __pyx_float_1_0);
      }
      __pyx_L70:;

      /* "discretize/_extensions/tree_ext.pyx":5932
 * 
 * 
 *                 w1 = _clip01(w1)             # <<<<<<<<<<<<<<
 *                 w2 = _clip01(w2)
 *                 w3 = _clip01(w3)
 */
      __Pyx_TraceLine(5932,0,__PYX_ERR(0, 5932, __pyx_L1_error))
      __pyx_v_w1 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w1);

      /* "discretize/_extensions/tree_ext.pyx":5933
 * 
 *                 w1 = _clip01(w1)
 *                 w2 = _clip01(w2)             # <<<<<<<<<<<<<<
 *                 w3 = _clip01(w3)
 *                 row_data[0] = w1 * w2 * w3
 */
      __Pyx_TraceLine(5933,0,__PYX_ERR(0, 5933, __pyx_L1_error))
      __pyx_v_w2 = __pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_v_w2);

      /* "discretize/_extensions/tree_ext.pyx":5934
 *                 w1 = _clip01(w1)
 *                 w2 = _clip01(w2)
 *                 w3 = _clip01(w3)             # <<<<<<<<<<<<<<
 *                 row_data[0] = w1 * w2 * w3
 *                 row_data[1] = (1 - w1) * w2 * w3
 */
      __Pyx_TraceLine(5934,0,__PYX_ERR(0, 5934, __pyx_L1_error))
      __pyx_t_21 = __pyx_PyFloat_AsDouble(__pyx_v_w3); if (unlikely((__pyx_t_21 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 5934, __pyx_L1_error)
      __pyx_t_6 = PyFloat_FromDouble(__pyx_f_10discretize_11_extensions_8tree_ext__clip01(__pyx_t_21)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5934, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF_SET(__pyx_v_w3, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "discretize/_extensions/tree_ext.pyx":5935
 *                 w2 = _clip01(w2)
 *                 w3 = _clip01(w3)
 *                 row_data[0] = w1 * w2 * w3             # <<<<<<<<<<<<<<
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3
 */
      __Pyx_TraceLine(5935,0,__PYX_ERR(0, 5935, __pyx_L1_error))
      __pyx_t_6 = PyFloat_FromDouble((__pyx_v_w1 * __pyx_v_w2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5935, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_w3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5935, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5935, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_19 = 0;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5935, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":5936
 *                 w3 = _clip01(w3)
 *                 row_data[0] = w1 * w2 * w3
 *                 row_data[1] = (1 - w1) * w2 * w3             # <<<<<<<<<<<<<<
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 */
      __Pyx_TraceLine(5936,0,__PYX_ERR(0, 5936, __pyx_L1_error))
      __pyx_t_3 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * __pyx_v_w2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5936, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_v_w3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5936, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5936, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_19 = 1;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5936, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":5937
 *                 row_data[0] = w1 * w2 * w3
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index
 */
      __Pyx_TraceLine(5937,0,__PYX_ERR(0, 5937, __pyx_L1_error))
      __pyx_t_6 = PyFloat_FromDouble((__pyx_v_w1 * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5937, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_w3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5937, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5937, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_19 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5937, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":5938
 *                 row_data[1] = (1 - w1) * w2 * w3
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3             # <<<<<<<<<<<<<<
 *                 row_inds[0] = i000.index
 *                 row_inds[1] = i001.index
 */
      __Pyx_TraceLine(5938,0,__PYX_ERR(0, 5938, __pyx_L1_error))
      __pyx_t_3 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5938, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_v_w3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5938, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5938, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_19 = 3;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_data.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5938, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":5939
 *                 row_data[2] = w1 * (1 - w2) * w3
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index             # <<<<<<<<<<<<<<
 *                 row_inds[1] = i001.index
 *                 row_inds[2] = i010.index
 */
      __Pyx_TraceLine(5939,0,__PYX_ERR(0, 5939, __pyx_L1_error))
      __pyx_t_23 = __pyx_v_i000->index;
      __pyx_t_19 = 0;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5939, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

      /* "discretize/_extensions/tree_ext.pyx":5940
 *                 row_data[3] = (1 - w1) * (1 - w2) * w3
 *                 row_inds[0] = i000.index
 *                 row_inds[1] = i001.index             # <<<<<<<<<<<<<<
 *                 row_inds[2] = i010.index
 *                 row_inds[3] = i011.index
 */
      __Pyx_TraceLine(5940,0,__PYX_ERR(0, 5940, __pyx_L1_error))
      __pyx_t_23 = __pyx_v_i001->index;
      __pyx_t_19 = 1;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5940, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

      /* "discretize/_extensions/tree_ext.pyx":5941
 *                 row_inds[0] = i000.index
 *                 row_inds[1] = i001.index
 *                 row_inds[2] = i010.index             # <<<<<<<<<<<<<<
 *                 row_inds[3] = i011.index
 *                 if dim==3:
 */
      __Pyx_TraceLine(5941,0,__PYX_ERR(0, 5941, __pyx_L1_error))
      __pyx_t_23 = __pyx_v_i010->index;
      __pyx_t_19 = 2;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5941, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

      /* "discretize/_extensions/tree_ext.pyx":5942
 *                 row_inds[1] = i001.index
 *                 row_inds[2] = i010.index
 *                 row_inds[3] = i011.index             # <<<<<<<<<<<<<<
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)
 */
      __Pyx_TraceLine(5942,0,__PYX_ERR(0, 5942, __pyx_L1_error))
      __pyx_t_23 = __pyx_v_i011->index;
      __pyx_t_19 = 3;
      __pyx_t_12 = -1;
      if (__pyx_t_19 < 0) {
        __pyx_t_19 += __pyx_v_row_inds.shape[0];
        if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 5942, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

      /* "discretize/_extensions/tree_ext.pyx":5943
 *                 row_inds[2] = i010.index
 *                 row_inds[3] = i011.index
 *                 if dim==3:             # <<<<<<<<<<<<<<
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 */
      __Pyx_TraceLine(5943,0,__PYX_ERR(0, 5943, __pyx_L1_error))
      __pyx_t_17 = ((__pyx_v_dim == 3) != 0);
      if (__pyx_t_17) {

        /* "discretize/_extensions/tree_ext.pyx":5944
 *                 row_inds[3] = i011.index
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5944,0,__PYX_ERR(0, 5944, __pyx_L1_error))
        __pyx_t_6 = PyFloat_FromDouble((__pyx_v_w1 * __pyx_v_w2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5944, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_w3, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5944, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5944, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5944, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_19 = 4;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5944, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

        /* "discretize/_extensions/tree_ext.pyx":5945
 *                 if dim==3:
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 */
        __Pyx_TraceLine(5945,0,__PYX_ERR(0, 5945, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * __pyx_v_w2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5945, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_w3, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5945, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PyNumber_Multiply(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5945, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5945, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_19 = 5;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5945, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

        /* "discretize/_extensions/tree_ext.pyx":5946
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index
 */
        __Pyx_TraceLine(5946,0,__PYX_ERR(0, 5946, __pyx_L1_error))
        __pyx_t_6 = PyFloat_FromDouble((__pyx_v_w1 * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5946, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_w3, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5946, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_5 = PyNumber_Multiply(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5946, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5946, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_19 = 6;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5946, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

        /* "discretize/_extensions/tree_ext.pyx":5947
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)             # <<<<<<<<<<<<<<
 *                     row_inds[4] = i100.index
 *                     row_inds[5] = i101.index
 */
        __Pyx_TraceLine(5947,0,__PYX_ERR(0, 5947, __pyx_L1_error))
        __pyx_t_5 = PyFloat_FromDouble(((1.0 - __pyx_v_w1) * (1.0 - __pyx_v_w2))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5947, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_w3, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5947, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PyNumber_Multiply(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5947, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_22 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 5947, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_19 = 7;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_data.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_data.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5947, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_row_data.data + __pyx_t_19 * __pyx_v_row_data.strides[0]) )) = __pyx_t_22;

        /* "discretize/_extensions/tree_ext.pyx":5948
 *                     row_data[6] = w1 * (1 - w2) * (1 - w3)
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index             # <<<<<<<<<<<<<<
 *                     row_inds[5] = i101.index
 *                     row_inds[6] = i110.index
 */
        __Pyx_TraceLine(5948,0,__PYX_ERR(0, 5948, __pyx_L1_error))
        __pyx_t_23 = __pyx_v_i100->index;
        __pyx_t_19 = 4;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5948, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

        /* "discretize/_extensions/tree_ext.pyx":5949
 *                     row_data[7] = (1 - w1) * (1 - w2) * (1 - w3)
 *                     row_inds[4] = i100.index
 *                     row_inds[5] = i101.index             # <<<<<<<<<<<<<<
 *                     row_inds[6] = i110.index
 *                     row_inds[7] = i111.index
 */
        __Pyx_TraceLine(5949,0,__PYX_ERR(0, 5949, __pyx_L1_error))
        __pyx_t_23 = __pyx_v_i101->index;
        __pyx_t_19 = 5;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5949, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

        /* "discretize/_extensions/tree_ext.pyx":5950
 *                     row_inds[4] = i100.index
 *                     row_inds[5] = i101.index
 *                     row_inds[6] = i110.index             # <<<<<<<<<<<<<<
 *                     row_inds[7] = i111.index
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0],self.n_cells))
 */
        __Pyx_TraceLine(5950,0,__PYX_ERR(0, 5950, __pyx_L1_error))
        __pyx_t_23 = __pyx_v_i110->index;
        __pyx_t_19 = 6;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5950, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

        /* "discretize/_extensions/tree_ext.pyx":5951
 *                     row_inds[5] = i101.index
 *                     row_inds[6] = i110.index
 *                     row_inds[7] = i111.index             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0],self.n_cells))
 * 
 */
        __Pyx_TraceLine(5951,0,__PYX_ERR(0, 5951, __pyx_L1_error))
        __pyx_t_23 = __pyx_v_i111->index;
        __pyx_t_19 = 7;
        __pyx_t_12 = -1;
        if (__pyx_t_19 < 0) {
          __pyx_t_19 += __pyx_v_row_inds.shape[0];
          if (unlikely(__pyx_t_19 < 0)) __pyx_t_12 = 0;
        } else if (unlikely(__pyx_t_19 >= __pyx_v_row_inds.shape[0])) __pyx_t_12 = 0;
        if (unlikely(__pyx_t_12 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_12);
          __PYX_ERR(0, 5951, __pyx_L1_error)
        }
        *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_row_inds.data + __pyx_t_19 * __pyx_v_row_inds.strides[0]) )) = __pyx_t_23;

        /* "discretize/_extensions/tree_ext.pyx":5943
 *                 row_inds[2] = i010.index
 *                 row_inds[3] = i011.index
 *                 if dim==3:             # <<<<<<<<<<<<<<
 *                     row_data[4] = w1 * w2 * (1 - w3)
 *                     row_data[5] = (1 - w1) * w2 * (1 - w3)
 */
      }
    }
    __pyx_L5:;
  }

  /* "discretize/_extensions/tree_ext.pyx":5952
 *                     row_inds[6] = i110.index
 *                     row_inds[7] = i111.index
 *         return sp.csr_matrix((data, indices, indptr), shape=(locs.shape[0],self.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(5952,0,__PYX_ERR(0, 5952, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_data, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_float64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_float64_t, 0);; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_indices, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_indptr, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4);
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_locs, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5736
 *         return sp.csr_matrix((V, (I, J)), shape=(locs.shape[0],self.n_total_nodes))*Rn
 * 
 *     def _getCellIntMat(self, locs, zeros_outside):             # <<<<<<<<<<<<<<
 *         cdef:
 *             double[:, :] locations = locs
 */

  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._getCellIntMat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_locations, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indptr, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indices, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_data, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_row_inds, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_row_data, 1);
  __Pyx_XDECREF(__pyx_v_w3);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5955
 * 
 *     @property
 *     def cell_nodes(self):             # <<<<<<<<<<<<<<
 *         """The index of all nodes for each cell.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int_t __pyx_v_npc;
  PyObject *__pyx_v_inds = NULL;
  __Pyx_memviewslice __pyx_v_node_index = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_i;
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_9;
  std::vector<Cell *>  *__pyx_t_10;
  Cell *__pyx_t_11;
  int_t __pyx_t_12;
  int_t __pyx_t_13;
  int_t __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 5955, 0, __PYX_ERR(0, 5955, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5969
 *         TreeMesh.total_nodes
 *         """
 *         cdef int_t npc = 4 if self.dim == 2 else 8             # <<<<<<<<<<<<<<
 *         inds = np.empty((self.n_cells, npc), dtype=np.int64)
 *         cdef np.int64_t[:, :] node_index = inds
 */
  __Pyx_TraceLine(5969,0,__PYX_ERR(0, 5969, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 5969, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {
    __pyx_t_1 = 4;
  } else {
    __pyx_t_1 = 8;
  }
  __pyx_v_npc = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":5970
 *         """
 *         cdef int_t npc = 4 if self.dim == 2 else 8
 *         inds = np.empty((self.n_cells, npc), dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:, :] node_index = inds
 *         cdef int_t i
 */
  __Pyx_TraceLine(5970,0,__PYX_ERR(0, 5970, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_int_t(__pyx_v_npc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5970, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_inds = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5971
 *         cdef int_t npc = 4 if self.dim == 2 else 8
 *         inds = np.empty((self.n_cells, npc), dtype=np.int64)
 *         cdef np.int64_t[:, :] node_index = inds             # <<<<<<<<<<<<<<
 *         cdef int_t i
 * 
 */
  __Pyx_TraceLine(5971,0,__PYX_ERR(0, 5971, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(__pyx_v_inds, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 5971, __pyx_L1_error)
  __pyx_v_node_index = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":5974
 *         cdef int_t i
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             for i in range(npc):
 *                 node_index[cell.index, i] = cell.points[i].index
 */
  __Pyx_TraceLine(5974,0,__PYX_ERR(0, 5974, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->cells;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_cell = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":5975
 * 
 *         for cell in self.tree.cells:
 *             for i in range(npc):             # <<<<<<<<<<<<<<
 *                 node_index[cell.index, i] = cell.points[i].index
 * 
 */
    __Pyx_TraceLine(5975,0,__PYX_ERR(0, 5975, __pyx_L1_error))
    __pyx_t_1 = __pyx_v_npc;
    __pyx_t_12 = __pyx_t_1;
    for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
      __pyx_v_i = __pyx_t_13;

      /* "discretize/_extensions/tree_ext.pyx":5976
 *         for cell in self.tree.cells:
 *             for i in range(npc):
 *                 node_index[cell.index, i] = cell.points[i].index             # <<<<<<<<<<<<<<
 * 
 *         return inds
 */
      __Pyx_TraceLine(5976,0,__PYX_ERR(0, 5976, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_cell->points[__pyx_v_i])->index;
      __pyx_t_15 = __pyx_v_cell->index;
      __pyx_t_16 = __pyx_v_i;
      __pyx_t_17 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v_node_index.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v_node_index.shape[0])) __pyx_t_17 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_node_index.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_node_index.shape[1])) __pyx_t_17 = 1;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 5976, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_node_index.data + __pyx_t_15 * __pyx_v_node_index.strides[0]) ) + __pyx_t_16 * __pyx_v_node_index.strides[1]) )) = __pyx_t_14;
    }

    /* "discretize/_extensions/tree_ext.pyx":5974
 *         cdef int_t i
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             for i in range(npc):
 *                 node_index[cell.index, i] = cell.points[i].index
 */
    __Pyx_TraceLine(5974,0,__PYX_ERR(0, 5974, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":5978
 *                 node_index[cell.index, i] = cell.points[i].index
 * 
 *         return inds             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(5978,0,__PYX_ERR(0, 5978, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_inds);
  __pyx_r = __pyx_v_inds;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5955
 * 
 *     @property
 *     def cell_nodes(self):             # <<<<<<<<<<<<<<
 *         """The index of all nodes for each cell.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.cell_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_inds);
  __PYX_XDEC_MEMVIEW(&__pyx_v_node_index, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":5981
 * 
 *     @property
 *     def edge_nodes(self):             # <<<<<<<<<<<<<<
 *         """The index of nodes for every edge.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_inds_x = NULL;
  PyObject *__pyx_v_inds_y = NULL;
  __Pyx_memviewslice __pyx_v_edge_inds = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::pair<int_t,Edge *>  __pyx_v_it;
  Edge *__pyx_v_edge;
  PyObject *__pyx_v_inds_z = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::map<int_t,Edge *> ::iterator __pyx_t_7;
  edge_map_t *__pyx_t_8;
  std::pair<int_t,Edge *>  __pyx_t_9;
  Edge *__pyx_t_10;
  int_t __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 5981, 0, __PYX_ERR(0, 5981, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":5995
 *         These arrays will also index into the hanging nodes.
 *         """
 *         inds_x = np.empty((self.n_total_edges_x, 2), dtype=np.int64)             # <<<<<<<<<<<<<<
 *         inds_y = np.empty((self.n_total_edges_y, 2), dtype=np.int64)
 *         cdef np.int64_t[:, :] edge_inds
 */
  __Pyx_TraceLine(5995,0,__PYX_ERR(0, 5995, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_2);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_inds_x = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5996
 *         """
 *         inds_x = np.empty((self.n_total_edges_x, 2), dtype=np.int64)
 *         inds_y = np.empty((self.n_total_edges_y, 2), dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:, :] edge_inds
 * 
 */
  __Pyx_TraceLine(5996,0,__PYX_ERR(0, 5996, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_INCREF(__pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_2);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 5996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_inds_y = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "discretize/_extensions/tree_ext.pyx":5999
 *         cdef np.int64_t[:, :] edge_inds
 * 
 *         edge_inds = inds_x             # <<<<<<<<<<<<<<
 *         for it in self.tree.edges_x:
 *             edge = it.second
 */
  __Pyx_TraceLine(5999,0,__PYX_ERR(0, 5999, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(__pyx_v_inds_x, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 5999, __pyx_L1_error)
  __pyx_v_edge_inds = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6000
 * 
 *         edge_inds = inds_x
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
  __Pyx_TraceLine(6000,0,__PYX_ERR(0, 6000, __pyx_L1_error))
  __pyx_t_8 = &__pyx_v_self->tree->edges_x;
  __pyx_t_7 = __pyx_t_8->begin();
  for (;;) {
    if (!(__pyx_t_7 != __pyx_t_8->end())) break;
    __pyx_t_9 = *__pyx_t_7;
    ++__pyx_t_7;
    __pyx_v_it = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":6001
 *         edge_inds = inds_x
 *         for it in self.tree.edges_x:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index
 */
    __Pyx_TraceLine(6001,0,__PYX_ERR(0, 6001, __pyx_L1_error))
    __pyx_t_10 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":6002
 *         for it in self.tree.edges_x:
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 */
    __Pyx_TraceLine(6002,0,__PYX_ERR(0, 6002, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[0])->index;
    __pyx_t_12 = __pyx_v_edge->index;
    __pyx_t_13 = 0;
    __pyx_t_14 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6002, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_12 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_13 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6003
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *         edge_inds = inds_y
 */
    __Pyx_TraceLine(6003,0,__PYX_ERR(0, 6003, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[1])->index;
    __pyx_t_13 = __pyx_v_edge->index;
    __pyx_t_12 = 1;
    __pyx_t_14 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6003, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_13 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_12 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6000
 * 
 *         edge_inds = inds_x
 *         for it in self.tree.edges_x:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
    __Pyx_TraceLine(6000,0,__PYX_ERR(0, 6000, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6005
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 *         edge_inds = inds_y             # <<<<<<<<<<<<<<
 *         for it in self.tree.edges_y:
 *             edge = it.second
 */
  __Pyx_TraceLine(6005,0,__PYX_ERR(0, 6005, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(__pyx_v_inds_y, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 6005, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_v_edge_inds, 1);
  __pyx_v_edge_inds = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6006
 * 
 *         edge_inds = inds_y
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
  __Pyx_TraceLine(6006,0,__PYX_ERR(0, 6006, __pyx_L1_error))
  __pyx_t_8 = &__pyx_v_self->tree->edges_y;
  __pyx_t_7 = __pyx_t_8->begin();
  for (;;) {
    if (!(__pyx_t_7 != __pyx_t_8->end())) break;
    __pyx_t_9 = *__pyx_t_7;
    ++__pyx_t_7;
    __pyx_v_it = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":6007
 *         edge_inds = inds_y
 *         for it in self.tree.edges_y:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index
 */
    __Pyx_TraceLine(6007,0,__PYX_ERR(0, 6007, __pyx_L1_error))
    __pyx_t_10 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":6008
 *         for it in self.tree.edges_y:
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 */
    __Pyx_TraceLine(6008,0,__PYX_ERR(0, 6008, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[0])->index;
    __pyx_t_12 = __pyx_v_edge->index;
    __pyx_t_13 = 0;
    __pyx_t_14 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6008, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_12 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_13 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6009
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *         if self.dim == 2:
 */
    __Pyx_TraceLine(6009,0,__PYX_ERR(0, 6009, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[1])->index;
    __pyx_t_13 = __pyx_v_edge->index;
    __pyx_t_12 = 1;
    __pyx_t_14 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6009, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_13 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_12 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6006
 * 
 *         edge_inds = inds_y
 *         for it in self.tree.edges_y:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
    __Pyx_TraceLine(6006,0,__PYX_ERR(0, 6006, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6011
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return inds_x, inds_y
 * 
 */
  __Pyx_TraceLine(6011,0,__PYX_ERR(0, 6011, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 6011, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_15) {

    /* "discretize/_extensions/tree_ext.pyx":6012
 * 
 *         if self.dim == 2:
 *             return inds_x, inds_y             # <<<<<<<<<<<<<<
 * 
 *         inds_z = np.empty((self.n_total_edges_z, 2), dtype=np.int64)
 */
    __Pyx_TraceLine(6012,0,__PYX_ERR(0, 6012, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_inds_x);
    __Pyx_GIVEREF(__pyx_v_inds_x);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_inds_x);
    __Pyx_INCREF(__pyx_v_inds_y);
    __Pyx_GIVEREF(__pyx_v_inds_y);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_inds_y);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6011
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             return inds_x, inds_y
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6014
 *             return inds_x, inds_y
 * 
 *         inds_z = np.empty((self.n_total_edges_z, 2), dtype=np.int64)             # <<<<<<<<<<<<<<
 *         edge_inds = inds_z
 *         for it in self.tree.edges_z:
 */
  __Pyx_TraceLine(6014,0,__PYX_ERR(0, 6014, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_total_edges_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_2);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_inds_z = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6015
 * 
 *         inds_z = np.empty((self.n_total_edges_z, 2), dtype=np.int64)
 *         edge_inds = inds_z             # <<<<<<<<<<<<<<
 *         for it in self.tree.edges_z:
 *             edge = it.second
 */
  __Pyx_TraceLine(6015,0,__PYX_ERR(0, 6015, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(__pyx_v_inds_z, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 6015, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_v_edge_inds, 1);
  __pyx_v_edge_inds = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6016
 *         inds_z = np.empty((self.n_total_edges_z, 2), dtype=np.int64)
 *         edge_inds = inds_z
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
  __Pyx_TraceLine(6016,0,__PYX_ERR(0, 6016, __pyx_L1_error))
  __pyx_t_8 = &__pyx_v_self->tree->edges_z;
  __pyx_t_7 = __pyx_t_8->begin();
  for (;;) {
    if (!(__pyx_t_7 != __pyx_t_8->end())) break;
    __pyx_t_9 = *__pyx_t_7;
    ++__pyx_t_7;
    __pyx_v_it = __pyx_t_9;

    /* "discretize/_extensions/tree_ext.pyx":6017
 *         edge_inds = inds_z
 *         for it in self.tree.edges_z:
 *             edge = it.second             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index
 */
    __Pyx_TraceLine(6017,0,__PYX_ERR(0, 6017, __pyx_L1_error))
    __pyx_t_10 = __pyx_v_it.second;
    __pyx_v_edge = __pyx_t_10;

    /* "discretize/_extensions/tree_ext.pyx":6018
 *         for it in self.tree.edges_z:
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index             # <<<<<<<<<<<<<<
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 */
    __Pyx_TraceLine(6018,0,__PYX_ERR(0, 6018, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[0])->index;
    __pyx_t_12 = __pyx_v_edge->index;
    __pyx_t_13 = 0;
    __pyx_t_14 = -1;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6018, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_12 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_13 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6019
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 *             edge_inds[edge.index, 1] = edge.points[1].index             # <<<<<<<<<<<<<<
 * 
 *         return inds_x, inds_y, inds_z
 */
    __Pyx_TraceLine(6019,0,__PYX_ERR(0, 6019, __pyx_L1_error))
    __pyx_t_11 = (__pyx_v_edge->points[1])->index;
    __pyx_t_13 = __pyx_v_edge->index;
    __pyx_t_12 = 1;
    __pyx_t_14 = -1;
    if (__pyx_t_13 < 0) {
      __pyx_t_13 += __pyx_v_edge_inds.shape[0];
      if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0;
    } else if (unlikely(__pyx_t_13 >= __pyx_v_edge_inds.shape[0])) __pyx_t_14 = 0;
    if (__pyx_t_12 < 0) {
      __pyx_t_12 += __pyx_v_edge_inds.shape[1];
      if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 1;
    } else if (unlikely(__pyx_t_12 >= __pyx_v_edge_inds.shape[1])) __pyx_t_14 = 1;
    if (unlikely(__pyx_t_14 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_14);
      __PYX_ERR(0, 6019, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_edge_inds.data + __pyx_t_13 * __pyx_v_edge_inds.strides[0]) ) + __pyx_t_12 * __pyx_v_edge_inds.strides[1]) )) = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6016
 *         inds_z = np.empty((self.n_total_edges_z, 2), dtype=np.int64)
 *         edge_inds = inds_z
 *         for it in self.tree.edges_z:             # <<<<<<<<<<<<<<
 *             edge = it.second
 *             edge_inds[edge.index, 0] = edge.points[0].index
 */
    __Pyx_TraceLine(6016,0,__PYX_ERR(0, 6016, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6021
 *             edge_inds[edge.index, 1] = edge.points[1].index
 * 
 *         return inds_x, inds_y, inds_z             # <<<<<<<<<<<<<<
 * 
 *     def __getstate__(self):
 */
  __Pyx_TraceLine(6021,0,__PYX_ERR(0, 6021, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_inds_x);
  __Pyx_GIVEREF(__pyx_v_inds_x);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_inds_x);
  __Pyx_INCREF(__pyx_v_inds_y);
  __Pyx_GIVEREF(__pyx_v_inds_y);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_inds_y);
  __Pyx_INCREF(__pyx_v_inds_z);
  __Pyx_GIVEREF(__pyx_v_inds_z);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_inds_z);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":5981
 * 
 *     @property
 *     def edge_nodes(self):             # <<<<<<<<<<<<<<
 *         """The index of nodes for every edge.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.edge_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_inds_x);
  __Pyx_XDECREF(__pyx_v_inds_y);
  __PYX_XDEC_MEMVIEW(&__pyx_v_edge_inds, 1);
  __Pyx_XDECREF(__pyx_v_inds_z);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6023
 *         return inds_x, inds_y, inds_z
 * 
 *     def __getstate__(self):             # <<<<<<<<<<<<<<
 *         """Get the current state of the TreeMesh."""
 *         cdef int id, dim = self._dim
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_89__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_88__getstate__[] = "_TreeMesh.__getstate__(self)\nGet the current state of the TreeMesh.";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_89__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_88__getstate__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_88__getstate__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  int __pyx_v_id;
  int __pyx_v_dim;
  PyObject *__pyx_v_indArr = NULL;
  PyObject *__pyx_v_levels = NULL;
  __Pyx_memviewslice __pyx_v__indArr = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v__levels = { 0, 0, { 0 }, { 0 }, { 0 } };
  Cell *__pyx_v_cell;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_9;
  std::vector<Cell *>  *__pyx_t_10;
  Cell *__pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  PY_LONG_LONG __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getstate__", 0);
  __Pyx_TraceCall("__getstate__", __pyx_f[0], 6023, 0, __PYX_ERR(0, 6023, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6025
 *     def __getstate__(self):
 *         """Get the current state of the TreeMesh."""
 *         cdef int id, dim = self._dim             # <<<<<<<<<<<<<<
 *         indArr = np.empty((self.n_cells, dim), dtype=np.int64)
 *         levels = np.empty((self.n_cells), dtype=np.int32)
 */
  __Pyx_TraceLine(6025,0,__PYX_ERR(0, 6025, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->_dim;
  __pyx_v_dim = __pyx_t_1;

  /* "discretize/_extensions/tree_ext.pyx":6026
 *         """Get the current state of the TreeMesh."""
 *         cdef int id, dim = self._dim
 *         indArr = np.empty((self.n_cells, dim), dtype=np.int64)             # <<<<<<<<<<<<<<
 *         levels = np.empty((self.n_cells), dtype=np.int32)
 *         cdef np.int64_t[:, :] _indArr = indArr
 */
  __Pyx_TraceLine(6026,0,__PYX_ERR(0, 6026, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_indArr = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6027
 *         cdef int id, dim = self._dim
 *         indArr = np.empty((self.n_cells, dim), dtype=np.int64)
 *         levels = np.empty((self.n_cells), dtype=np.int32)             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:, :] _indArr = indArr
 *         cdef np.int32_t[:] _levels = levels
 */
  __Pyx_TraceLine(6027,0,__PYX_ERR(0, 6027, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_levels = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6028
 *         indArr = np.empty((self.n_cells, dim), dtype=np.int64)
 *         levels = np.empty((self.n_cells), dtype=np.int32)
 *         cdef np.int64_t[:, :] _indArr = indArr             # <<<<<<<<<<<<<<
 *         cdef np.int32_t[:] _levels = levels
 *         for cell in self.tree.cells:
 */
  __Pyx_TraceLine(6028,0,__PYX_ERR(0, 6028, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(__pyx_v_indArr, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 6028, __pyx_L1_error)
  __pyx_v__indArr = __pyx_t_7;
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6029
 *         levels = np.empty((self.n_cells), dtype=np.int32)
 *         cdef np.int64_t[:, :] _indArr = indArr
 *         cdef np.int32_t[:] _levels = levels             # <<<<<<<<<<<<<<
 *         for cell in self.tree.cells:
 *             for id in range(dim):
 */
  __Pyx_TraceLine(6029,0,__PYX_ERR(0, 6029, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int32_t(__pyx_v_levels, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 6029, __pyx_L1_error)
  __pyx_v__levels = __pyx_t_8;
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6030
 *         cdef np.int64_t[:, :] _indArr = indArr
 *         cdef np.int32_t[:] _levels = levels
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             for id in range(dim):
 *                 _indArr[cell.index, id] = cell.location_ind[id]
 */
  __Pyx_TraceLine(6030,0,__PYX_ERR(0, 6030, __pyx_L1_error))
  __pyx_t_10 = &__pyx_v_self->tree->cells;
  __pyx_t_9 = __pyx_t_10->begin();
  for (;;) {
    if (!(__pyx_t_9 != __pyx_t_10->end())) break;
    __pyx_t_11 = *__pyx_t_9;
    ++__pyx_t_9;
    __pyx_v_cell = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6031
 *         cdef np.int32_t[:] _levels = levels
 *         for cell in self.tree.cells:
 *             for id in range(dim):             # <<<<<<<<<<<<<<
 *                 _indArr[cell.index, id] = cell.location_ind[id]
 *             _levels[cell.index] = cell.level
 */
    __Pyx_TraceLine(6031,0,__PYX_ERR(0, 6031, __pyx_L1_error))
    __pyx_t_12 = __pyx_v_dim;
    __pyx_t_13 = __pyx_t_12;
    for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
      __pyx_v_id = __pyx_t_14;

      /* "discretize/_extensions/tree_ext.pyx":6032
 *         for cell in self.tree.cells:
 *             for id in range(dim):
 *                 _indArr[cell.index, id] = cell.location_ind[id]             # <<<<<<<<<<<<<<
 *             _levels[cell.index] = cell.level
 *         return indArr, levels
 */
      __Pyx_TraceLine(6032,0,__PYX_ERR(0, 6032, __pyx_L1_error))
      __pyx_t_15 = __pyx_v_cell->index;
      __pyx_t_16 = __pyx_v_id;
      __pyx_t_17 = -1;
      if (__pyx_t_15 < 0) {
        __pyx_t_15 += __pyx_v__indArr.shape[0];
        if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0;
      } else if (unlikely(__pyx_t_15 >= __pyx_v__indArr.shape[0])) __pyx_t_17 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v__indArr.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v__indArr.shape[1])) __pyx_t_17 = 1;
      if (unlikely(__pyx_t_17 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_17);
        __PYX_ERR(0, 6032, __pyx_L1_error)
      }
      *((__pyx_t_5numpy_int64_t *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v__indArr.data + __pyx_t_15 * __pyx_v__indArr.strides[0]) ) + __pyx_t_16 * __pyx_v__indArr.strides[1]) )) = (__pyx_v_cell->location_ind[__pyx_v_id]);
    }

    /* "discretize/_extensions/tree_ext.pyx":6033
 *             for id in range(dim):
 *                 _indArr[cell.index, id] = cell.location_ind[id]
 *             _levels[cell.index] = cell.level             # <<<<<<<<<<<<<<
 *         return indArr, levels
 * 
 */
    __Pyx_TraceLine(6033,0,__PYX_ERR(0, 6033, __pyx_L1_error))
    __pyx_t_1 = __pyx_v_cell->level;
    __pyx_t_15 = __pyx_v_cell->index;
    __pyx_t_12 = -1;
    if (__pyx_t_15 < 0) {
      __pyx_t_15 += __pyx_v__levels.shape[0];
      if (unlikely(__pyx_t_15 < 0)) __pyx_t_12 = 0;
    } else if (unlikely(__pyx_t_15 >= __pyx_v__levels.shape[0])) __pyx_t_12 = 0;
    if (unlikely(__pyx_t_12 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_12);
      __PYX_ERR(0, 6033, __pyx_L1_error)
    }
    *((__pyx_t_5numpy_int32_t *) ( /* dim=0 */ (__pyx_v__levels.data + __pyx_t_15 * __pyx_v__levels.strides[0]) )) = __pyx_t_1;

    /* "discretize/_extensions/tree_ext.pyx":6030
 *         cdef np.int64_t[:, :] _indArr = indArr
 *         cdef np.int32_t[:] _levels = levels
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             for id in range(dim):
 *                 _indArr[cell.index, id] = cell.location_ind[id]
 */
    __Pyx_TraceLine(6030,0,__PYX_ERR(0, 6030, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6034
 *                 _indArr[cell.index, id] = cell.location_ind[id]
 *             _levels[cell.index] = cell.level
 *         return indArr, levels             # <<<<<<<<<<<<<<
 * 
 *     def __setstate__(self, state):
 */
  __Pyx_TraceLine(6034,0,__PYX_ERR(0, 6034, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6034, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_indArr);
  __Pyx_GIVEREF(__pyx_v_indArr);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_indArr);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_GIVEREF(__pyx_v_levels);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_levels);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6023
 *         return inds_x, inds_y, inds_z
 * 
 *     def __getstate__(self):             # <<<<<<<<<<<<<<
 *         """Get the current state of the TreeMesh."""
 *         cdef int id, dim = self._dim
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indArr);
  __Pyx_XDECREF(__pyx_v_levels);
  __PYX_XDEC_MEMVIEW(&__pyx_v__indArr, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v__levels, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6036
 *         return indArr, levels
 * 
 *     def __setstate__(self, state):             # <<<<<<<<<<<<<<
 *         """Set the current state of the TreeMesh."""
 *         indArr, levels = state
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_91__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_90__setstate__[] = "_TreeMesh.__setstate__(self, state)\nSet the current state of the TreeMesh.";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_91__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_90__setstate__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_state));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_90__setstate__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_state) {
  PyObject *__pyx_v_indArr = NULL;
  PyObject *__pyx_v_levels = NULL;
  PyObject *__pyx_v_xs = NULL;
  PyObject *__pyx_v_ys = NULL;
  PyObject *__pyx_v_zs = NULL;
  PyObject *__pyx_v_points = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate__", 0);
  __Pyx_TraceCall("__setstate__", __pyx_f[0], 6036, 0, __PYX_ERR(0, 6036, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6038
 *     def __setstate__(self, state):
 *         """Set the current state of the TreeMesh."""
 *         indArr, levels = state             # <<<<<<<<<<<<<<
 *         indArr = np.asarray(indArr)
 *         levels = np.asarray(levels)
 */
  __Pyx_TraceLine(6038,0,__PYX_ERR(0, 6038, __pyx_L1_error))
  if ((likely(PyTuple_CheckExact(__pyx_v_state))) || (PyList_CheckExact(__pyx_v_state))) {
    PyObject* sequence = __pyx_v_state;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 6038, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
  } else {
    Py_ssize_t index = -1;
    __pyx_t_3 = PyObject_GetIter(__pyx_v_state); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_2 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_4(__pyx_t_3), 2) < 0) __PYX_ERR(0, 6038, __pyx_L1_error)
    __pyx_t_4 = NULL;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 6038, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  __pyx_v_indArr = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_levels = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6039
 *         """Set the current state of the TreeMesh."""
 *         indArr, levels = state
 *         indArr = np.asarray(indArr)             # <<<<<<<<<<<<<<
 *         levels = np.asarray(levels)
 *         xs = np.array(self._xs)
 */
  __Pyx_TraceLine(6039,0,__PYX_ERR(0, 6039, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_asarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_v_indArr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_indArr);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_indArr, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6040
 *         indArr, levels = state
 *         indArr = np.asarray(indArr)
 *         levels = np.asarray(levels)             # <<<<<<<<<<<<<<
 *         xs = np.array(self._xs)
 *         ys = np.array(self._ys)
 */
  __Pyx_TraceLine(6040,0,__PYX_ERR(0, 6040, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asarray); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_levels) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_levels);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6041
 *         indArr = np.asarray(indArr)
 *         levels = np.asarray(levels)
 *         xs = np.array(self._xs)             # <<<<<<<<<<<<<<
 *         ys = np.array(self._ys)
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(6041,0,__PYX_ERR(0, 6041, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6041, __pyx_L1_error)}
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_self->_xs, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_xs = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6042
 *         levels = np.asarray(levels)
 *         xs = np.array(self._xs)
 *         ys = np.array(self._ys)             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             zs = np.array(self._zs)
 */
  __Pyx_TraceLine(6042,0,__PYX_ERR(0, 6042, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6042, __pyx_L1_error)}
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_self->_ys, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ys = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6043
 *         xs = np.array(self._xs)
 *         ys = np.array(self._ys)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             zs = np.array(self._zs)
 *             points = np.column_stack((xs[indArr[:, 0]],
 */
  __Pyx_TraceLine(6043,0,__PYX_ERR(0, 6043, __pyx_L1_error))
  __pyx_t_6 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_6) {

    /* "discretize/_extensions/tree_ext.pyx":6044
 *         ys = np.array(self._ys)
 *         if self._dim == 3:
 *             zs = np.array(self._zs)             # <<<<<<<<<<<<<<
 *             points = np.column_stack((xs[indArr[:, 0]],
 *                                       ys[indArr[:, 1]],
 */
    __Pyx_TraceLine(6044,0,__PYX_ERR(0, 6044, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6044, __pyx_L1_error)}
    __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_self->_zs, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_zs = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6045
 *         if self._dim == 3:
 *             zs = np.array(self._zs)
 *             points = np.column_stack((xs[indArr[:, 0]],             # <<<<<<<<<<<<<<
 *                                       ys[indArr[:, 1]],
 *                                       zs[indArr[:, 2]]))
 */
    __Pyx_TraceLine(6045,0,__PYX_ERR(0, 6045, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_column_stack); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__21); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_xs, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6046
 *             zs = np.array(self._zs)
 *             points = np.column_stack((xs[indArr[:, 0]],
 *                                       ys[indArr[:, 1]],             # <<<<<<<<<<<<<<
 *                                       zs[indArr[:, 2]]))
 *         else:
 */
    __Pyx_TraceLine(6046,0,__PYX_ERR(0, 6046, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__22); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_ys, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6047
 *             points = np.column_stack((xs[indArr[:, 0]],
 *                                       ys[indArr[:, 1]],
 *                                       zs[indArr[:, 2]]))             # <<<<<<<<<<<<<<
 *         else:
 *             points = np.column_stack((xs[indArr[:, 0]], ys[indArr[:, 1]]))
 */
    __Pyx_TraceLine(6047,0,__PYX_ERR(0, 6047, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__23); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_zs, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6045
 *         if self._dim == 3:
 *             zs = np.array(self._zs)
 *             points = np.column_stack((xs[indArr[:, 0]],             # <<<<<<<<<<<<<<
 *                                       ys[indArr[:, 1]],
 *                                       zs[indArr[:, 2]]))
 */
    __Pyx_TraceLine(6045,0,__PYX_ERR(0, 6045, __pyx_L1_error))
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
    __pyx_t_5 = 0;
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_points = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6043
 *         xs = np.array(self._xs)
 *         ys = np.array(self._ys)
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             zs = np.array(self._zs)
 *             points = np.column_stack((xs[indArr[:, 0]],
 */
    goto __pyx_L5;
  }

  /* "discretize/_extensions/tree_ext.pyx":6049
 *                                       zs[indArr[:, 2]]))
 *         else:
 *             points = np.column_stack((xs[indArr[:, 0]], ys[indArr[:, 1]]))             # <<<<<<<<<<<<<<
 *         # Set diagonal balance as false. If the state itself came from a diagonally
 *         # balanced tree, those cells will naturally be included in the state information
 */
  __Pyx_TraceLine(6049,0,__PYX_ERR(0, 6049, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_column_stack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_xs, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_ys, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
    __pyx_t_8 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_points = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_L5:;

  /* "discretize/_extensions/tree_ext.pyx":6055
 *         # us to support reading in older TreeMesh that are not diagonally balanced when
 *         # we switch the default to be a diagonally balanced tree.
 *         self.insert_cells(points, levels, diagonal_balance=False)             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key):
 */
  __Pyx_TraceLine(6055,0,__PYX_ERR(0, 6055, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_insert_cells); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_points);
  __Pyx_GIVEREF(__pyx_v_points);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_points);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_GIVEREF(__pyx_v_levels);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_levels);
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_diagonal_balance, Py_False) < 0) __PYX_ERR(0, 6055, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6036
 *         return indArr, levels
 * 
 *     def __setstate__(self, state):             # <<<<<<<<<<<<<<
 *         """Set the current state of the TreeMesh."""
 *         indArr, levels = state
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indArr);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_xs);
  __Pyx_XDECREF(__pyx_v_ys);
  __Pyx_XDECREF(__pyx_v_zs);
  __Pyx_XDECREF(__pyx_v_points);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6057
 *         self.insert_cells(points, levels, diagonal_balance=False)
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         """Get a TreeCell or cells.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_93__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__[] = "Get a TreeCell or cells.\n\n        Each item of the TreeMesh is a TreeCell that contains information\n        about the\n\n        Returns\n        -------\n        discretize.tree_mesh.TreeCell\n        ";
#if CYTHON_UPDATE_DESCRIPTOR_DOC
struct wrapperbase __pyx_wrapperbase_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__;
#endif
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_93__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_key));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_key) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *__pyx_v_pycell = NULL;
  PyObject *__pyx_7genexpr__pyx_v_ii = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  std::vector<Cell *> ::size_type __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);
  __Pyx_TraceCall("__getitem__", __pyx_f[0], 6057, 0, __PYX_ERR(0, 6057, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_key);

  /* "discretize/_extensions/tree_ext.pyx":6067
 *         discretize.tree_mesh.TreeCell
 *         """
 *         if isinstance(key, slice):             # <<<<<<<<<<<<<<
 *             # Get the start, stop, and step from the slice
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 */
  __Pyx_TraceLine(6067,0,__PYX_ERR(0, 6067, __pyx_L1_error))
  __pyx_t_1 = PySlice_Check(__pyx_v_key); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":6069
 *         if isinstance(key, slice):
 *             # Get the start, stop, and step from the slice
 *             return [self[ii] for ii in range(*key.indices(len(self)))]             # <<<<<<<<<<<<<<
 *         elif isinstance(key, (int, np.integer)):
 *             if key < 0:  # Handle negative indices
 */
    __Pyx_TraceLine(6069,0,__PYX_ERR(0, 6069, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    { /* enter inner scope */
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_indices); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 6069, __pyx_L6_error)
      __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PySequence_Tuple(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6069, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
        __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
        __pyx_t_9 = NULL;
      } else {
        __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6069, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6069, __pyx_L6_error)
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      for (;;) {
        if (likely(!__pyx_t_9)) {
          if (likely(PyList_CheckExact(__pyx_t_5))) {
            if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 6069, __pyx_L6_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6069, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          } else {
            if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 6069, __pyx_L6_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6069, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          }
        } else {
          __pyx_t_4 = __pyx_t_9(__pyx_t_5);
          if (unlikely(!__pyx_t_4)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 6069, __pyx_L6_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_4);
        }
        __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_ii, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_7genexpr__pyx_v_ii); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6069, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 6069, __pyx_L6_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ii); __pyx_7genexpr__pyx_v_ii = 0;
      goto __pyx_L9_exit_scope;
      __pyx_L6_error:;
      __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ii); __pyx_7genexpr__pyx_v_ii = 0;
      goto __pyx_L1_error;
      __pyx_L9_exit_scope:;
    } /* exit inner scope */
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6067
 *         discretize.tree_mesh.TreeCell
 *         """
 *         if isinstance(key, slice):             # <<<<<<<<<<<<<<
 *             # Get the start, stop, and step from the slice
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6070
 *             # Get the start, stop, and step from the slice
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 *         elif isinstance(key, (int, np.integer)):             # <<<<<<<<<<<<<<
 *             if key < 0:  # Handle negative indices
 *                 key += len(self)
 */
  __Pyx_TraceLine(6070,0,__PYX_ERR(0, 6070, __pyx_L1_error))
  __pyx_t_1 = PyInt_Check(__pyx_v_key); 
  __pyx_t_10 = (__pyx_t_1 != 0);
  if (!__pyx_t_10) {
  } else {
    __pyx_t_2 = __pyx_t_10;
    goto __pyx_L10_bool_binop_done;
  }
  __pyx_t_10 = __Pyx_TypeCheck(__pyx_v_key, __pyx_ptype_5numpy_integer); 
  __pyx_t_1 = (__pyx_t_10 != 0);
  __pyx_t_2 = __pyx_t_1;
  __pyx_L10_bool_binop_done:;
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (likely(__pyx_t_1)) {

    /* "discretize/_extensions/tree_ext.pyx":6071
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 *         elif isinstance(key, (int, np.integer)):
 *             if key < 0:  # Handle negative indices             # <<<<<<<<<<<<<<
 *                 key += len(self)
 *             if key >= len(self):
 */
    __Pyx_TraceLine(6071,0,__PYX_ERR(0, 6071, __pyx_L1_error))
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_key, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6071, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 6071, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_1) {

      /* "discretize/_extensions/tree_ext.pyx":6072
 *         elif isinstance(key, (int, np.integer)):
 *             if key < 0:  # Handle negative indices
 *                 key += len(self)             # <<<<<<<<<<<<<<
 *             if key >= len(self):
 *                 raise IndexError(
 */
      __Pyx_TraceLine(6072,0,__PYX_ERR(0, 6072, __pyx_L1_error))
      __pyx_t_6 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 6072, __pyx_L1_error)
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6072, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_key, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6072, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6071
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 *         elif isinstance(key, (int, np.integer)):
 *             if key < 0:  # Handle negative indices             # <<<<<<<<<<<<<<
 *                 key += len(self)
 *             if key >= len(self):
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6073
 *             if key < 0:  # Handle negative indices
 *                 key += len(self)
 *             if key >= len(self):             # <<<<<<<<<<<<<<
 *                 raise IndexError(
 *                     "The index ({0:d}) is out of range.".format(key)
 */
    __Pyx_TraceLine(6073,0,__PYX_ERR(0, 6073, __pyx_L1_error))
    __pyx_t_6 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 6073, __pyx_L1_error)
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6073, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_key, __pyx_t_5, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6073, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 6073, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(__pyx_t_1)) {

      /* "discretize/_extensions/tree_ext.pyx":6075
 *             if key >= len(self):
 *                 raise IndexError(
 *                     "The index ({0:d}) is out of range.".format(key)             # <<<<<<<<<<<<<<
 *                 )
 *             pycell = TreeCell()
 */
      __Pyx_TraceLine(6075,0,__PYX_ERR(0, 6075, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_The_index_0_d_is_out_of_range, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6075, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_key) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_key);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6075, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6074
 *                 key += len(self)
 *             if key >= len(self):
 *                 raise IndexError(             # <<<<<<<<<<<<<<
 *                     "The index ({0:d}) is out of range.".format(key)
 *                 )
 */
      __Pyx_TraceLine(6074,0,__PYX_ERR(0, 6074, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6074, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 6074, __pyx_L1_error)

      /* "discretize/_extensions/tree_ext.pyx":6073
 *             if key < 0:  # Handle negative indices
 *                 key += len(self)
 *             if key >= len(self):             # <<<<<<<<<<<<<<
 *                 raise IndexError(
 *                     "The index ({0:d}) is out of range.".format(key)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6077
 *                     "The index ({0:d}) is out of range.".format(key)
 *                 )
 *             pycell = TreeCell()             # <<<<<<<<<<<<<<
 *             pycell._set(self.tree.cells[key])
 *             return pycell
 */
    __Pyx_TraceLine(6077,0,__PYX_ERR(0, 6077, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_10discretize_11_extensions_8tree_ext_TreeCell)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_pycell = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6078
 *                 )
 *             pycell = TreeCell()
 *             pycell._set(self.tree.cells[key])             # <<<<<<<<<<<<<<
 *             return pycell
 *         else:
 */
    __Pyx_TraceLine(6078,0,__PYX_ERR(0, 6078, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_v_key); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 6078, __pyx_L1_error)
    ((struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell *)__pyx_v_pycell->__pyx_vtab)->_set(__pyx_v_pycell, (__pyx_v_self->tree->cells[__pyx_t_11]));

    /* "discretize/_extensions/tree_ext.pyx":6079
 *             pycell = TreeCell()
 *             pycell._set(self.tree.cells[key])
 *             return pycell             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError("Invalid argument type.")
 */
    __Pyx_TraceLine(6079,0,__PYX_ERR(0, 6079, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_pycell));
    __pyx_r = ((PyObject *)__pyx_v_pycell);
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6070
 *             # Get the start, stop, and step from the slice
 *             return [self[ii] for ii in range(*key.indices(len(self)))]
 *         elif isinstance(key, (int, np.integer)):             # <<<<<<<<<<<<<<
 *             if key < 0:  # Handle negative indices
 *                 key += len(self)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6081
 *             return pycell
 *         else:
 *             raise TypeError("Invalid argument type.")             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(6081,0,__PYX_ERR(0, 6081, __pyx_L1_error))
  /*else*/ {
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6081, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 6081, __pyx_L1_error)
  }

  /* "discretize/_extensions/tree_ext.pyx":6057
 *         self.insert_cells(points, levels, diagonal_balance=False)
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         """Get a TreeCell or cells.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_pycell);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ii);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6084
 * 
 *     @property
 *     def _ubc_indArr(self):             # <<<<<<<<<<<<<<
 *         if self.__ubc_indArr is not None:
 *             return self.__ubc_indArr
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_indArr = NULL;
  PyObject *__pyx_v_levels = NULL;
  PyObject *__pyx_v_max_level = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 6084, 0, __PYX_ERR(0, 6084, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6085
 *     @property
 *     def _ubc_indArr(self):
 *         if self.__ubc_indArr is not None:             # <<<<<<<<<<<<<<
 *             return self.__ubc_indArr
 *         indArr, levels = self.__getstate__()
 */
  __Pyx_TraceLine(6085,0,__PYX_ERR(0, 6085, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->__pyx___ubc_indArr != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":6086
 *     def _ubc_indArr(self):
 *         if self.__ubc_indArr is not None:
 *             return self.__ubc_indArr             # <<<<<<<<<<<<<<
 *         indArr, levels = self.__getstate__()
 * 
 */
    __Pyx_TraceLine(6086,0,__PYX_ERR(0, 6086, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->__pyx___ubc_indArr);
    __pyx_r = __pyx_v_self->__pyx___ubc_indArr;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6085
 *     @property
 *     def _ubc_indArr(self):
 *         if self.__ubc_indArr is not None:             # <<<<<<<<<<<<<<
 *             return self.__ubc_indArr
 *         indArr, levels = self.__getstate__()
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6087
 *         if self.__ubc_indArr is not None:
 *             return self.__ubc_indArr
 *         indArr, levels = self.__getstate__()             # <<<<<<<<<<<<<<
 * 
 *         max_level = self.tree.max_level
 */
  __Pyx_TraceLine(6087,0,__PYX_ERR(0, 6087, __pyx_L1_error))
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getstate); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6087, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6087, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 6087, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 6087, __pyx_L1_error)
    __pyx_t_7 = NULL;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 6087, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_v_indArr = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_levels = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6089
 *         indArr, levels = self.__getstate__()
 * 
 *         max_level = self.tree.max_level             # <<<<<<<<<<<<<<
 * 
 *         levels = 1<<(max_level - levels)
 */
  __Pyx_TraceLine(6089,0,__PYX_ERR(0, 6089, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyInt_From_int_t(__pyx_v_self->tree->max_level); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_max_level = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6091
 *         max_level = self.tree.max_level
 * 
 *         levels = 1<<(max_level - levels)             # <<<<<<<<<<<<<<
 * 
 *         if self.dim == 2:
 */
  __Pyx_TraceLine(6091,0,__PYX_ERR(0, 6091, __pyx_L1_error))
  __pyx_t_3 = PyNumber_Subtract(__pyx_v_max_level, __pyx_v_levels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Lshift(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_levels, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6093
 *         levels = 1<<(max_level - levels)
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             indArr[:, -1] = (self._ys.shape[0]-1) - indArr[:, -1]
 *         else:
 */
  __Pyx_TraceLine(6093,0,__PYX_ERR(0, 6093, __pyx_L1_error))
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 6093, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":6094
 * 
 *         if self.dim == 2:
 *             indArr[:, -1] = (self._ys.shape[0]-1) - indArr[:, -1]             # <<<<<<<<<<<<<<
 *         else:
 *             indArr[:, -1] = (self._zs.shape[0]-1) - indArr[:, -1]
 */
    __Pyx_TraceLine(6094,0,__PYX_ERR(0, 6094, __pyx_L1_error))
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6094, __pyx_L1_error)}
    __pyx_t_3 = PyInt_FromSsize_t(((__pyx_v_self->_ys.shape[0]) - 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6094, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__42); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6094, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyNumber_Subtract(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6094, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_indArr, __pyx_tuple__42, __pyx_t_4) < 0)) __PYX_ERR(0, 6094, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6093
 *         levels = 1<<(max_level - levels)
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             indArr[:, -1] = (self._ys.shape[0]-1) - indArr[:, -1]
 *         else:
 */
    goto __pyx_L6;
  }

  /* "discretize/_extensions/tree_ext.pyx":6096
 *             indArr[:, -1] = (self._ys.shape[0]-1) - indArr[:, -1]
 *         else:
 *             indArr[:, -1] = (self._zs.shape[0]-1) - indArr[:, -1]             # <<<<<<<<<<<<<<
 * 
 *         indArr = (indArr - levels[:, None])//2
 */
  __Pyx_TraceLine(6096,0,__PYX_ERR(0, 6096, __pyx_L1_error))
  /*else*/ {
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6096, __pyx_L1_error)}
    __pyx_t_4 = PyInt_FromSsize_t(((__pyx_v_self->_zs.shape[0]) - 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6096, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__42); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6096, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6096, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_indArr, __pyx_tuple__42, __pyx_t_3) < 0)) __PYX_ERR(0, 6096, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L6:;

  /* "discretize/_extensions/tree_ext.pyx":6098
 *             indArr[:, -1] = (self._zs.shape[0]-1) - indArr[:, -1]
 * 
 *         indArr = (indArr - levels[:, None])//2             # <<<<<<<<<<<<<<
 *         indArr += 1
 * 
 */
  __Pyx_TraceLine(6098,0,__PYX_ERR(0, 6098, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_levels, __pyx_tuple__43); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6098, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyNumber_Subtract(__pyx_v_indArr, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6098, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_5, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6098, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_indArr, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6099
 * 
 *         indArr = (indArr - levels[:, None])//2
 *         indArr += 1             # <<<<<<<<<<<<<<
 * 
 *         self.__ubc_indArr = (indArr, levels)
 */
  __Pyx_TraceLine(6099,0,__PYX_ERR(0, 6099, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_indArr, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF_SET(__pyx_v_indArr, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6101
 *         indArr += 1
 * 
 *         self.__ubc_indArr = (indArr, levels)             # <<<<<<<<<<<<<<
 *         return self.__ubc_indArr
 * 
 */
  __Pyx_TraceLine(6101,0,__PYX_ERR(0, 6101, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_indArr);
  __Pyx_GIVEREF(__pyx_v_indArr);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_indArr);
  __Pyx_INCREF(__pyx_v_levels);
  __Pyx_GIVEREF(__pyx_v_levels);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_levels);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->__pyx___ubc_indArr);
  __Pyx_DECREF(__pyx_v_self->__pyx___ubc_indArr);
  __pyx_v_self->__pyx___ubc_indArr = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6102
 * 
 *         self.__ubc_indArr = (indArr, levels)
 *         return self.__ubc_indArr             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(6102,0,__PYX_ERR(0, 6102, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->__pyx___ubc_indArr);
  __pyx_r = __pyx_v_self->__pyx___ubc_indArr;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6084
 * 
 *     @property
 *     def _ubc_indArr(self):             # <<<<<<<<<<<<<<
 *         if self.__ubc_indArr is not None:
 *             return self.__ubc_indArr
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._ubc_indArr.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indArr);
  __Pyx_XDECREF(__pyx_v_levels);
  __Pyx_XDECREF(__pyx_v_max_level);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6105
 * 
 *     @property
 *     def _ubc_order(self):             # <<<<<<<<<<<<<<
 *         if self.__ubc_order is not None:
 *             return self.__ubc_order
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order___get__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order___get__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_v_indArr = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 6105, 0, __PYX_ERR(0, 6105, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6106
 *     @property
 *     def _ubc_order(self):
 *         if self.__ubc_order is not None:             # <<<<<<<<<<<<<<
 *             return self.__ubc_order
 *         indArr, _ = self._ubc_indArr
 */
  __Pyx_TraceLine(6106,0,__PYX_ERR(0, 6106, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->__pyx___ubc_order != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":6107
 *     def _ubc_order(self):
 *         if self.__ubc_order is not None:
 *             return self.__ubc_order             # <<<<<<<<<<<<<<
 *         indArr, _ = self._ubc_indArr
 *         if self.dim == 2:
 */
    __Pyx_TraceLine(6107,0,__PYX_ERR(0, 6107, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->__pyx___ubc_order);
    __pyx_r = __pyx_v_self->__pyx___ubc_order;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6106
 *     @property
 *     def _ubc_order(self):
 *         if self.__ubc_order is not None:             # <<<<<<<<<<<<<<
 *             return self.__ubc_order
 *         indArr, _ = self._ubc_indArr
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6108
 *         if self.__ubc_order is not None:
 *             return self.__ubc_order
 *         indArr, _ = self._ubc_indArr             # <<<<<<<<<<<<<<
 *         if self.dim == 2:
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1]))
 */
  __Pyx_TraceLine(6108,0,__PYX_ERR(0, 6108, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ubc_indArr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 6108, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 6108, __pyx_L1_error)
    __pyx_t_7 = NULL;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 6108, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_v_indArr = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v__ = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "discretize/_extensions/tree_ext.pyx":6109
 *             return self.__ubc_order
 *         indArr, _ = self._ubc_indArr
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1]))
 *         else:
 */
  __Pyx_TraceLine(6109,0,__PYX_ERR(0, 6109, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 6109, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_2) {

    /* "discretize/_extensions/tree_ext.pyx":6110
 *         indArr, _ = self._ubc_indArr
 *         if self.dim == 2:
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1]))             # <<<<<<<<<<<<<<
 *         else:
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1], indArr[:, 2]))
 */
    __Pyx_TraceLine(6110,0,__PYX_ERR(0, 6110, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_lexsort); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__21); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__22); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
    __pyx_t_3 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->__pyx___ubc_order);
    __Pyx_DECREF(__pyx_v_self->__pyx___ubc_order);
    __pyx_v_self->__pyx___ubc_order = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6109
 *             return self.__ubc_order
 *         indArr, _ = self._ubc_indArr
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1]))
 *         else:
 */
    goto __pyx_L6;
  }

  /* "discretize/_extensions/tree_ext.pyx":6112
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1]))
 *         else:
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1], indArr[:, 2]))             # <<<<<<<<<<<<<<
 *         return self.__ubc_order
 * 
 */
  __Pyx_TraceLine(6112,0,__PYX_ERR(0, 6112, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_lexsort); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__22); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_indArr, __pyx_tuple__23); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_6 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6112, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->__pyx___ubc_order);
    __Pyx_DECREF(__pyx_v_self->__pyx___ubc_order);
    __pyx_v_self->__pyx___ubc_order = __pyx_t_5;
    __pyx_t_5 = 0;
  }
  __pyx_L6:;

  /* "discretize/_extensions/tree_ext.pyx":6113
 *         else:
 *             self.__ubc_order = np.lexsort((indArr[:, 0], indArr[:, 1], indArr[:, 2]))
 *         return self.__ubc_order             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_TraceLine(6113,0,__PYX_ERR(0, 6113, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->__pyx___ubc_order);
  __pyx_r = __pyx_v_self->__pyx___ubc_order;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6105
 * 
 *     @property
 *     def _ubc_order(self):             # <<<<<<<<<<<<<<
 *         if self.__ubc_order is not None:
 *             return self.__ubc_order
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._ubc_order.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indArr);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6115
 *         return self.__ubc_order
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         del self.tree
 *         del self.wrapper
 */

/* Python wrapper */
static void __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_95__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_95__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_94__dealloc__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static void __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_94__dealloc__(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 6115, 0, __PYX_ERR(0, 6115, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6116
 * 
 *     def __dealloc__(self):
 *         del self.tree             # <<<<<<<<<<<<<<
 *         del self.wrapper
 * 
 */
  __Pyx_TraceLine(6116,0,__PYX_ERR(0, 6116, __pyx_L1_error))
  delete __pyx_v_self->tree;

  /* "discretize/_extensions/tree_ext.pyx":6117
 *     def __dealloc__(self):
 *         del self.tree
 *         del self.wrapper             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(6117,0,__PYX_ERR(0, 6117, __pyx_L1_error))
  delete __pyx_v_self->wrapper;

  /* "discretize/_extensions/tree_ext.pyx":6115
 *         return self.__ubc_order
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         del self.tree
 *         del self.wrapper
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("discretize._extensions.tree_ext._TreeMesh.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "discretize/_extensions/tree_ext.pyx":6121
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_from_tree(self, _TreeMesh meshin, values=None, output=None):             # <<<<<<<<<<<<<<
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_97_vol_avg_from_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_96_vol_avg_from_tree[] = "_TreeMesh._vol_avg_from_tree(self, _TreeMesh meshin, values=None, output=None)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_97_vol_avg_from_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_meshin = 0;
  PyObject *__pyx_v_values = 0;
  PyObject *__pyx_v_output = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_vol_avg_from_tree (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_meshin,&__pyx_n_s_values,&__pyx_n_s_output,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    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_meshin)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_values);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_output);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_vol_avg_from_tree") < 0)) __PYX_ERR(0, 6121, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_meshin = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)values[0]);
    __pyx_v_values = values[1];
    __pyx_v_output = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_vol_avg_from_tree", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 6121, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_meshin), __pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh, 1, "meshin", 0))) __PYX_ERR(0, 6121, __pyx_L1_error)
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_96_vol_avg_from_tree(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_meshin, __pyx_v_values, __pyx_v_output);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_96_vol_avg_from_tree(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_meshin, PyObject *__pyx_v_values, PyObject *__pyx_v_output) {
  int_t __pyx_v_same_base;
  Cell *__pyx_v_out_cell;
  Cell *__pyx_v_in_cell;
  __Pyx_memviewslice __pyx_v_vals = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_outs = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_build_mat;
  std::vector<int_t>  __pyx_v_row_inds;
  std::vector<int_t>  __pyx_v_col_inds;
  std::vector<int_t>  __pyx_v_indptr;
  std::vector<double>  __pyx_v_all_weights;
  double *__pyx_v_weights;
  double __pyx_v_over_lap_vol;
  double __pyx_v_x1m;
  double __pyx_v_x1p;
  double __pyx_v_y1m;
  double __pyx_v_y1p;
  double __pyx_v_z1m;
  double __pyx_v_z1p;
  double __pyx_v_x2m;
  double __pyx_v_x2p;
  double __pyx_v_y2m;
  double __pyx_v_y2p;
  double __pyx_v_z2m;
  double __pyx_v_z2p;
  __Pyx_memviewslice __pyx_v_origin = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_xF = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_nnz_counter;
  int_t __pyx_v_nnz_row;
  int_t __pyx_v_i;
  int_t __pyx_v_in_cell_ind;
  int_t __pyx_v_n_overlap;
  double __pyx_v_weight_sum;
  double __pyx_v_weight;
  std::vector<int_t>  __pyx_v_out_visited;
  int_t __pyx_v_n_unvisited;
  PyObject *__pyx_v_P = NULL;
  Cell *__pyx_v_cell;
  std::vector<int_t>  __pyx_v_overlapping_cell_inds;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int_t __pyx_t_13;
  __Pyx_memviewslice __pyx_t_14 = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_t_15;
  __Pyx_memviewslice __pyx_t_16 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_17;
  std::vector<double> ::size_type __pyx_t_18;
  std::vector<int_t> ::size_type __pyx_t_19;
  std::vector<Cell *> ::iterator __pyx_t_20;
  std::vector<Cell *>  *__pyx_t_21;
  Cell *__pyx_t_22;
  PY_LONG_LONG __pyx_t_23;
  PY_LONG_LONG __pyx_t_24;
  PyObject *__pyx_t_25 = NULL;
  double __pyx_t_26;
  double __pyx_t_27;
  double __pyx_t_28;
  std::vector<int_t> ::iterator __pyx_t_29;
  double __pyx_t_30;
  int_t __pyx_t_31;
  int_t __pyx_t_32;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_vol_avg_from_tree", 0);
  __Pyx_TraceCall("_vol_avg_from_tree", __pyx_f[0], 6121, 0, __PYX_ERR(0, 6121, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_output);

  /* "discretize/_extensions/tree_ext.pyx":6124
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, meshin.nodes_x)
 */
  __Pyx_TraceLine(6124,0,__PYX_ERR(0, 6124, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "discretize/_extensions/tree_ext.pyx":6126
 *         try:
 *             same_base = (
 *                 np.allclose(self.nodes_x, meshin.nodes_x)             # <<<<<<<<<<<<<<
 *                 and np.allclose(self.nodes_y, meshin.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, meshin.nodes_z))
 */
      __Pyx_TraceLine(6126,0,__PYX_ERR(0, 6126, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6126, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_allclose); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6126, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6126, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6126, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6126, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6126, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6126, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_6 = 0;
        __pyx_t_8 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6126, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6126, __pyx_L3_error)
      if (__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6126, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6127
 *             same_base = (
 *                 np.allclose(self.nodes_x, meshin.nodes_x)
 *                 and np.allclose(self.nodes_y, meshin.nodes_y)             # <<<<<<<<<<<<<<
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, meshin.nodes_z))
 *             )
 */
      __Pyx_TraceLine(6127,0,__PYX_ERR(0, 6127, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6127, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_allclose); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6127, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6127, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6127, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_7, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6127, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_7, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6127, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6127, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6127, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6127, __pyx_L3_error)
      if (__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6127, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6128
 *                 np.allclose(self.nodes_x, meshin.nodes_x)
 *                 and np.allclose(self.nodes_y, meshin.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, meshin.nodes_z))             # <<<<<<<<<<<<<<
 *             )
 *         except ValueError:
 */
      __Pyx_TraceLine(6128,0,__PYX_ERR(0, 6128, __pyx_L3_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_11 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6128, __pyx_L3_error)
      if (!__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_11); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6128, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_allclose); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6128, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
        __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6128, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
        __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6128, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6128, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_10, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_5 = 0;
        __pyx_t_8 = 0;
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6128, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_11); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6128, __pyx_L3_error)
      __pyx_t_4 = __pyx_t_13;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_v_same_base = __pyx_t_4;

      /* "discretize/_extensions/tree_ext.pyx":6124
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, meshin.nodes_x)
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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;

    /* "discretize/_extensions/tree_ext.pyx":6130
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, meshin.nodes_z))
 *             )
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             same_base = False
 *         cdef c_Cell * out_cell
 */
    __Pyx_TraceLine(6130,0,__PYX_ERR(0, 6130, __pyx_L5_except_error))
    __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_10) {
      __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_9, &__pyx_t_6) < 0) __PYX_ERR(0, 6130, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_6);

      /* "discretize/_extensions/tree_ext.pyx":6131
 *             )
 *         except ValueError:
 *             same_base = False             # <<<<<<<<<<<<<<
 *         cdef c_Cell * out_cell
 *         cdef c_Cell * in_cell
 */
      __Pyx_TraceLine(6131,0,__PYX_ERR(0, 6131, __pyx_L5_except_error))
      __pyx_v_same_base = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "discretize/_extensions/tree_ext.pyx":6124
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, meshin.nodes_x)
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "discretize/_extensions/tree_ext.pyx":6135
 *         cdef c_Cell * in_cell
 * 
 *         cdef np.float64_t[:] vals = np.array([])             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] outs = np.array([])
 *         cdef int_t build_mat = 1
 */
  __Pyx_TraceLine(6135,0,__PYX_ERR(0, 6135, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_array); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 6135, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_vals = __pyx_t_14;
  __pyx_t_14.memview = NULL;
  __pyx_t_14.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6136
 * 
 *         cdef np.float64_t[:] vals = np.array([])
 *         cdef np.float64_t[:] outs = np.array([])             # <<<<<<<<<<<<<<
 *         cdef int_t build_mat = 1
 * 
 */
  __Pyx_TraceLine(6136,0,__PYX_ERR(0, 6136, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_11);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_6, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 6136, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_outs = __pyx_t_14;
  __pyx_t_14.memview = NULL;
  __pyx_t_14.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6137
 *         cdef np.float64_t[:] vals = np.array([])
 *         cdef np.float64_t[:] outs = np.array([])
 *         cdef int_t build_mat = 1             # <<<<<<<<<<<<<<
 * 
 *         if values is not None:
 */
  __Pyx_TraceLine(6137,0,__PYX_ERR(0, 6137, __pyx_L1_error))
  __pyx_v_build_mat = 1;

  /* "discretize/_extensions/tree_ext.pyx":6139
 *         cdef int_t build_mat = 1
 * 
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values
 *             if output is None:
 */
  __Pyx_TraceLine(6139,0,__PYX_ERR(0, 6139, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_values != Py_None);
  __pyx_t_15 = (__pyx_t_12 != 0);
  if (__pyx_t_15) {

    /* "discretize/_extensions/tree_ext.pyx":6140
 * 
 *         if values is not None:
 *             vals = values             # <<<<<<<<<<<<<<
 *             if output is None:
 *                 output = np.empty(self.n_cells)
 */
    __Pyx_TraceLine(6140,0,__PYX_ERR(0, 6140, __pyx_L1_error))
    __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_values, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 6140, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
    __pyx_v_vals = __pyx_t_14;
    __pyx_t_14.memview = NULL;
    __pyx_t_14.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6141
 *         if values is not None:
 *             vals = values
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 */
    __Pyx_TraceLine(6141,0,__PYX_ERR(0, 6141, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_output == Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6142
 *             vals = values
 *             if output is None:
 *                 output = np.empty(self.n_cells)             # <<<<<<<<<<<<<<
 *             output[:] = 0
 *             outs = output
 */
      __Pyx_TraceLine(6142,0,__PYX_ERR(0, 6142, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6142, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6141
 *         if values is not None:
 *             vals = values
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6143
 *             if output is None:
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0             # <<<<<<<<<<<<<<
 *             outs = output
 * 
 */
    __Pyx_TraceLine(6143,0,__PYX_ERR(0, 6143, __pyx_L1_error))
    if (__Pyx_PyObject_SetSlice(__pyx_v_output, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 6143, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":6144
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 *             outs = output             # <<<<<<<<<<<<<<
 * 
 *             build_mat = 0
 */
    __Pyx_TraceLine(6144,0,__PYX_ERR(0, 6144, __pyx_L1_error))
    __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_output, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 6144, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
    __pyx_v_outs = __pyx_t_14;
    __pyx_t_14.memview = NULL;
    __pyx_t_14.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6146
 *             outs = output
 * 
 *             build_mat = 0             # <<<<<<<<<<<<<<
 * 
 *         cdef vector[int_t] row_inds, col_inds
 */
    __Pyx_TraceLine(6146,0,__PYX_ERR(0, 6146, __pyx_L1_error))
    __pyx_v_build_mat = 0;

    /* "discretize/_extensions/tree_ext.pyx":6139
 *         cdef int_t build_mat = 1
 * 
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values
 *             if output is None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6157
 *         cdef double x1m, x1p, y1m, y1p, z1m, z1p
 *         cdef double x2m, x2p, y2m, y2p, z2m, z2p
 *         cdef double[:] origin = meshin._origin             # <<<<<<<<<<<<<<
 *         cdef double[:] xF
 *         if self.dim == 2:
 */
  __Pyx_TraceLine(6157,0,__PYX_ERR(0, 6157, __pyx_L1_error))
  if (unlikely(!__pyx_v_meshin->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6157, __pyx_L1_error)}
  __pyx_t_16 = __pyx_v_meshin->_origin;
  __PYX_INC_MEMVIEW(&__pyx_t_16, 1);
  __pyx_v_origin = __pyx_t_16;
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6159
 *         cdef double[:] origin = meshin._origin
 *         cdef double[:] xF
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1]])
 *         else:
 */
  __Pyx_TraceLine(6159,0,__PYX_ERR(0, 6159, __pyx_L1_error))
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6159, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6160
 *         cdef double[:] xF
 *         if self.dim == 2:
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1]])             # <<<<<<<<<<<<<<
 *         else:
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1], meshin._zs[-1]])
 */
    __Pyx_TraceLine(6160,0,__PYX_ERR(0, 6160, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_v_meshin->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6160, __pyx_L1_error)}
    __pyx_t_17 = -1L;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_meshin->_xs.shape[0];
    __pyx_t_6 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_meshin->_xs.data + __pyx_t_17 * __pyx_v_meshin->_xs.strides[0]) )))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(!__pyx_v_meshin->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6160, __pyx_L1_error)}
    __pyx_t_17 = -1L;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_meshin->_ys.shape[0];
    __pyx_t_8 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_meshin->_ys.data + __pyx_t_17 * __pyx_v_meshin->_ys.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
    __pyx_t_6 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_11 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_11, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6160, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_v_xF = __pyx_t_16;
    __pyx_t_16.memview = NULL;
    __pyx_t_16.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6159
 *         cdef double[:] origin = meshin._origin
 *         cdef double[:] xF
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1]])
 *         else:
 */
    goto __pyx_L17;
  }

  /* "discretize/_extensions/tree_ext.pyx":6162
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1]])
 *         else:
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1], meshin._zs[-1]])             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t nnz_counter = 0
 */
  __Pyx_TraceLine(6162,0,__PYX_ERR(0, 6162, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_v_meshin->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6162, __pyx_L1_error)}
    __pyx_t_17 = -1L;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_meshin->_xs.shape[0];
    __pyx_t_9 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_meshin->_xs.data + __pyx_t_17 * __pyx_v_meshin->_xs.strides[0]) )))); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (unlikely(!__pyx_v_meshin->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6162, __pyx_L1_error)}
    __pyx_t_17 = -1L;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_meshin->_ys.shape[0];
    __pyx_t_8 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_meshin->_ys.data + __pyx_t_17 * __pyx_v_meshin->_ys.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (unlikely(!__pyx_v_meshin->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6162, __pyx_L1_error)}
    __pyx_t_17 = -1L;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_meshin->_zs.shape[0];
    __pyx_t_6 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_meshin->_zs.data + __pyx_t_17 * __pyx_v_meshin->_zs.strides[0]) )))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
    __pyx_t_9 = 0;
    __pyx_t_8 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_11 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_11, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6162, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_v_xF = __pyx_t_16;
    __pyx_t_16.memview = NULL;
    __pyx_t_16.data = NULL;
  }
  __pyx_L17:;

  /* "discretize/_extensions/tree_ext.pyx":6164
 *             xF = np.array([meshin._xs[-1], meshin._ys[-1], meshin._zs[-1]])
 * 
 *         cdef int_t nnz_counter = 0             # <<<<<<<<<<<<<<
 *         cdef int_t nnz_row = 0
 *         if build_mat:
 */
  __Pyx_TraceLine(6164,0,__PYX_ERR(0, 6164, __pyx_L1_error))
  __pyx_v_nnz_counter = 0;

  /* "discretize/_extensions/tree_ext.pyx":6165
 * 
 *         cdef int_t nnz_counter = 0
 *         cdef int_t nnz_row = 0             # <<<<<<<<<<<<<<
 *         if build_mat:
 *             indptr.push_back(0)
 */
  __Pyx_TraceLine(6165,0,__PYX_ERR(0, 6165, __pyx_L1_error))
  __pyx_v_nnz_row = 0;

  /* "discretize/_extensions/tree_ext.pyx":6166
 *         cdef int_t nnz_counter = 0
 *         cdef int_t nnz_row = 0
 *         if build_mat:             # <<<<<<<<<<<<<<
 *             indptr.push_back(0)
 *         cdef int_t i, in_cell_ind
 */
  __Pyx_TraceLine(6166,0,__PYX_ERR(0, 6166, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_build_mat != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6167
 *         cdef int_t nnz_row = 0
 *         if build_mat:
 *             indptr.push_back(0)             # <<<<<<<<<<<<<<
 *         cdef int_t i, in_cell_ind
 *         cdef int_t n_overlap
 */
    __Pyx_TraceLine(6167,0,__PYX_ERR(0, 6167, __pyx_L1_error))
    try {
      __pyx_v_indptr.push_back(0);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(0, 6167, __pyx_L1_error)
    }

    /* "discretize/_extensions/tree_ext.pyx":6166
 *         cdef int_t nnz_counter = 0
 *         cdef int_t nnz_row = 0
 *         if build_mat:             # <<<<<<<<<<<<<<
 *             indptr.push_back(0)
 *         cdef int_t i, in_cell_ind
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6176
 * 
 *         # easier path if they share the same base:
 *         if same_base:             # <<<<<<<<<<<<<<
 *             if build_mat:
 *                 all_weights.resize(meshin.n_cells, 0.0)
 */
  __Pyx_TraceLine(6176,0,__PYX_ERR(0, 6176, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_same_base != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6177
 *         # easier path if they share the same base:
 *         if same_base:
 *             if build_mat:             # <<<<<<<<<<<<<<
 *                 all_weights.resize(meshin.n_cells, 0.0)
 *                 row_inds.resize(meshin.n_cells, 0)
 */
    __Pyx_TraceLine(6177,0,__PYX_ERR(0, 6177, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_build_mat != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6178
 *         if same_base:
 *             if build_mat:
 *                 all_weights.resize(meshin.n_cells, 0.0)             # <<<<<<<<<<<<<<
 *                 row_inds.resize(meshin.n_cells, 0)
 *             out_visited.resize(self.n_cells, 0)
 */
      __Pyx_TraceLine(6178,0,__PYX_ERR(0, 6178, __pyx_L1_error))
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6178, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_18 = __Pyx_PyInt_As_size_t(__pyx_t_11); if (unlikely((__pyx_t_18 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 6178, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      try {
        __pyx_v_all_weights.resize(__pyx_t_18, 0.0);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 6178, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":6179
 *             if build_mat:
 *                 all_weights.resize(meshin.n_cells, 0.0)
 *                 row_inds.resize(meshin.n_cells, 0)             # <<<<<<<<<<<<<<
 *             out_visited.resize(self.n_cells, 0)
 *             for in_cell in meshin.tree.cells:
 */
      __Pyx_TraceLine(6179,0,__PYX_ERR(0, 6179, __pyx_L1_error))
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6179, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_19 = __Pyx_PyInt_As_size_t(__pyx_t_11); if (unlikely((__pyx_t_19 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 6179, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      try {
        __pyx_v_row_inds.resize(__pyx_t_19, 0);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 6179, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":6177
 *         # easier path if they share the same base:
 *         if same_base:
 *             if build_mat:             # <<<<<<<<<<<<<<
 *                 all_weights.resize(meshin.n_cells, 0.0)
 *                 row_inds.resize(meshin.n_cells, 0)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6180
 *                 all_weights.resize(meshin.n_cells, 0.0)
 *                 row_inds.resize(meshin.n_cells, 0)
 *             out_visited.resize(self.n_cells, 0)             # <<<<<<<<<<<<<<
 *             for in_cell in meshin.tree.cells:
 *                 # for each input cell find containing output cell
 */
    __Pyx_TraceLine(6180,0,__PYX_ERR(0, 6180, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_19 = __Pyx_PyInt_As_size_t(__pyx_t_11); if (unlikely((__pyx_t_19 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 6180, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    try {
      __pyx_v_out_visited.resize(__pyx_t_19, 0);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(0, 6180, __pyx_L1_error)
    }

    /* "discretize/_extensions/tree_ext.pyx":6181
 *                 row_inds.resize(meshin.n_cells, 0)
 *             out_visited.resize(self.n_cells, 0)
 *             for in_cell in meshin.tree.cells:             # <<<<<<<<<<<<<<
 *                 # for each input cell find containing output cell
 *                 out_cell = self.tree.containing_cell(
 */
    __Pyx_TraceLine(6181,0,__PYX_ERR(0, 6181, __pyx_L1_error))
    __pyx_t_21 = &__pyx_v_meshin->tree->cells;
    __pyx_t_20 = __pyx_t_21->begin();
    for (;;) {
      if (!(__pyx_t_20 != __pyx_t_21->end())) break;
      __pyx_t_22 = *__pyx_t_20;
      ++__pyx_t_20;
      __pyx_v_in_cell = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":6183
 *             for in_cell in meshin.tree.cells:
 *                 # for each input cell find containing output cell
 *                 out_cell = self.tree.containing_cell(             # <<<<<<<<<<<<<<
 *                     in_cell.location[0],
 *                     in_cell.location[1],
 */
      __Pyx_TraceLine(6183,0,__PYX_ERR(0, 6183, __pyx_L1_error))
      __pyx_v_out_cell = __pyx_v_self->tree->containing_cell((__pyx_v_in_cell->location[0]), (__pyx_v_in_cell->location[1]), (__pyx_v_in_cell->location[2]));

      /* "discretize/_extensions/tree_ext.pyx":6192
 *                 # else:
 *                 # contribution is 1.0
 *                 if out_cell.level < in_cell.level:             # <<<<<<<<<<<<<<
 *                     out_visited[out_cell.index] = 1
 *                     weight = in_cell.volume/out_cell.volume
 */
      __Pyx_TraceLine(6192,0,__PYX_ERR(0, 6192, __pyx_L1_error))
      __pyx_t_12 = ((__pyx_v_out_cell->level < __pyx_v_in_cell->level) != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6193
 *                 # contribution is 1.0
 *                 if out_cell.level < in_cell.level:
 *                     out_visited[out_cell.index] = 1             # <<<<<<<<<<<<<<
 *                     weight = in_cell.volume/out_cell.volume
 *                     if not build_mat:
 */
        __Pyx_TraceLine(6193,0,__PYX_ERR(0, 6193, __pyx_L1_error))
        (__pyx_v_out_visited[__pyx_v_out_cell->index]) = 1;

        /* "discretize/_extensions/tree_ext.pyx":6194
 *                 if out_cell.level < in_cell.level:
 *                     out_visited[out_cell.index] = 1
 *                     weight = in_cell.volume/out_cell.volume             # <<<<<<<<<<<<<<
 *                     if not build_mat:
 *                         outs[out_cell.index] += weight*vals[in_cell.index]
 */
        __Pyx_TraceLine(6194,0,__PYX_ERR(0, 6194, __pyx_L1_error))
        __pyx_v_weight = (__pyx_v_in_cell->volume / __pyx_v_out_cell->volume);

        /* "discretize/_extensions/tree_ext.pyx":6195
 *                     out_visited[out_cell.index] = 1
 *                     weight = in_cell.volume/out_cell.volume
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         outs[out_cell.index] += weight*vals[in_cell.index]
 *                     else:
 */
        __Pyx_TraceLine(6195,0,__PYX_ERR(0, 6195, __pyx_L1_error))
        __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
        if (__pyx_t_12) {

          /* "discretize/_extensions/tree_ext.pyx":6196
 *                     weight = in_cell.volume/out_cell.volume
 *                     if not build_mat:
 *                         outs[out_cell.index] += weight*vals[in_cell.index]             # <<<<<<<<<<<<<<
 *                     else:
 *                         all_weights[in_cell.index] = weight
 */
          __Pyx_TraceLine(6196,0,__PYX_ERR(0, 6196, __pyx_L1_error))
          __pyx_t_23 = __pyx_v_in_cell->index;
          if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_v_vals.shape[0];
          __pyx_t_24 = __pyx_v_out_cell->index;
          if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_v_outs.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_outs.data + __pyx_t_24 * __pyx_v_outs.strides[0]) )) += (__pyx_v_weight * (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_vals.data + __pyx_t_23 * __pyx_v_vals.strides[0]) ))));

          /* "discretize/_extensions/tree_ext.pyx":6195
 *                     out_visited[out_cell.index] = 1
 *                     weight = in_cell.volume/out_cell.volume
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         outs[out_cell.index] += weight*vals[in_cell.index]
 *                     else:
 */
          goto __pyx_L24;
        }

        /* "discretize/_extensions/tree_ext.pyx":6198
 *                         outs[out_cell.index] += weight*vals[in_cell.index]
 *                     else:
 *                         all_weights[in_cell.index] = weight             # <<<<<<<<<<<<<<
 *                         row_inds[in_cell.index] = out_cell.index
 * 
 */
        __Pyx_TraceLine(6198,0,__PYX_ERR(0, 6198, __pyx_L1_error))
        /*else*/ {
          (__pyx_v_all_weights[__pyx_v_in_cell->index]) = __pyx_v_weight;

          /* "discretize/_extensions/tree_ext.pyx":6199
 *                     else:
 *                         all_weights[in_cell.index] = weight
 *                         row_inds[in_cell.index] = out_cell.index             # <<<<<<<<<<<<<<
 * 
 *             if build_mat:
 */
          __Pyx_TraceLine(6199,0,__PYX_ERR(0, 6199, __pyx_L1_error))
          __pyx_t_23 = __pyx_v_out_cell->index;
          (__pyx_v_row_inds[__pyx_v_in_cell->index]) = __pyx_t_23;
        }
        __pyx_L24:;

        /* "discretize/_extensions/tree_ext.pyx":6192
 *                 # else:
 *                 # contribution is 1.0
 *                 if out_cell.level < in_cell.level:             # <<<<<<<<<<<<<<
 *                     out_visited[out_cell.index] = 1
 *                     weight = in_cell.volume/out_cell.volume
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6181
 *                 row_inds.resize(meshin.n_cells, 0)
 *             out_visited.resize(self.n_cells, 0)
 *             for in_cell in meshin.tree.cells:             # <<<<<<<<<<<<<<
 *                 # for each input cell find containing output cell
 *                 out_cell = self.tree.containing_cell(
 */
      __Pyx_TraceLine(6181,0,__PYX_ERR(0, 6181, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":6201
 *                         row_inds[in_cell.index] = out_cell.index
 * 
 *             if build_mat:             # <<<<<<<<<<<<<<
 *                 P = sp.csr_matrix((all_weights, (row_inds, np.arange(meshin.n_cells))),
 *                                   shape=(self.n_cells, meshin.n_cells))
 */
    __Pyx_TraceLine(6201,0,__PYX_ERR(0, 6201, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_build_mat != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6202
 * 
 *             if build_mat:
 *                 P = sp.csr_matrix((all_weights, (row_inds, np.arange(meshin.n_cells))),             # <<<<<<<<<<<<<<
 *                                   shape=(self.n_cells, meshin.n_cells))
 * 
 */
      __Pyx_TraceLine(6202,0,__PYX_ERR(0, 6202, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_sp); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = __pyx_convert_vector_to_py_double(__pyx_v_all_weights); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_7 = __pyx_convert_vector_to_py_int_t(__pyx_v_row_inds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_arange); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_25 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_25 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_25)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_25);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_6 = (__pyx_t_25) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_25, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
      __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_6);
      __pyx_t_7 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_9);
      __pyx_t_11 = 0;
      __pyx_t_9 = 0;
      __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6203
 *             if build_mat:
 *                 P = sp.csr_matrix((all_weights, (row_inds, np.arange(meshin.n_cells))),
 *                                   shape=(self.n_cells, meshin.n_cells))             # <<<<<<<<<<<<<<
 * 
 *                 n_unvisited = self.n_cells - np.sum(out_visited)
 */
      __Pyx_TraceLine(6203,0,__PYX_ERR(0, 6203, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
      __pyx_t_11 = 0;
      __pyx_t_7 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_shape, __pyx_t_8) < 0) __PYX_ERR(0, 6203, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6202
 * 
 *             if build_mat:
 *                 P = sp.csr_matrix((all_weights, (row_inds, np.arange(meshin.n_cells))),             # <<<<<<<<<<<<<<
 *                                   shape=(self.n_cells, meshin.n_cells))
 * 
 */
      __Pyx_TraceLine(6202,0,__PYX_ERR(0, 6202, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6202, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_P = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6205
 *                                   shape=(self.n_cells, meshin.n_cells))
 * 
 *                 n_unvisited = self.n_cells - np.sum(out_visited)             # <<<<<<<<<<<<<<
 *                 row_inds.resize(n_unvisited, 0)
 *                 col_inds.resize(n_unvisited, 0)
 */
      __Pyx_TraceLine(6205,0,__PYX_ERR(0, 6205, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_sum); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __pyx_convert_vector_to_py_int_t(__pyx_v_out_visited); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Subtract(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_4 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_4 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6205, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_n_unvisited = __pyx_t_4;

      /* "discretize/_extensions/tree_ext.pyx":6206
 * 
 *                 n_unvisited = self.n_cells - np.sum(out_visited)
 *                 row_inds.resize(n_unvisited, 0)             # <<<<<<<<<<<<<<
 *                 col_inds.resize(n_unvisited, 0)
 *             i = 0
 */
      __Pyx_TraceLine(6206,0,__PYX_ERR(0, 6206, __pyx_L1_error))
      try {
        __pyx_v_row_inds.resize(__pyx_v_n_unvisited, 0);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 6206, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":6207
 *                 n_unvisited = self.n_cells - np.sum(out_visited)
 *                 row_inds.resize(n_unvisited, 0)
 *                 col_inds.resize(n_unvisited, 0)             # <<<<<<<<<<<<<<
 *             i = 0
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 */
      __Pyx_TraceLine(6207,0,__PYX_ERR(0, 6207, __pyx_L1_error))
      try {
        __pyx_v_col_inds.resize(__pyx_v_n_unvisited, 0);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 6207, __pyx_L1_error)
      }

      /* "discretize/_extensions/tree_ext.pyx":6201
 *                         row_inds[in_cell.index] = out_cell.index
 * 
 *             if build_mat:             # <<<<<<<<<<<<<<
 *                 P = sp.csr_matrix((all_weights, (row_inds, np.arange(meshin.n_cells))),
 *                                   shape=(self.n_cells, meshin.n_cells))
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6208
 *                 row_inds.resize(n_unvisited, 0)
 *                 col_inds.resize(n_unvisited, 0)
 *             i = 0             # <<<<<<<<<<<<<<
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 *             for out_cell in self.tree.cells:
 */
    __Pyx_TraceLine(6208,0,__PYX_ERR(0, 6208, __pyx_L1_error))
    __pyx_v_i = 0;

    /* "discretize/_extensions/tree_ext.pyx":6210
 *             i = 0
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 *             for out_cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 if not out_visited[out_cell.index]:
 *                     in_cell = meshin.tree.containing_cell(
 */
    __Pyx_TraceLine(6210,0,__PYX_ERR(0, 6210, __pyx_L1_error))
    __pyx_t_21 = &__pyx_v_self->tree->cells;
    __pyx_t_20 = __pyx_t_21->begin();
    for (;;) {
      if (!(__pyx_t_20 != __pyx_t_21->end())) break;
      __pyx_t_22 = *__pyx_t_20;
      ++__pyx_t_20;
      __pyx_v_out_cell = __pyx_t_22;

      /* "discretize/_extensions/tree_ext.pyx":6211
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 *             for out_cell in self.tree.cells:
 *                 if not out_visited[out_cell.index]:             # <<<<<<<<<<<<<<
 *                     in_cell = meshin.tree.containing_cell(
 *                         out_cell.location[0],
 */
      __Pyx_TraceLine(6211,0,__PYX_ERR(0, 6211, __pyx_L1_error))
      __pyx_t_12 = ((!((__pyx_v_out_visited[__pyx_v_out_cell->index]) != 0)) != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6212
 *             for out_cell in self.tree.cells:
 *                 if not out_visited[out_cell.index]:
 *                     in_cell = meshin.tree.containing_cell(             # <<<<<<<<<<<<<<
 *                         out_cell.location[0],
 *                         out_cell.location[1],
 */
        __Pyx_TraceLine(6212,0,__PYX_ERR(0, 6212, __pyx_L1_error))
        __pyx_v_in_cell = __pyx_v_meshin->tree->containing_cell((__pyx_v_out_cell->location[0]), (__pyx_v_out_cell->location[1]), (__pyx_v_out_cell->location[2]));

        /* "discretize/_extensions/tree_ext.pyx":6218
 *                     )
 * 
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         outs[out_cell.index] = vals[in_cell.index]
 *                     else:
 */
        __Pyx_TraceLine(6218,0,__PYX_ERR(0, 6218, __pyx_L1_error))
        __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
        if (__pyx_t_12) {

          /* "discretize/_extensions/tree_ext.pyx":6219
 * 
 *                     if not build_mat:
 *                         outs[out_cell.index] = vals[in_cell.index]             # <<<<<<<<<<<<<<
 *                     else:
 *                         row_inds[i] = out_cell.index
 */
          __Pyx_TraceLine(6219,0,__PYX_ERR(0, 6219, __pyx_L1_error))
          __pyx_t_23 = __pyx_v_in_cell->index;
          if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_v_vals.shape[0];
          __pyx_t_24 = __pyx_v_out_cell->index;
          if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_v_outs.shape[0];
          *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_outs.data + __pyx_t_24 * __pyx_v_outs.strides[0]) )) = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_vals.data + __pyx_t_23 * __pyx_v_vals.strides[0]) )));

          /* "discretize/_extensions/tree_ext.pyx":6218
 *                     )
 * 
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         outs[out_cell.index] = vals[in_cell.index]
 *                     else:
 */
          goto __pyx_L29;
        }

        /* "discretize/_extensions/tree_ext.pyx":6221
 *                         outs[out_cell.index] = vals[in_cell.index]
 *                     else:
 *                         row_inds[i] = out_cell.index             # <<<<<<<<<<<<<<
 *                         col_inds[i] = in_cell.index
 *                         i += 1
 */
        __Pyx_TraceLine(6221,0,__PYX_ERR(0, 6221, __pyx_L1_error))
        /*else*/ {
          __pyx_t_23 = __pyx_v_out_cell->index;
          (__pyx_v_row_inds[__pyx_v_i]) = __pyx_t_23;

          /* "discretize/_extensions/tree_ext.pyx":6222
 *                     else:
 *                         row_inds[i] = out_cell.index
 *                         col_inds[i] = in_cell.index             # <<<<<<<<<<<<<<
 *                         i += 1
 *             if build_mat and n_unvisited > 0:
 */
          __Pyx_TraceLine(6222,0,__PYX_ERR(0, 6222, __pyx_L1_error))
          __pyx_t_23 = __pyx_v_in_cell->index;
          (__pyx_v_col_inds[__pyx_v_i]) = __pyx_t_23;

          /* "discretize/_extensions/tree_ext.pyx":6223
 *                         row_inds[i] = out_cell.index
 *                         col_inds[i] = in_cell.index
 *                         i += 1             # <<<<<<<<<<<<<<
 *             if build_mat and n_unvisited > 0:
 *                 P += sp.csr_matrix(
 */
          __Pyx_TraceLine(6223,0,__PYX_ERR(0, 6223, __pyx_L1_error))
          __pyx_v_i = (__pyx_v_i + 1);
        }
        __pyx_L29:;

        /* "discretize/_extensions/tree_ext.pyx":6211
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 *             for out_cell in self.tree.cells:
 *                 if not out_visited[out_cell.index]:             # <<<<<<<<<<<<<<
 *                     in_cell = meshin.tree.containing_cell(
 *                         out_cell.location[0],
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6210
 *             i = 0
 *             # assign weights of 1 to unvisited output cells and find their containing cell
 *             for out_cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *                 if not out_visited[out_cell.index]:
 *                     in_cell = meshin.tree.containing_cell(
 */
      __Pyx_TraceLine(6210,0,__PYX_ERR(0, 6210, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":6224
 *                         col_inds[i] = in_cell.index
 *                         i += 1
 *             if build_mat and n_unvisited > 0:             # <<<<<<<<<<<<<<
 *                 P += sp.csr_matrix(
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 */
    __Pyx_TraceLine(6224,0,__PYX_ERR(0, 6224, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_build_mat != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_12 = __pyx_t_15;
      goto __pyx_L31_bool_binop_done;
    }
    __pyx_t_15 = ((__pyx_v_n_unvisited > 0) != 0);
    __pyx_t_12 = __pyx_t_15;
    __pyx_L31_bool_binop_done:;
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6225
 *                         i += 1
 *             if build_mat and n_unvisited > 0:
 *                 P += sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 *                     shape=(self.n_cells, meshin.n_cells)
 */
      __Pyx_TraceLine(6225,0,__PYX_ERR(0, 6225, __pyx_L1_error))
      if (unlikely(!__pyx_v_P)) { __Pyx_RaiseUnboundLocalError("P"); __PYX_ERR(0, 6225, __pyx_L1_error) }
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_sp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6226
 *             if build_mat and n_unvisited > 0:
 *                 P += sp.csr_matrix(
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),             # <<<<<<<<<<<<<<
 *                     shape=(self.n_cells, meshin.n_cells)
 *                 )
 */
      __Pyx_TraceLine(6226,0,__PYX_ERR(0, 6226, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ones); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_n_unvisited); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __pyx_convert_vector_to_py_int_t(__pyx_v_row_inds); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = __pyx_convert_vector_to_py_int_t(__pyx_v_col_inds); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
      __pyx_t_9 = 0;
      __pyx_t_8 = 0;
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
      __pyx_t_5 = 0;
      __pyx_t_7 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6225
 *                         i += 1
 *             if build_mat and n_unvisited > 0:
 *                 P += sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 *                     shape=(self.n_cells, meshin.n_cells)
 */
      __Pyx_TraceLine(6225,0,__PYX_ERR(0, 6225, __pyx_L1_error))
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6227
 *                 P += sp.csr_matrix(
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 *                     shape=(self.n_cells, meshin.n_cells)             # <<<<<<<<<<<<<<
 *                 )
 *             if not build_mat:
 */
      __Pyx_TraceLine(6227,0,__PYX_ERR(0, 6227, __pyx_L1_error))
      __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9);
      __pyx_t_5 = 0;
      __pyx_t_9 = 0;
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_shape, __pyx_t_11) < 0) __PYX_ERR(0, 6227, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6225
 *                         i += 1
 *             if build_mat and n_unvisited > 0:
 *                 P += sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 *                     shape=(self.n_cells, meshin.n_cells)
 */
      __Pyx_TraceLine(6225,0,__PYX_ERR(0, 6225, __pyx_L1_error))
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_P, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF_SET(__pyx_v_P, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6224
 *                         col_inds[i] = in_cell.index
 *                         i += 1
 *             if build_mat and n_unvisited > 0:             # <<<<<<<<<<<<<<
 *                 P += sp.csr_matrix(
 *                     (np.ones(n_unvisited), (row_inds, col_inds)),
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6229
 *                     shape=(self.n_cells, meshin.n_cells)
 *                 )
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 return output
 *             return P
 */
    __Pyx_TraceLine(6229,0,__PYX_ERR(0, 6229, __pyx_L1_error))
    __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6230
 *                 )
 *             if not build_mat:
 *                 return output             # <<<<<<<<<<<<<<
 *             return P
 * 
 */
      __Pyx_TraceLine(6230,0,__PYX_ERR(0, 6230, __pyx_L1_error))
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_output);
      __pyx_r = __pyx_v_output;
      goto __pyx_L0;

      /* "discretize/_extensions/tree_ext.pyx":6229
 *                     shape=(self.n_cells, meshin.n_cells)
 *                 )
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 return output
 *             return P
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6231
 *             if not build_mat:
 *                 return output
 *             return P             # <<<<<<<<<<<<<<
 * 
 *         for cell in self.tree.cells:
 */
    __Pyx_TraceLine(6231,0,__PYX_ERR(0, 6231, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_P)) { __Pyx_RaiseUnboundLocalError("P"); __PYX_ERR(0, 6231, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_P);
    __pyx_r = __pyx_v_P;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6176
 * 
 *         # easier path if they share the same base:
 *         if same_base:             # <<<<<<<<<<<<<<
 *             if build_mat:
 *                 all_weights.resize(meshin.n_cells, 0.0)
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6233
 *             return P
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])
 */
  __Pyx_TraceLine(6233,0,__PYX_ERR(0, 6233, __pyx_L1_error))
  __pyx_t_21 = &__pyx_v_self->tree->cells;
  __pyx_t_20 = __pyx_t_21->begin();
  for (;;) {
    if (!(__pyx_t_20 != __pyx_t_21->end())) break;
    __pyx_t_22 = *__pyx_t_20;
    ++__pyx_t_20;
    __pyx_v_cell = __pyx_t_22;

    /* "discretize/_extensions/tree_ext.pyx":6234
 * 
 *         for cell in self.tree.cells:
 *             x1m = min(cell.points[0].location[0], xF[0])             # <<<<<<<<<<<<<<
 *             y1m = min(cell.points[0].location[1], xF[1])
 * 
 */
    __Pyx_TraceLine(6234,0,__PYX_ERR(0, 6234, __pyx_L1_error))
    __pyx_t_17 = 0;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
    __pyx_t_26 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )));
    __pyx_t_27 = ((__pyx_v_cell->points[0])->location[0]);
    if (((__pyx_t_26 < __pyx_t_27) != 0)) {
      __pyx_t_28 = __pyx_t_26;
    } else {
      __pyx_t_28 = __pyx_t_27;
    }
    __pyx_v_x1m = __pyx_t_28;

    /* "discretize/_extensions/tree_ext.pyx":6235
 *         for cell in self.tree.cells:
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])             # <<<<<<<<<<<<<<
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])
 */
    __Pyx_TraceLine(6235,0,__PYX_ERR(0, 6235, __pyx_L1_error))
    __pyx_t_17 = 1;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
    __pyx_t_28 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )));
    __pyx_t_26 = ((__pyx_v_cell->points[0])->location[1]);
    if (((__pyx_t_28 < __pyx_t_26) != 0)) {
      __pyx_t_27 = __pyx_t_28;
    } else {
      __pyx_t_27 = __pyx_t_26;
    }
    __pyx_v_y1m = __pyx_t_27;

    /* "discretize/_extensions/tree_ext.pyx":6237
 *             y1m = min(cell.points[0].location[1], xF[1])
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])             # <<<<<<<<<<<<<<
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:
 */
    __Pyx_TraceLine(6237,0,__PYX_ERR(0, 6237, __pyx_L1_error))
    __pyx_t_17 = 0;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
    __pyx_t_27 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )));
    __pyx_t_28 = ((__pyx_v_cell->points[3])->location[0]);
    if (((__pyx_t_27 > __pyx_t_28) != 0)) {
      __pyx_t_26 = __pyx_t_27;
    } else {
      __pyx_t_26 = __pyx_t_28;
    }
    __pyx_v_x1p = __pyx_t_26;

    /* "discretize/_extensions/tree_ext.pyx":6238
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])             # <<<<<<<<<<<<<<
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])
 */
    __Pyx_TraceLine(6238,0,__PYX_ERR(0, 6238, __pyx_L1_error))
    __pyx_t_17 = 1;
    if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
    __pyx_t_26 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )));
    __pyx_t_27 = ((__pyx_v_cell->points[3])->location[1]);
    if (((__pyx_t_26 > __pyx_t_27) != 0)) {
      __pyx_t_28 = __pyx_t_26;
    } else {
      __pyx_t_28 = __pyx_t_27;
    }
    __pyx_v_y1p = __pyx_t_28;

    /* "discretize/_extensions/tree_ext.pyx":6239
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])
 */
    __Pyx_TraceLine(6239,0,__PYX_ERR(0, 6239, __pyx_L1_error))
    __pyx_t_12 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6240
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])             # <<<<<<<<<<<<<<
 *                 z1p = max(cell.points[7].location[2], origin[2])
 *             overlapping_cell_inds = meshin.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 */
      __Pyx_TraceLine(6240,0,__PYX_ERR(0, 6240, __pyx_L1_error))
      __pyx_t_17 = 2;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
      __pyx_t_28 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )));
      __pyx_t_26 = ((__pyx_v_cell->points[0])->location[2]);
      if (((__pyx_t_28 < __pyx_t_26) != 0)) {
        __pyx_t_27 = __pyx_t_28;
      } else {
        __pyx_t_27 = __pyx_t_26;
      }
      __pyx_v_z1m = __pyx_t_27;

      /* "discretize/_extensions/tree_ext.pyx":6241
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])             # <<<<<<<<<<<<<<
 *             overlapping_cell_inds = meshin.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *             n_overlap = overlapping_cell_inds.size()
 */
      __Pyx_TraceLine(6241,0,__PYX_ERR(0, 6241, __pyx_L1_error))
      __pyx_t_17 = 2;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
      __pyx_t_27 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )));
      __pyx_t_28 = ((__pyx_v_cell->points[7])->location[2]);
      if (((__pyx_t_27 > __pyx_t_28) != 0)) {
        __pyx_t_26 = __pyx_t_27;
      } else {
        __pyx_t_26 = __pyx_t_28;
      }
      __pyx_v_z1p = __pyx_t_26;

      /* "discretize/_extensions/tree_ext.pyx":6239
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6242
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])
 *             overlapping_cell_inds = meshin.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)             # <<<<<<<<<<<<<<
 *             n_overlap = overlapping_cell_inds.size()
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 */
    __Pyx_TraceLine(6242,0,__PYX_ERR(0, 6242, __pyx_L1_error))
    __pyx_v_overlapping_cell_inds = __pyx_v_meshin->tree->find_overlapping_cells(__pyx_v_x1m, __pyx_v_x1p, __pyx_v_y1m, __pyx_v_y1p, __pyx_v_z1m, __pyx_v_z1p);

    /* "discretize/_extensions/tree_ext.pyx":6243
 *                 z1p = max(cell.points[7].location[2], origin[2])
 *             overlapping_cell_inds = meshin.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *             n_overlap = overlapping_cell_inds.size()             # <<<<<<<<<<<<<<
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 *             i = 0
 */
    __Pyx_TraceLine(6243,0,__PYX_ERR(0, 6243, __pyx_L1_error))
    __pyx_v_n_overlap = __pyx_v_overlapping_cell_inds.size();

    /* "discretize/_extensions/tree_ext.pyx":6244
 *             overlapping_cell_inds = meshin.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *             n_overlap = overlapping_cell_inds.size()
 *             weights = <double *> malloc(n_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 *             i = 0
 *             weight_sum = 0.0
 */
    __Pyx_TraceLine(6244,0,__PYX_ERR(0, 6244, __pyx_L1_error))
    __pyx_v_weights = ((double *)malloc((__pyx_v_n_overlap * (sizeof(double)))));

    /* "discretize/_extensions/tree_ext.pyx":6245
 *             n_overlap = overlapping_cell_inds.size()
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 *             i = 0             # <<<<<<<<<<<<<<
 *             weight_sum = 0.0
 *             nnz_row = 0
 */
    __Pyx_TraceLine(6245,0,__PYX_ERR(0, 6245, __pyx_L1_error))
    __pyx_v_i = 0;

    /* "discretize/_extensions/tree_ext.pyx":6246
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 *             i = 0
 *             weight_sum = 0.0             # <<<<<<<<<<<<<<
 *             nnz_row = 0
 *             for in_cell_ind in overlapping_cell_inds:
 */
    __Pyx_TraceLine(6246,0,__PYX_ERR(0, 6246, __pyx_L1_error))
    __pyx_v_weight_sum = 0.0;

    /* "discretize/_extensions/tree_ext.pyx":6247
 *             i = 0
 *             weight_sum = 0.0
 *             nnz_row = 0             # <<<<<<<<<<<<<<
 *             for in_cell_ind in overlapping_cell_inds:
 *                 in_cell = meshin.tree.cells[in_cell_ind]
 */
    __Pyx_TraceLine(6247,0,__PYX_ERR(0, 6247, __pyx_L1_error))
    __pyx_v_nnz_row = 0;

    /* "discretize/_extensions/tree_ext.pyx":6248
 *             weight_sum = 0.0
 *             nnz_row = 0
 *             for in_cell_ind in overlapping_cell_inds:             # <<<<<<<<<<<<<<
 *                 in_cell = meshin.tree.cells[in_cell_ind]
 *                 x2m = in_cell.points[0].location[0]
 */
    __Pyx_TraceLine(6248,0,__PYX_ERR(0, 6248, __pyx_L1_error))
    __pyx_t_29 = __pyx_v_overlapping_cell_inds.begin();
    for (;;) {
      if (!(__pyx_t_29 != __pyx_v_overlapping_cell_inds.end())) break;
      __pyx_t_4 = *__pyx_t_29;
      ++__pyx_t_29;
      __pyx_v_in_cell_ind = __pyx_t_4;

      /* "discretize/_extensions/tree_ext.pyx":6249
 *             nnz_row = 0
 *             for in_cell_ind in overlapping_cell_inds:
 *                 in_cell = meshin.tree.cells[in_cell_ind]             # <<<<<<<<<<<<<<
 *                 x2m = in_cell.points[0].location[0]
 *                 y2m = in_cell.points[0].location[1]
 */
      __Pyx_TraceLine(6249,0,__PYX_ERR(0, 6249, __pyx_L1_error))
      __pyx_v_in_cell = (__pyx_v_meshin->tree->cells[__pyx_v_in_cell_ind]);

      /* "discretize/_extensions/tree_ext.pyx":6250
 *             for in_cell_ind in overlapping_cell_inds:
 *                 in_cell = meshin.tree.cells[in_cell_ind]
 *                 x2m = in_cell.points[0].location[0]             # <<<<<<<<<<<<<<
 *                 y2m = in_cell.points[0].location[1]
 *                 z2m = in_cell.points[0].location[2]
 */
      __Pyx_TraceLine(6250,0,__PYX_ERR(0, 6250, __pyx_L1_error))
      __pyx_v_x2m = ((__pyx_v_in_cell->points[0])->location[0]);

      /* "discretize/_extensions/tree_ext.pyx":6251
 *                 in_cell = meshin.tree.cells[in_cell_ind]
 *                 x2m = in_cell.points[0].location[0]
 *                 y2m = in_cell.points[0].location[1]             # <<<<<<<<<<<<<<
 *                 z2m = in_cell.points[0].location[2]
 *                 x2p = in_cell.points[3].location[0]
 */
      __Pyx_TraceLine(6251,0,__PYX_ERR(0, 6251, __pyx_L1_error))
      __pyx_v_y2m = ((__pyx_v_in_cell->points[0])->location[1]);

      /* "discretize/_extensions/tree_ext.pyx":6252
 *                 x2m = in_cell.points[0].location[0]
 *                 y2m = in_cell.points[0].location[1]
 *                 z2m = in_cell.points[0].location[2]             # <<<<<<<<<<<<<<
 *                 x2p = in_cell.points[3].location[0]
 *                 y2p = in_cell.points[3].location[1]
 */
      __Pyx_TraceLine(6252,0,__PYX_ERR(0, 6252, __pyx_L1_error))
      __pyx_v_z2m = ((__pyx_v_in_cell->points[0])->location[2]);

      /* "discretize/_extensions/tree_ext.pyx":6253
 *                 y2m = in_cell.points[0].location[1]
 *                 z2m = in_cell.points[0].location[2]
 *                 x2p = in_cell.points[3].location[0]             # <<<<<<<<<<<<<<
 *                 y2p = in_cell.points[3].location[1]
 *                 z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 */
      __Pyx_TraceLine(6253,0,__PYX_ERR(0, 6253, __pyx_L1_error))
      __pyx_v_x2p = ((__pyx_v_in_cell->points[3])->location[0]);

      /* "discretize/_extensions/tree_ext.pyx":6254
 *                 z2m = in_cell.points[0].location[2]
 *                 x2p = in_cell.points[3].location[0]
 *                 y2p = in_cell.points[3].location[1]             # <<<<<<<<<<<<<<
 *                 z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 */
      __Pyx_TraceLine(6254,0,__PYX_ERR(0, 6254, __pyx_L1_error))
      __pyx_v_y2p = ((__pyx_v_in_cell->points[3])->location[1]);

      /* "discretize/_extensions/tree_ext.pyx":6255
 *                 x2p = in_cell.points[3].location[0]
 *                 y2p = in_cell.points[3].location[1]
 *                 z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0             # <<<<<<<<<<<<<<
 * 
 *                 if x1m == xF[0] or x1p == origin[0]:
 */
      __Pyx_TraceLine(6255,0,__PYX_ERR(0, 6255, __pyx_L1_error))
      if (((__pyx_v_self->_dim == 3) != 0)) {
        __pyx_t_26 = ((__pyx_v_in_cell->points[7])->location[2]);
      } else {
        __pyx_t_26 = 0.0;
      }
      __pyx_v_z2p = __pyx_t_26;

      /* "discretize/_extensions/tree_ext.pyx":6257
 *                 z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 *                 if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                     over_lap_vol = 1.0
 *                 else:
 */
      __Pyx_TraceLine(6257,0,__PYX_ERR(0, 6257, __pyx_L1_error))
      __pyx_t_17 = 0;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
      __pyx_t_15 = ((__pyx_v_x1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )))) != 0);
      if (!__pyx_t_15) {
      } else {
        __pyx_t_12 = __pyx_t_15;
        goto __pyx_L40_bool_binop_done;
      }
      __pyx_t_17 = 0;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
      __pyx_t_15 = ((__pyx_v_x1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )))) != 0);
      __pyx_t_12 = __pyx_t_15;
      __pyx_L40_bool_binop_done:;
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6258
 * 
 *                 if x1m == xF[0] or x1p == origin[0]:
 *                     over_lap_vol = 1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 */
        __Pyx_TraceLine(6258,0,__PYX_ERR(0, 6258, __pyx_L1_error))
        __pyx_v_over_lap_vol = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":6257
 *                 z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 *                 if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                     over_lap_vol = 1.0
 *                 else:
 */
        goto __pyx_L39;
      }

      /* "discretize/_extensions/tree_ext.pyx":6260
 *                     over_lap_vol = 1.0
 *                 else:
 *                     over_lap_vol = min(x1p, x2p) - max(x1m, x2m)             # <<<<<<<<<<<<<<
 *                 if y1m == xF[1] or y1p == origin[1]:
 *                     over_lap_vol *= 1.0
 */
      __Pyx_TraceLine(6260,0,__PYX_ERR(0, 6260, __pyx_L1_error))
      /*else*/ {
        __pyx_t_26 = __pyx_v_x2p;
        __pyx_t_27 = __pyx_v_x1p;
        if (((__pyx_t_26 < __pyx_t_27) != 0)) {
          __pyx_t_28 = __pyx_t_26;
        } else {
          __pyx_t_28 = __pyx_t_27;
        }
        __pyx_t_26 = __pyx_v_x2m;
        __pyx_t_27 = __pyx_v_x1m;
        if (((__pyx_t_26 > __pyx_t_27) != 0)) {
          __pyx_t_30 = __pyx_t_26;
        } else {
          __pyx_t_30 = __pyx_t_27;
        }
        __pyx_v_over_lap_vol = (__pyx_t_28 - __pyx_t_30);
      }
      __pyx_L39:;

      /* "discretize/_extensions/tree_ext.pyx":6261
 *                 else:
 *                     over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                 if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                     over_lap_vol *= 1.0
 *                 else:
 */
      __Pyx_TraceLine(6261,0,__PYX_ERR(0, 6261, __pyx_L1_error))
      __pyx_t_17 = 1;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
      __pyx_t_15 = ((__pyx_v_y1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )))) != 0);
      if (!__pyx_t_15) {
      } else {
        __pyx_t_12 = __pyx_t_15;
        goto __pyx_L43_bool_binop_done;
      }
      __pyx_t_17 = 1;
      if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
      __pyx_t_15 = ((__pyx_v_y1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )))) != 0);
      __pyx_t_12 = __pyx_t_15;
      __pyx_L43_bool_binop_done:;
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6262
 *                     over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                 if y1m == xF[1] or y1p == origin[1]:
 *                     over_lap_vol *= 1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 */
        __Pyx_TraceLine(6262,0,__PYX_ERR(0, 6262, __pyx_L1_error))
        __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * 1.0);

        /* "discretize/_extensions/tree_ext.pyx":6261
 *                 else:
 *                     over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                 if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                     over_lap_vol *= 1.0
 *                 else:
 */
        goto __pyx_L42;
      }

      /* "discretize/_extensions/tree_ext.pyx":6264
 *                     over_lap_vol *= 1.0
 *                 else:
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)             # <<<<<<<<<<<<<<
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:
 */
      __Pyx_TraceLine(6264,0,__PYX_ERR(0, 6264, __pyx_L1_error))
      /*else*/ {
        __pyx_t_30 = __pyx_v_y2p;
        __pyx_t_28 = __pyx_v_y1p;
        if (((__pyx_t_30 < __pyx_t_28) != 0)) {
          __pyx_t_26 = __pyx_t_30;
        } else {
          __pyx_t_26 = __pyx_t_28;
        }
        __pyx_t_30 = __pyx_v_y2m;
        __pyx_t_28 = __pyx_v_y1m;
        if (((__pyx_t_30 > __pyx_t_28) != 0)) {
          __pyx_t_27 = __pyx_t_30;
        } else {
          __pyx_t_27 = __pyx_t_28;
        }
        __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * (__pyx_t_26 - __pyx_t_27));
      }
      __pyx_L42:;

      /* "discretize/_extensions/tree_ext.pyx":6265
 *                 else:
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                 if self._dim==3:             # <<<<<<<<<<<<<<
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         over_lap_vol *= 1.0
 */
      __Pyx_TraceLine(6265,0,__PYX_ERR(0, 6265, __pyx_L1_error))
      __pyx_t_12 = ((__pyx_v_self->_dim == 3) != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6266
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                         over_lap_vol *= 1.0
 *                     else:
 */
        __Pyx_TraceLine(6266,0,__PYX_ERR(0, 6266, __pyx_L1_error))
        __pyx_t_17 = 2;
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_xF.shape[0];
        __pyx_t_15 = ((__pyx_v_z1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_17 * __pyx_v_xF.strides[0]) )))) != 0);
        if (!__pyx_t_15) {
        } else {
          __pyx_t_12 = __pyx_t_15;
          goto __pyx_L47_bool_binop_done;
        }
        __pyx_t_17 = 2;
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_origin.shape[0];
        __pyx_t_15 = ((__pyx_v_z1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_17 * __pyx_v_origin.strides[0]) )))) != 0);
        __pyx_t_12 = __pyx_t_15;
        __pyx_L47_bool_binop_done:;
        if (__pyx_t_12) {

          /* "discretize/_extensions/tree_ext.pyx":6267
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         over_lap_vol *= 1.0             # <<<<<<<<<<<<<<
 *                     else:
 *                         over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)
 */
          __Pyx_TraceLine(6267,0,__PYX_ERR(0, 6267, __pyx_L1_error))
          __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * 1.0);

          /* "discretize/_extensions/tree_ext.pyx":6266
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                         over_lap_vol *= 1.0
 *                     else:
 */
          goto __pyx_L46;
        }

        /* "discretize/_extensions/tree_ext.pyx":6269
 *                         over_lap_vol *= 1.0
 *                     else:
 *                         over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)             # <<<<<<<<<<<<<<
 * 
 *                 weights[i] = over_lap_vol
 */
        __Pyx_TraceLine(6269,0,__PYX_ERR(0, 6269, __pyx_L1_error))
        /*else*/ {
          __pyx_t_27 = __pyx_v_z2p;
          __pyx_t_26 = __pyx_v_z1p;
          if (((__pyx_t_27 < __pyx_t_26) != 0)) {
            __pyx_t_30 = __pyx_t_27;
          } else {
            __pyx_t_30 = __pyx_t_26;
          }
          __pyx_t_27 = __pyx_v_z2m;
          __pyx_t_26 = __pyx_v_z1m;
          if (((__pyx_t_27 > __pyx_t_26) != 0)) {
            __pyx_t_28 = __pyx_t_27;
          } else {
            __pyx_t_28 = __pyx_t_26;
          }
          __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * (__pyx_t_30 - __pyx_t_28));
        }
        __pyx_L46:;

        /* "discretize/_extensions/tree_ext.pyx":6265
 *                 else:
 *                     over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                 if self._dim==3:             # <<<<<<<<<<<<<<
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         over_lap_vol *= 1.0
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6271
 *                         over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)
 * 
 *                 weights[i] = over_lap_vol             # <<<<<<<<<<<<<<
 *                 if build_mat and weights[i] != 0.0:
 *                     nnz_row += 1
 */
      __Pyx_TraceLine(6271,0,__PYX_ERR(0, 6271, __pyx_L1_error))
      (__pyx_v_weights[__pyx_v_i]) = __pyx_v_over_lap_vol;

      /* "discretize/_extensions/tree_ext.pyx":6272
 * 
 *                 weights[i] = over_lap_vol
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     nnz_row += 1
 *                     row_inds.push_back(in_cell_ind)
 */
      __Pyx_TraceLine(6272,0,__PYX_ERR(0, 6272, __pyx_L1_error))
      __pyx_t_15 = (__pyx_v_build_mat != 0);
      if (__pyx_t_15) {
      } else {
        __pyx_t_12 = __pyx_t_15;
        goto __pyx_L50_bool_binop_done;
      }
      __pyx_t_15 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
      __pyx_t_12 = __pyx_t_15;
      __pyx_L50_bool_binop_done:;
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6273
 *                 weights[i] = over_lap_vol
 *                 if build_mat and weights[i] != 0.0:
 *                     nnz_row += 1             # <<<<<<<<<<<<<<
 *                     row_inds.push_back(in_cell_ind)
 * 
 */
        __Pyx_TraceLine(6273,0,__PYX_ERR(0, 6273, __pyx_L1_error))
        __pyx_v_nnz_row = (__pyx_v_nnz_row + 1);

        /* "discretize/_extensions/tree_ext.pyx":6274
 *                 if build_mat and weights[i] != 0.0:
 *                     nnz_row += 1
 *                     row_inds.push_back(in_cell_ind)             # <<<<<<<<<<<<<<
 * 
 *                 weight_sum += weights[i]
 */
        __Pyx_TraceLine(6274,0,__PYX_ERR(0, 6274, __pyx_L1_error))
        try {
          __pyx_v_row_inds.push_back(__pyx_v_in_cell_ind);
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 6274, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":6272
 * 
 *                 weights[i] = over_lap_vol
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     nnz_row += 1
 *                     row_inds.push_back(in_cell_ind)
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6276
 *                     row_inds.push_back(in_cell_ind)
 * 
 *                 weight_sum += weights[i]             # <<<<<<<<<<<<<<
 *                 i += 1
 *             for i in range(n_overlap):
 */
      __Pyx_TraceLine(6276,0,__PYX_ERR(0, 6276, __pyx_L1_error))
      __pyx_v_weight_sum = (__pyx_v_weight_sum + (__pyx_v_weights[__pyx_v_i]));

      /* "discretize/_extensions/tree_ext.pyx":6277
 * 
 *                 weight_sum += weights[i]
 *                 i += 1             # <<<<<<<<<<<<<<
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum
 */
      __Pyx_TraceLine(6277,0,__PYX_ERR(0, 6277, __pyx_L1_error))
      __pyx_v_i = (__pyx_v_i + 1);

      /* "discretize/_extensions/tree_ext.pyx":6248
 *             weight_sum = 0.0
 *             nnz_row = 0
 *             for in_cell_ind in overlapping_cell_inds:             # <<<<<<<<<<<<<<
 *                 in_cell = meshin.tree.cells[in_cell_ind]
 *                 x2m = in_cell.points[0].location[0]
 */
      __Pyx_TraceLine(6248,0,__PYX_ERR(0, 6248, __pyx_L1_error))
    }

    /* "discretize/_extensions/tree_ext.pyx":6278
 *                 weight_sum += weights[i]
 *                 i += 1
 *             for i in range(n_overlap):             # <<<<<<<<<<<<<<
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:
 */
    __Pyx_TraceLine(6278,0,__PYX_ERR(0, 6278, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_n_overlap;
    __pyx_t_13 = __pyx_t_4;
    for (__pyx_t_31 = 0; __pyx_t_31 < __pyx_t_13; __pyx_t_31+=1) {
      __pyx_v_i = __pyx_t_31;

      /* "discretize/_extensions/tree_ext.pyx":6279
 *                 i += 1
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum             # <<<<<<<<<<<<<<
 *                 if build_mat and weights[i] != 0.0:
 *                     all_weights.push_back(weights[i])
 */
      __Pyx_TraceLine(6279,0,__PYX_ERR(0, 6279, __pyx_L1_error))
      __pyx_t_32 = __pyx_v_i;
      (__pyx_v_weights[__pyx_t_32]) = ((__pyx_v_weights[__pyx_t_32]) / __pyx_v_weight_sum);

      /* "discretize/_extensions/tree_ext.pyx":6280
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     all_weights.push_back(weights[i])
 * 
 */
      __Pyx_TraceLine(6280,0,__PYX_ERR(0, 6280, __pyx_L1_error))
      __pyx_t_15 = (__pyx_v_build_mat != 0);
      if (__pyx_t_15) {
      } else {
        __pyx_t_12 = __pyx_t_15;
        goto __pyx_L55_bool_binop_done;
      }
      __pyx_t_15 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
      __pyx_t_12 = __pyx_t_15;
      __pyx_L55_bool_binop_done:;
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6281
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:
 *                     all_weights.push_back(weights[i])             # <<<<<<<<<<<<<<
 * 
 *             if not build_mat:
 */
        __Pyx_TraceLine(6281,0,__PYX_ERR(0, 6281, __pyx_L1_error))
        try {
          __pyx_v_all_weights.push_back((__pyx_v_weights[__pyx_v_i]));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 6281, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":6280
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     all_weights.push_back(weights[i])
 * 
 */
      }
    }

    /* "discretize/_extensions/tree_ext.pyx":6283
 *                     all_weights.push_back(weights[i])
 * 
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 for i in range(n_overlap):
 *                     outs[cell.index] += vals[overlapping_cell_inds[i]]*weights[i]
 */
    __Pyx_TraceLine(6283,0,__PYX_ERR(0, 6283, __pyx_L1_error))
    __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6284
 * 
 *             if not build_mat:
 *                 for i in range(n_overlap):             # <<<<<<<<<<<<<<
 *                     outs[cell.index] += vals[overlapping_cell_inds[i]]*weights[i]
 *             else:
 */
      __Pyx_TraceLine(6284,0,__PYX_ERR(0, 6284, __pyx_L1_error))
      __pyx_t_4 = __pyx_v_n_overlap;
      __pyx_t_13 = __pyx_t_4;
      for (__pyx_t_31 = 0; __pyx_t_31 < __pyx_t_13; __pyx_t_31+=1) {
        __pyx_v_i = __pyx_t_31;

        /* "discretize/_extensions/tree_ext.pyx":6285
 *             if not build_mat:
 *                 for i in range(n_overlap):
 *                     outs[cell.index] += vals[overlapping_cell_inds[i]]*weights[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 nnz_counter += nnz_row
 */
        __Pyx_TraceLine(6285,0,__PYX_ERR(0, 6285, __pyx_L1_error))
        __pyx_t_17 = (__pyx_v_overlapping_cell_inds[__pyx_v_i]);
        if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_v_vals.shape[0];
        __pyx_t_23 = __pyx_v_cell->index;
        if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_v_outs.shape[0];
        *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_outs.data + __pyx_t_23 * __pyx_v_outs.strides[0]) )) += ((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_vals.data + __pyx_t_17 * __pyx_v_vals.strides[0]) ))) * (__pyx_v_weights[__pyx_v_i]));
      }

      /* "discretize/_extensions/tree_ext.pyx":6283
 *                     all_weights.push_back(weights[i])
 * 
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 for i in range(n_overlap):
 *                     outs[cell.index] += vals[overlapping_cell_inds[i]]*weights[i]
 */
      goto __pyx_L57;
    }

    /* "discretize/_extensions/tree_ext.pyx":6287
 *                     outs[cell.index] += vals[overlapping_cell_inds[i]]*weights[i]
 *             else:
 *                 nnz_counter += nnz_row             # <<<<<<<<<<<<<<
 *                 indptr.push_back(nnz_counter)
 * 
 */
    __Pyx_TraceLine(6287,0,__PYX_ERR(0, 6287, __pyx_L1_error))
    /*else*/ {
      __pyx_v_nnz_counter = (__pyx_v_nnz_counter + __pyx_v_nnz_row);

      /* "discretize/_extensions/tree_ext.pyx":6288
 *             else:
 *                 nnz_counter += nnz_row
 *                 indptr.push_back(nnz_counter)             # <<<<<<<<<<<<<<
 * 
 *             free(weights)
 */
      __Pyx_TraceLine(6288,0,__PYX_ERR(0, 6288, __pyx_L1_error))
      try {
        __pyx_v_indptr.push_back(__pyx_v_nnz_counter);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 6288, __pyx_L1_error)
      }
    }
    __pyx_L57:;

    /* "discretize/_extensions/tree_ext.pyx":6290
 *                 indptr.push_back(nnz_counter)
 * 
 *             free(weights)             # <<<<<<<<<<<<<<
 *             overlapping_cell_inds.clear()
 * 
 */
    __Pyx_TraceLine(6290,0,__PYX_ERR(0, 6290, __pyx_L1_error))
    free(__pyx_v_weights);

    /* "discretize/_extensions/tree_ext.pyx":6291
 * 
 *             free(weights)
 *             overlapping_cell_inds.clear()             # <<<<<<<<<<<<<<
 * 
 *         if not build_mat:
 */
    __Pyx_TraceLine(6291,0,__PYX_ERR(0, 6291, __pyx_L1_error))
    __pyx_v_overlapping_cell_inds.clear();

    /* "discretize/_extensions/tree_ext.pyx":6233
 *             return P
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])
 */
    __Pyx_TraceLine(6233,0,__PYX_ERR(0, 6233, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6293
 *             overlapping_cell_inds.clear()
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, meshin.n_cells))
 */
  __Pyx_TraceLine(6293,0,__PYX_ERR(0, 6293, __pyx_L1_error))
  __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6294
 * 
 *         if not build_mat:
 *             return output             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, meshin.n_cells))
 * 
 */
    __Pyx_TraceLine(6294,0,__PYX_ERR(0, 6294, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_output);
    __pyx_r = __pyx_v_output;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6293
 *             overlapping_cell_inds.clear()
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, meshin.n_cells))
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6295
 *         if not build_mat:
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, meshin.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(6295,0,__PYX_ERR(0, 6295, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_sp); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __pyx_convert_vector_to_py_double(__pyx_v_all_weights); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __pyx_convert_vector_to_py_int_t(__pyx_v_row_inds); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __pyx_convert_vector_to_py_int_t(__pyx_v_indptr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_6);
  __pyx_t_8 = 0;
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_meshin), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_shape, __pyx_t_5) < 0) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6121
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_from_tree(self, _TreeMesh meshin, values=None, output=None):             # <<<<<<<<<<<<<<
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __Pyx_XDECREF(__pyx_t_25);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_origin, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_xF, 1);
  __Pyx_XDECREF(__pyx_v_P);
  __Pyx_XDECREF(__pyx_v_output);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6299
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_to_tens(self, out_tens_mesh, values=None, output=None):             # <<<<<<<<<<<<<<
 *         cdef vector[int_t] *overlapping_cells
 *         cdef double *weights
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_99_vol_avg_to_tens(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_98_vol_avg_to_tens[] = "_TreeMesh._vol_avg_to_tens(self, out_tens_mesh, values=None, output=None)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_99_vol_avg_to_tens(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_out_tens_mesh = 0;
  PyObject *__pyx_v_values = 0;
  PyObject *__pyx_v_output = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_vol_avg_to_tens (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_out_tens_mesh,&__pyx_n_s_values,&__pyx_n_s_output,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    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_out_tens_mesh)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_values);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_output);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_vol_avg_to_tens") < 0)) __PYX_ERR(0, 6299, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_out_tens_mesh = values[0];
    __pyx_v_values = values[1];
    __pyx_v_output = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_vol_avg_to_tens", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 6299, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_to_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_98_vol_avg_to_tens(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_out_tens_mesh, __pyx_v_values, __pyx_v_output);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_98_vol_avg_to_tens(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_out_tens_mesh, PyObject *__pyx_v_values, PyObject *__pyx_v_output) {
  double *__pyx_v_weights;
  double __pyx_v_over_lap_vol;
  double __pyx_v_x1m;
  double __pyx_v_x1p;
  double __pyx_v_y1m;
  double __pyx_v_y1p;
  double __pyx_v_z1m;
  double __pyx_v_z1p;
  double __pyx_v_x2m;
  double __pyx_v_x2p;
  double __pyx_v_y2m;
  double __pyx_v_y2p;
  double __pyx_v_z2m;
  double __pyx_v_z2p;
  __Pyx_memviewslice __pyx_v_origin = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_xF = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_same_base;
  PyObject *__pyx_v_in_cell_inds = NULL;
  Cell *__pyx_v_in_cell;
  __Pyx_memviewslice __pyx_v_vals = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_outs = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<int_t>  __pyx_v_row_inds;
  std::vector<int_t>  __pyx_v_indptr;
  std::vector<double>  __pyx_v_all_weights;
  int_t __pyx_v_nnz_row;
  int_t __pyx_v_nnz_counter;
  __Pyx_memviewslice __pyx_v_nodes_x = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_nodes_y = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_nodes_z = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_nx;
  int_t __pyx_v_ny;
  int_t __pyx_v_nz;
  int_t __pyx_v_build_mat;
  int_t __pyx_v_ix;
  int_t __pyx_v_iy;
  int_t __pyx_v_iz;
  int_t __pyx_v_in_cell_ind;
  int_t __pyx_v_i;
  int_t __pyx_v_n_overlap;
  double __pyx_v_weight_sum;
  std::vector<int_t>  __pyx_v_overlapping_cell_inds;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int_t __pyx_t_13;
  int __pyx_t_14;
  __Pyx_memviewslice __pyx_t_15 = { 0, 0, { 0 }, { 0 }, { 0 } };
  Py_ssize_t __pyx_t_16;
  __Pyx_memviewslice __pyx_t_17 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_18 = { 0, 0, { 0 }, { 0 }, { 0 } };
  size_t __pyx_t_19;
  int_t __pyx_t_20;
  double __pyx_t_21;
  double __pyx_t_22;
  double __pyx_t_23;
  int_t __pyx_t_24;
  int_t __pyx_t_25;
  int_t __pyx_t_26;
  int_t __pyx_t_27;
  int_t __pyx_t_28;
  int_t __pyx_t_29;
  std::vector<int_t> ::iterator __pyx_t_30;
  int_t __pyx_t_31;
  double __pyx_t_32;
  int_t __pyx_t_33;
  int_t __pyx_t_34;
  int_t __pyx_t_35;
  Py_ssize_t __pyx_t_36;
  Py_ssize_t __pyx_t_37;
  Py_ssize_t __pyx_t_38;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_vol_avg_to_tens", 0);
  __Pyx_TraceCall("_vol_avg_to_tens", __pyx_f[0], 6299, 0, __PYX_ERR(0, 6299, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_output);

  /* "discretize/_extensions/tree_ext.pyx":6310
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)
 */
  __Pyx_TraceLine(6310,0,__PYX_ERR(0, 6310, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "discretize/_extensions/tree_ext.pyx":6312
 *         try:
 *             same_base = (
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)             # <<<<<<<<<<<<<<
 *                 and np.allclose(self.nodes_y, out_tens_mesh.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, out_tens_mesh.nodes_z))
 */
      __Pyx_TraceLine(6312,0,__PYX_ERR(0, 6312, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6312, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_allclose); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6312, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6312, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6312, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6312, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6312, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6312, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_6 = 0;
        __pyx_t_8 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6312, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6312, __pyx_L3_error)
      if (__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6312, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6313
 *             same_base = (
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)
 *                 and np.allclose(self.nodes_y, out_tens_mesh.nodes_y)             # <<<<<<<<<<<<<<
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, out_tens_mesh.nodes_z))
 *             )
 */
      __Pyx_TraceLine(6313,0,__PYX_ERR(0, 6313, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6313, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_allclose); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6313, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6313, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6313, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_7, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6313, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_7, __pyx_t_8};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6313, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6313, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_7 = 0;
        __pyx_t_8 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6313, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6313, __pyx_L3_error)
      if (__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_5); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6313, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6314
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)
 *                 and np.allclose(self.nodes_y, out_tens_mesh.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, out_tens_mesh.nodes_z))             # <<<<<<<<<<<<<<
 *             )
 *         except ValueError:
 */
      __Pyx_TraceLine(6314,0,__PYX_ERR(0, 6314, __pyx_L3_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_11 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6314, __pyx_L3_error)
      if (!__pyx_t_12) {
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_11); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6314, __pyx_L3_error)
        __pyx_t_4 = __pyx_t_13;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_allclose); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6314, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
        __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6314, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
        __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6314, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6314, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_10, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_5 = 0;
        __pyx_t_8 = 0;
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6314, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_13 = __Pyx_PyInt_As_int_t(__pyx_t_11); if (unlikely((__pyx_t_13 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6314, __pyx_L3_error)
      __pyx_t_4 = __pyx_t_13;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_v_same_base = __pyx_t_4;

      /* "discretize/_extensions/tree_ext.pyx":6310
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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;

    /* "discretize/_extensions/tree_ext.pyx":6316
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, out_tens_mesh.nodes_z))
 *             )
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             same_base = False
 * 
 */
    __Pyx_TraceLine(6316,0,__PYX_ERR(0, 6316, __pyx_L5_except_error))
    __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_10) {
      __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_to_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_9, &__pyx_t_6) < 0) __PYX_ERR(0, 6316, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_6);

      /* "discretize/_extensions/tree_ext.pyx":6317
 *             )
 *         except ValueError:
 *             same_base = False             # <<<<<<<<<<<<<<
 * 
 *         if same_base:
 */
      __Pyx_TraceLine(6317,0,__PYX_ERR(0, 6317, __pyx_L5_except_error))
      __pyx_v_same_base = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "discretize/_extensions/tree_ext.pyx":6310
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, out_tens_mesh.nodes_x)
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "discretize/_extensions/tree_ext.pyx":6319
 *             same_base = False
 * 
 *         if same_base:             # <<<<<<<<<<<<<<
 *             in_cell_inds = self._get_containing_cell_indexes(out_tens_mesh.cell_centers)
 *             # Every cell input cell is gauranteed to be a lower level than the output tenser mesh
 */
  __Pyx_TraceLine(6319,0,__PYX_ERR(0, 6319, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_same_base != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6320
 * 
 *         if same_base:
 *             in_cell_inds = self._get_containing_cell_indexes(out_tens_mesh.cell_centers)             # <<<<<<<<<<<<<<
 *             # Every cell input cell is gauranteed to be a lower level than the output tenser mesh
 *             # therefore all weights a 1.0
 */
    __Pyx_TraceLine(6320,0,__PYX_ERR(0, 6320, __pyx_L1_error))
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_containing_cell_indexes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_cell_centers); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_11);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_in_cell_inds = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6323
 *             # Every cell input cell is gauranteed to be a lower level than the output tenser mesh
 *             # therefore all weights a 1.0
 *             if values is not None:             # <<<<<<<<<<<<<<
 *                 if output is None:
 *                     output = np.empty(out_tens_mesh.n_cells)
 */
    __Pyx_TraceLine(6323,0,__PYX_ERR(0, 6323, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_values != Py_None);
    __pyx_t_14 = (__pyx_t_12 != 0);
    if (__pyx_t_14) {

      /* "discretize/_extensions/tree_ext.pyx":6324
 *             # therefore all weights a 1.0
 *             if values is not None:
 *                 if output is None:             # <<<<<<<<<<<<<<
 *                     output = np.empty(out_tens_mesh.n_cells)
 *                 output[:] = values[in_cell_inds]
 */
      __Pyx_TraceLine(6324,0,__PYX_ERR(0, 6324, __pyx_L1_error))
      __pyx_t_14 = (__pyx_v_output == Py_None);
      __pyx_t_12 = (__pyx_t_14 != 0);
      if (__pyx_t_12) {

        /* "discretize/_extensions/tree_ext.pyx":6325
 *             if values is not None:
 *                 if output is None:
 *                     output = np.empty(out_tens_mesh.n_cells)             # <<<<<<<<<<<<<<
 *                 output[:] = values[in_cell_inds]
 *                 return output
 */
        __Pyx_TraceLine(6325,0,__PYX_ERR(0, 6325, __pyx_L1_error))
        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6325, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6325, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6325, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
          }
        }
        __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6325, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "discretize/_extensions/tree_ext.pyx":6324
 *             # therefore all weights a 1.0
 *             if values is not None:
 *                 if output is None:             # <<<<<<<<<<<<<<
 *                     output = np.empty(out_tens_mesh.n_cells)
 *                 output[:] = values[in_cell_inds]
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6326
 *                 if output is None:
 *                     output = np.empty(out_tens_mesh.n_cells)
 *                 output[:] = values[in_cell_inds]             # <<<<<<<<<<<<<<
 *                 return output
 *             return sp.csr_matrix(
 */
      __Pyx_TraceLine(6326,0,__PYX_ERR(0, 6326, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_values, __pyx_v_in_cell_inds); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__Pyx_PyObject_SetSlice(__pyx_v_output, __pyx_t_6, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 6326, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6327
 *                     output = np.empty(out_tens_mesh.n_cells)
 *                 output[:] = values[in_cell_inds]
 *                 return output             # <<<<<<<<<<<<<<
 *             return sp.csr_matrix(
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),
 */
      __Pyx_TraceLine(6327,0,__PYX_ERR(0, 6327, __pyx_L1_error))
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_output);
      __pyx_r = __pyx_v_output;
      goto __pyx_L0;

      /* "discretize/_extensions/tree_ext.pyx":6323
 *             # Every cell input cell is gauranteed to be a lower level than the output tenser mesh
 *             # therefore all weights a 1.0
 *             if values is not None:             # <<<<<<<<<<<<<<
 *                 if output is None:
 *                     output = np.empty(out_tens_mesh.n_cells)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6328
 *                 output[:] = values[in_cell_inds]
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),
 *                 shape=(out_tens_mesh.n_cells, self.n_cells)
 */
    __Pyx_TraceLine(6328,0,__PYX_ERR(0, 6328, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6329
 *                 return output
 *             return sp.csr_matrix(
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),             # <<<<<<<<<<<<<<
 *                 shape=(out_tens_mesh.n_cells, self.n_cells)
 *             )
 */
    __Pyx_TraceLine(6329,0,__PYX_ERR(0, 6329, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_ones); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_arange); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_8 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8);
    __Pyx_INCREF(__pyx_v_in_cell_inds);
    __Pyx_GIVEREF(__pyx_v_in_cell_inds);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_in_cell_inds);
    __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
    __pyx_t_6 = 0;
    __pyx_t_5 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6328
 *                 output[:] = values[in_cell_inds]
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),
 *                 shape=(out_tens_mesh.n_cells, self.n_cells)
 */
    __Pyx_TraceLine(6328,0,__PYX_ERR(0, 6328, __pyx_L1_error))
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6330
 *             return sp.csr_matrix(
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),
 *                 shape=(out_tens_mesh.n_cells, self.n_cells)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __Pyx_TraceLine(6330,0,__PYX_ERR(0, 6330, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_9);
    __pyx_t_6 = 0;
    __pyx_t_9 = 0;
    if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 6330, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6328
 *                 output[:] = values[in_cell_inds]
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (np.ones(out_tens_mesh.n_cells), (np.arange(out_tens_mesh.n_cells), in_cell_inds)),
 *                 shape=(out_tens_mesh.n_cells, self.n_cells)
 */
    __Pyx_TraceLine(6328,0,__PYX_ERR(0, 6328, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6319
 *             same_base = False
 * 
 *         if same_base:             # <<<<<<<<<<<<<<
 *             in_cell_inds = self._get_containing_cell_indexes(out_tens_mesh.cell_centers)
 *             # Every cell input cell is gauranteed to be a lower level than the output tenser mesh
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6333
 *             )
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             origin = np.r_[self.origin, 0.0]
 *             xF = np.array([self._xs[-1], self._ys[-1], 0.0])
 */
  __Pyx_TraceLine(6333,0,__PYX_ERR(0, 6333, __pyx_L1_error))
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6333, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyInt_EqObjC(__pyx_t_7, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6333, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 6333, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6334
 * 
 *         if self.dim == 2:
 *             origin = np.r_[self.origin, 0.0]             # <<<<<<<<<<<<<<
 *             xF = np.array([self._xs[-1], self._ys[-1], 0.0])
 *         else:
 */
    __Pyx_TraceLine(6334,0,__PYX_ERR(0, 6334, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_r); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_origin); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8);
    __Pyx_INCREF(__pyx_float_0_0);
    __Pyx_GIVEREF(__pyx_float_0_0);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_float_0_0);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6334, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_origin = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6335
 *         if self.dim == 2:
 *             origin = np.r_[self.origin, 0.0]
 *             xF = np.array([self._xs[-1], self._ys[-1], 0.0])             # <<<<<<<<<<<<<<
 *         else:
 *             origin = self._origin
 */
    __Pyx_TraceLine(6335,0,__PYX_ERR(0, 6335, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6335, __pyx_L1_error)}
    __pyx_t_16 = -1L;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_self->_xs.shape[0];
    __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_16 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6335, __pyx_L1_error)}
    __pyx_t_16 = -1L;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_self->_ys.shape[0];
    __pyx_t_11 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_16 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_9 = PyList_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_11);
    PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_11);
    __Pyx_INCREF(__pyx_float_0_0);
    __Pyx_GIVEREF(__pyx_float_0_0);
    PyList_SET_ITEM(__pyx_t_9, 2, __pyx_float_0_0);
    __pyx_t_5 = 0;
    __pyx_t_11 = 0;
    __pyx_t_11 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_8 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_11, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6335, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_xF = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6333
 *             )
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             origin = np.r_[self.origin, 0.0]
 *             xF = np.array([self._xs[-1], self._ys[-1], 0.0])
 */
    goto __pyx_L18;
  }

  /* "discretize/_extensions/tree_ext.pyx":6337
 *             xF = np.array([self._xs[-1], self._ys[-1], 0.0])
 *         else:
 *             origin = self._origin             # <<<<<<<<<<<<<<
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])
 *         cdef c_Cell * in_cell
 */
  __Pyx_TraceLine(6337,0,__PYX_ERR(0, 6337, __pyx_L1_error))
  /*else*/ {
    if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6337, __pyx_L1_error)}
    __pyx_t_15 = __pyx_v_self->_origin;
    __PYX_INC_MEMVIEW(&__pyx_t_15, 1);
    __pyx_v_origin = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6338
 *         else:
 *             origin = self._origin
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])             # <<<<<<<<<<<<<<
 *         cdef c_Cell * in_cell
 * 
 */
    __Pyx_TraceLine(6338,0,__PYX_ERR(0, 6338, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6338, __pyx_L1_error)}
    __pyx_t_16 = -1L;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_self->_xs.shape[0];
    __pyx_t_7 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_16 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6338, __pyx_L1_error)}
    __pyx_t_16 = -1L;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_self->_ys.shape[0];
    __pyx_t_11 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_16 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6338, __pyx_L1_error)}
    __pyx_t_16 = -1L;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_self->_zs.shape[0];
    __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_16 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyList_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_11);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_6, 2, __pyx_t_5);
    __pyx_t_7 = 0;
    __pyx_t_11 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6338, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_xF = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;
  }
  __pyx_L18:;

  /* "discretize/_extensions/tree_ext.pyx":6341
 *         cdef c_Cell * in_cell
 * 
 *         cdef np.float64_t[:] vals = np.array([])             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[::1, :, :] outs = np.array([[[]]])
 * 
 */
  __Pyx_TraceLine(6341,0,__PYX_ERR(0, 6341, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 6341, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_vals = __pyx_t_17;
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6342
 * 
 *         cdef np.float64_t[:] vals = np.array([])
 *         cdef np.float64_t[::1, :, :] outs = np.array([[[]]])             # <<<<<<<<<<<<<<
 * 
 *         cdef vector[int_t] row_inds
 */
  __Pyx_TraceLine(6342,0,__PYX_ERR(0, 6342, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 6342, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_outs = __pyx_t_18;
  __pyx_t_18.memview = NULL;
  __pyx_t_18.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6347
 *         cdef vector[int_t] indptr
 *         cdef vector[double] all_weights
 *         cdef int_t nnz_row = 0             # <<<<<<<<<<<<<<
 *         cdef int_t nnz_counter = 0
 * 
 */
  __Pyx_TraceLine(6347,0,__PYX_ERR(0, 6347, __pyx_L1_error))
  __pyx_v_nnz_row = 0;

  /* "discretize/_extensions/tree_ext.pyx":6348
 *         cdef vector[double] all_weights
 *         cdef int_t nnz_row = 0
 *         cdef int_t nnz_counter = 0             # <<<<<<<<<<<<<<
 * 
 *         cdef double[:] nodes_x = out_tens_mesh.nodes_x
 */
  __Pyx_TraceLine(6348,0,__PYX_ERR(0, 6348, __pyx_L1_error))
  __pyx_v_nnz_counter = 0;

  /* "discretize/_extensions/tree_ext.pyx":6350
 *         cdef int_t nnz_counter = 0
 * 
 *         cdef double[:] nodes_x = out_tens_mesh.nodes_x             # <<<<<<<<<<<<<<
 *         cdef double[:] nodes_y = out_tens_mesh.nodes_y
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])
 */
  __Pyx_TraceLine(6350,0,__PYX_ERR(0, 6350, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_x = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6351
 * 
 *         cdef double[:] nodes_x = out_tens_mesh.nodes_x
 *         cdef double[:] nodes_y = out_tens_mesh.nodes_y             # <<<<<<<<<<<<<<
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim==3:
 */
  __Pyx_TraceLine(6351,0,__PYX_ERR(0, 6351, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6351, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_y = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6352
 *         cdef double[:] nodes_x = out_tens_mesh.nodes_x
 *         cdef double[:] nodes_y = out_tens_mesh.nodes_y
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])             # <<<<<<<<<<<<<<
 *         if self._dim==3:
 *             nodes_z = out_tens_mesh.nodes_z
 */
  __Pyx_TraceLine(6352,0,__PYX_ERR(0, 6352, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyList_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_INCREF(__pyx_float_0_0);
  __Pyx_GIVEREF(__pyx_float_0_0);
  PyList_SET_ITEM(__pyx_t_9, 0, __pyx_float_0_0);
  __Pyx_INCREF(__pyx_float_0_0);
  __Pyx_GIVEREF(__pyx_float_0_0);
  PyList_SET_ITEM(__pyx_t_9, 1, __pyx_float_0_0);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6352, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6352, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_z = __pyx_t_15;
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6353
 *         cdef double[:] nodes_y = out_tens_mesh.nodes_y
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim==3:             # <<<<<<<<<<<<<<
 *             nodes_z = out_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 */
  __Pyx_TraceLine(6353,0,__PYX_ERR(0, 6353, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6354
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim==3:
 *             nodes_z = out_tens_mesh.nodes_z             # <<<<<<<<<<<<<<
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1
 */
    __Pyx_TraceLine(6354,0,__PYX_ERR(0, 6354, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6354, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 6354, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_z, 1);
    __pyx_v_nodes_z = __pyx_t_15;
    __pyx_t_15.memview = NULL;
    __pyx_t_15.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6353
 *         cdef double[:] nodes_y = out_tens_mesh.nodes_y
 *         cdef double[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim==3:             # <<<<<<<<<<<<<<
 *             nodes_z = out_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6355
 *         if self._dim==3:
 *             nodes_z = out_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1             # <<<<<<<<<<<<<<
 *         cdef int_t ny = len(nodes_y)-1
 *         cdef int_t nz = len(nodes_z)-1
 */
  __Pyx_TraceLine(6355,0,__PYX_ERR(0, 6355, __pyx_L1_error))
  __pyx_t_19 = __Pyx_MemoryView_Len(__pyx_v_nodes_x); 
  __pyx_v_nx = (__pyx_t_19 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6356
 *             nodes_z = out_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1             # <<<<<<<<<<<<<<
 *         cdef int_t nz = len(nodes_z)-1
 * 
 */
  __Pyx_TraceLine(6356,0,__PYX_ERR(0, 6356, __pyx_L1_error))
  __pyx_t_19 = __Pyx_MemoryView_Len(__pyx_v_nodes_y); 
  __pyx_v_ny = (__pyx_t_19 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6357
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1
 *         cdef int_t nz = len(nodes_z)-1             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t build_mat = 1
 */
  __Pyx_TraceLine(6357,0,__PYX_ERR(0, 6357, __pyx_L1_error))
  __pyx_t_19 = __Pyx_MemoryView_Len(__pyx_v_nodes_z); 
  __pyx_v_nz = (__pyx_t_19 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6359
 *         cdef int_t nz = len(nodes_z)-1
 * 
 *         cdef int_t build_mat = 1             # <<<<<<<<<<<<<<
 *         if values is not None:
 *             vals = values
 */
  __Pyx_TraceLine(6359,0,__PYX_ERR(0, 6359, __pyx_L1_error))
  __pyx_v_build_mat = 1;

  /* "discretize/_extensions/tree_ext.pyx":6360
 * 
 *         cdef int_t build_mat = 1
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values
 *             if output is None:
 */
  __Pyx_TraceLine(6360,0,__PYX_ERR(0, 6360, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_values != Py_None);
  __pyx_t_14 = (__pyx_t_12 != 0);
  if (__pyx_t_14) {

    /* "discretize/_extensions/tree_ext.pyx":6361
 *         cdef int_t build_mat = 1
 *         if values is not None:
 *             vals = values             # <<<<<<<<<<<<<<
 *             if output is None:
 *                 output = np.empty((nx, ny, nz), order='F')
 */
    __Pyx_TraceLine(6361,0,__PYX_ERR(0, 6361, __pyx_L1_error))
    __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_values, PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 6361, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
    __pyx_v_vals = __pyx_t_17;
    __pyx_t_17.memview = NULL;
    __pyx_t_17.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6362
 *         if values is not None:
 *             vals = values
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty((nx, ny, nz), order='F')
 *             else:
 */
    __Pyx_TraceLine(6362,0,__PYX_ERR(0, 6362, __pyx_L1_error))
    __pyx_t_14 = (__pyx_v_output == Py_None);
    __pyx_t_12 = (__pyx_t_14 != 0);
    if (__pyx_t_12) {

      /* "discretize/_extensions/tree_ext.pyx":6363
 *             vals = values
 *             if output is None:
 *                 output = np.empty((nx, ny, nz), order='F')             # <<<<<<<<<<<<<<
 *             else:
 *                 output = output.reshape((nx, ny, nz), order='F')
 */
      __Pyx_TraceLine(6363,0,__PYX_ERR(0, 6363, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_nx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyInt_From_int_t(__pyx_v_ny); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_5 = __Pyx_PyInt_From_int_t(__pyx_v_nz); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_5);
      __pyx_t_8 = 0;
      __pyx_t_9 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 6363, __pyx_L1_error)
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6362
 *         if values is not None:
 *             vals = values
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty((nx, ny, nz), order='F')
 *             else:
 */
      goto __pyx_L21;
    }

    /* "discretize/_extensions/tree_ext.pyx":6365
 *                 output = np.empty((nx, ny, nz), order='F')
 *             else:
 *                 output = output.reshape((nx, ny, nz), order='F')             # <<<<<<<<<<<<<<
 *             output[:] = 0
 *             outs = output
 */
    __Pyx_TraceLine(6365,0,__PYX_ERR(0, 6365, __pyx_L1_error))
    /*else*/ {
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_reshape); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_11 = __Pyx_PyInt_From_int_t(__pyx_v_nx); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_5 = __Pyx_PyInt_From_int_t(__pyx_v_ny); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_int_t(__pyx_v_nz); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6);
      __pyx_t_11 = 0;
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 6365, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L21:;

    /* "discretize/_extensions/tree_ext.pyx":6366
 *             else:
 *                 output = output.reshape((nx, ny, nz), order='F')
 *             output[:] = 0             # <<<<<<<<<<<<<<
 *             outs = output
 * 
 */
    __Pyx_TraceLine(6366,0,__PYX_ERR(0, 6366, __pyx_L1_error))
    if (__Pyx_PyObject_SetSlice(__pyx_v_output, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 6366, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":6367
 *                 output = output.reshape((nx, ny, nz), order='F')
 *             output[:] = 0
 *             outs = output             # <<<<<<<<<<<<<<
 * 
 *             build_mat = 0
 */
    __Pyx_TraceLine(6367,0,__PYX_ERR(0, 6367, __pyx_L1_error))
    __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(__pyx_v_output, PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 6367, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
    __pyx_v_outs = __pyx_t_18;
    __pyx_t_18.memview = NULL;
    __pyx_t_18.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6369
 *             outs = output
 * 
 *             build_mat = 0             # <<<<<<<<<<<<<<
 *         if build_mat:
 *             indptr.push_back(0)
 */
    __Pyx_TraceLine(6369,0,__PYX_ERR(0, 6369, __pyx_L1_error))
    __pyx_v_build_mat = 0;

    /* "discretize/_extensions/tree_ext.pyx":6360
 * 
 *         cdef int_t build_mat = 1
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values
 *             if output is None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6370
 * 
 *             build_mat = 0
 *         if build_mat:             # <<<<<<<<<<<<<<
 *             indptr.push_back(0)
 * 
 */
  __Pyx_TraceLine(6370,0,__PYX_ERR(0, 6370, __pyx_L1_error))
  __pyx_t_12 = (__pyx_v_build_mat != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6371
 *             build_mat = 0
 *         if build_mat:
 *             indptr.push_back(0)             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t ix, iy, iz, in_cell_ind, i
 */
    __Pyx_TraceLine(6371,0,__PYX_ERR(0, 6371, __pyx_L1_error))
    try {
      __pyx_v_indptr.push_back(0);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(0, 6371, __pyx_L1_error)
    }

    /* "discretize/_extensions/tree_ext.pyx":6370
 * 
 *             build_mat = 0
 *         if build_mat:             # <<<<<<<<<<<<<<
 *             indptr.push_back(0)
 * 
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6378
 * 
 *         #for cell in self.tree.cells:
 *         for iz in range(nz):             # <<<<<<<<<<<<<<
 *             z1m = min(nodes_z[iz], xF[2])
 *             z1p = max(nodes_z[iz+1], origin[2])
 */
  __Pyx_TraceLine(6378,0,__PYX_ERR(0, 6378, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_nz;
  __pyx_t_13 = __pyx_t_4;
  for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_13; __pyx_t_20+=1) {
    __pyx_v_iz = __pyx_t_20;

    /* "discretize/_extensions/tree_ext.pyx":6379
 *         #for cell in self.tree.cells:
 *         for iz in range(nz):
 *             z1m = min(nodes_z[iz], xF[2])             # <<<<<<<<<<<<<<
 *             z1p = max(nodes_z[iz+1], origin[2])
 *             for iy in range(ny):
 */
    __Pyx_TraceLine(6379,0,__PYX_ERR(0, 6379, __pyx_L1_error))
    __pyx_t_16 = 2;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
    __pyx_t_21 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )));
    __pyx_t_16 = __pyx_v_iz;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_z.shape[0];
    __pyx_t_22 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_z.data + __pyx_t_16 * __pyx_v_nodes_z.strides[0]) )));
    if (((__pyx_t_21 < __pyx_t_22) != 0)) {
      __pyx_t_23 = __pyx_t_21;
    } else {
      __pyx_t_23 = __pyx_t_22;
    }
    __pyx_v_z1m = __pyx_t_23;

    /* "discretize/_extensions/tree_ext.pyx":6380
 *         for iz in range(nz):
 *             z1m = min(nodes_z[iz], xF[2])
 *             z1p = max(nodes_z[iz+1], origin[2])             # <<<<<<<<<<<<<<
 *             for iy in range(ny):
 *                 y1m = min(nodes_y[iy], xF[1])
 */
    __Pyx_TraceLine(6380,0,__PYX_ERR(0, 6380, __pyx_L1_error))
    __pyx_t_16 = 2;
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
    __pyx_t_23 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )));
    __pyx_t_16 = (__pyx_v_iz + 1);
    if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_z.shape[0];
    __pyx_t_21 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_z.data + __pyx_t_16 * __pyx_v_nodes_z.strides[0]) )));
    if (((__pyx_t_23 > __pyx_t_21) != 0)) {
      __pyx_t_22 = __pyx_t_23;
    } else {
      __pyx_t_22 = __pyx_t_21;
    }
    __pyx_v_z1p = __pyx_t_22;

    /* "discretize/_extensions/tree_ext.pyx":6381
 *             z1m = min(nodes_z[iz], xF[2])
 *             z1p = max(nodes_z[iz+1], origin[2])
 *             for iy in range(ny):             # <<<<<<<<<<<<<<
 *                 y1m = min(nodes_y[iy], xF[1])
 *                 y1p = max(nodes_y[iy+1], origin[1])
 */
    __Pyx_TraceLine(6381,0,__PYX_ERR(0, 6381, __pyx_L1_error))
    __pyx_t_24 = __pyx_v_ny;
    __pyx_t_25 = __pyx_t_24;
    for (__pyx_t_26 = 0; __pyx_t_26 < __pyx_t_25; __pyx_t_26+=1) {
      __pyx_v_iy = __pyx_t_26;

      /* "discretize/_extensions/tree_ext.pyx":6382
 *             z1p = max(nodes_z[iz+1], origin[2])
 *             for iy in range(ny):
 *                 y1m = min(nodes_y[iy], xF[1])             # <<<<<<<<<<<<<<
 *                 y1p = max(nodes_y[iy+1], origin[1])
 *                 for ix in range(nx):
 */
      __Pyx_TraceLine(6382,0,__PYX_ERR(0, 6382, __pyx_L1_error))
      __pyx_t_16 = 1;
      if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
      __pyx_t_22 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )));
      __pyx_t_16 = __pyx_v_iy;
      if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_y.shape[0];
      __pyx_t_23 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_16 * __pyx_v_nodes_y.strides[0]) )));
      if (((__pyx_t_22 < __pyx_t_23) != 0)) {
        __pyx_t_21 = __pyx_t_22;
      } else {
        __pyx_t_21 = __pyx_t_23;
      }
      __pyx_v_y1m = __pyx_t_21;

      /* "discretize/_extensions/tree_ext.pyx":6383
 *             for iy in range(ny):
 *                 y1m = min(nodes_y[iy], xF[1])
 *                 y1p = max(nodes_y[iy+1], origin[1])             # <<<<<<<<<<<<<<
 *                 for ix in range(nx):
 *                     x1m = min(nodes_x[ix], xF[0])
 */
      __Pyx_TraceLine(6383,0,__PYX_ERR(0, 6383, __pyx_L1_error))
      __pyx_t_16 = 1;
      if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
      __pyx_t_21 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )));
      __pyx_t_16 = (__pyx_v_iy + 1);
      if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_y.shape[0];
      __pyx_t_22 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_16 * __pyx_v_nodes_y.strides[0]) )));
      if (((__pyx_t_21 > __pyx_t_22) != 0)) {
        __pyx_t_23 = __pyx_t_21;
      } else {
        __pyx_t_23 = __pyx_t_22;
      }
      __pyx_v_y1p = __pyx_t_23;

      /* "discretize/_extensions/tree_ext.pyx":6384
 *                 y1m = min(nodes_y[iy], xF[1])
 *                 y1p = max(nodes_y[iy+1], origin[1])
 *                 for ix in range(nx):             # <<<<<<<<<<<<<<
 *                     x1m = min(nodes_x[ix], xF[0])
 *                     x1p = max(nodes_x[ix+1], origin[0])
 */
      __Pyx_TraceLine(6384,0,__PYX_ERR(0, 6384, __pyx_L1_error))
      __pyx_t_27 = __pyx_v_nx;
      __pyx_t_28 = __pyx_t_27;
      for (__pyx_t_29 = 0; __pyx_t_29 < __pyx_t_28; __pyx_t_29+=1) {
        __pyx_v_ix = __pyx_t_29;

        /* "discretize/_extensions/tree_ext.pyx":6385
 *                 y1p = max(nodes_y[iy+1], origin[1])
 *                 for ix in range(nx):
 *                     x1m = min(nodes_x[ix], xF[0])             # <<<<<<<<<<<<<<
 *                     x1p = max(nodes_x[ix+1], origin[0])
 *                     overlapping_cell_inds = self.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 */
        __Pyx_TraceLine(6385,0,__PYX_ERR(0, 6385, __pyx_L1_error))
        __pyx_t_16 = 0;
        if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
        __pyx_t_23 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )));
        __pyx_t_16 = __pyx_v_ix;
        if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_x.shape[0];
        __pyx_t_21 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_16 * __pyx_v_nodes_x.strides[0]) )));
        if (((__pyx_t_23 < __pyx_t_21) != 0)) {
          __pyx_t_22 = __pyx_t_23;
        } else {
          __pyx_t_22 = __pyx_t_21;
        }
        __pyx_v_x1m = __pyx_t_22;

        /* "discretize/_extensions/tree_ext.pyx":6386
 *                 for ix in range(nx):
 *                     x1m = min(nodes_x[ix], xF[0])
 *                     x1p = max(nodes_x[ix+1], origin[0])             # <<<<<<<<<<<<<<
 *                     overlapping_cell_inds = self.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *                     n_overlap = overlapping_cell_inds.size()
 */
        __Pyx_TraceLine(6386,0,__PYX_ERR(0, 6386, __pyx_L1_error))
        __pyx_t_16 = 0;
        if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
        __pyx_t_22 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )));
        __pyx_t_16 = (__pyx_v_ix + 1);
        if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_nodes_x.shape[0];
        __pyx_t_23 = (*((double *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_16 * __pyx_v_nodes_x.strides[0]) )));
        if (((__pyx_t_22 > __pyx_t_23) != 0)) {
          __pyx_t_21 = __pyx_t_22;
        } else {
          __pyx_t_21 = __pyx_t_23;
        }
        __pyx_v_x1p = __pyx_t_21;

        /* "discretize/_extensions/tree_ext.pyx":6387
 *                     x1m = min(nodes_x[ix], xF[0])
 *                     x1p = max(nodes_x[ix+1], origin[0])
 *                     overlapping_cell_inds = self.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)             # <<<<<<<<<<<<<<
 *                     n_overlap = overlapping_cell_inds.size()
 *                     weights = <double *> malloc(n_overlap*sizeof(double))
 */
        __Pyx_TraceLine(6387,0,__PYX_ERR(0, 6387, __pyx_L1_error))
        __pyx_v_overlapping_cell_inds = __pyx_v_self->tree->find_overlapping_cells(__pyx_v_x1m, __pyx_v_x1p, __pyx_v_y1m, __pyx_v_y1p, __pyx_v_z1m, __pyx_v_z1p);

        /* "discretize/_extensions/tree_ext.pyx":6388
 *                     x1p = max(nodes_x[ix+1], origin[0])
 *                     overlapping_cell_inds = self.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *                     n_overlap = overlapping_cell_inds.size()             # <<<<<<<<<<<<<<
 *                     weights = <double *> malloc(n_overlap*sizeof(double))
 *                     i = 0
 */
        __Pyx_TraceLine(6388,0,__PYX_ERR(0, 6388, __pyx_L1_error))
        __pyx_v_n_overlap = __pyx_v_overlapping_cell_inds.size();

        /* "discretize/_extensions/tree_ext.pyx":6389
 *                     overlapping_cell_inds = self.tree.find_overlapping_cells(x1m, x1p, y1m, y1p, z1m, z1p)
 *                     n_overlap = overlapping_cell_inds.size()
 *                     weights = <double *> malloc(n_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 *                     i = 0
 *                     weight_sum = 0.0
 */
        __Pyx_TraceLine(6389,0,__PYX_ERR(0, 6389, __pyx_L1_error))
        __pyx_v_weights = ((double *)malloc((__pyx_v_n_overlap * (sizeof(double)))));

        /* "discretize/_extensions/tree_ext.pyx":6390
 *                     n_overlap = overlapping_cell_inds.size()
 *                     weights = <double *> malloc(n_overlap*sizeof(double))
 *                     i = 0             # <<<<<<<<<<<<<<
 *                     weight_sum = 0.0
 *                     nnz_row = 0
 */
        __Pyx_TraceLine(6390,0,__PYX_ERR(0, 6390, __pyx_L1_error))
        __pyx_v_i = 0;

        /* "discretize/_extensions/tree_ext.pyx":6391
 *                     weights = <double *> malloc(n_overlap*sizeof(double))
 *                     i = 0
 *                     weight_sum = 0.0             # <<<<<<<<<<<<<<
 *                     nnz_row = 0
 *                     for in_cell_ind in overlapping_cell_inds:
 */
        __Pyx_TraceLine(6391,0,__PYX_ERR(0, 6391, __pyx_L1_error))
        __pyx_v_weight_sum = 0.0;

        /* "discretize/_extensions/tree_ext.pyx":6392
 *                     i = 0
 *                     weight_sum = 0.0
 *                     nnz_row = 0             # <<<<<<<<<<<<<<
 *                     for in_cell_ind in overlapping_cell_inds:
 *                         in_cell = self.tree.cells[in_cell_ind]
 */
        __Pyx_TraceLine(6392,0,__PYX_ERR(0, 6392, __pyx_L1_error))
        __pyx_v_nnz_row = 0;

        /* "discretize/_extensions/tree_ext.pyx":6393
 *                     weight_sum = 0.0
 *                     nnz_row = 0
 *                     for in_cell_ind in overlapping_cell_inds:             # <<<<<<<<<<<<<<
 *                         in_cell = self.tree.cells[in_cell_ind]
 *                         x2m = in_cell.points[0].location[0]
 */
        __Pyx_TraceLine(6393,0,__PYX_ERR(0, 6393, __pyx_L1_error))
        __pyx_t_30 = __pyx_v_overlapping_cell_inds.begin();
        for (;;) {
          if (!(__pyx_t_30 != __pyx_v_overlapping_cell_inds.end())) break;
          __pyx_t_31 = *__pyx_t_30;
          ++__pyx_t_30;
          __pyx_v_in_cell_ind = __pyx_t_31;

          /* "discretize/_extensions/tree_ext.pyx":6394
 *                     nnz_row = 0
 *                     for in_cell_ind in overlapping_cell_inds:
 *                         in_cell = self.tree.cells[in_cell_ind]             # <<<<<<<<<<<<<<
 *                         x2m = in_cell.points[0].location[0]
 *                         y2m = in_cell.points[0].location[1]
 */
          __Pyx_TraceLine(6394,0,__PYX_ERR(0, 6394, __pyx_L1_error))
          __pyx_v_in_cell = (__pyx_v_self->tree->cells[__pyx_v_in_cell_ind]);

          /* "discretize/_extensions/tree_ext.pyx":6395
 *                     for in_cell_ind in overlapping_cell_inds:
 *                         in_cell = self.tree.cells[in_cell_ind]
 *                         x2m = in_cell.points[0].location[0]             # <<<<<<<<<<<<<<
 *                         y2m = in_cell.points[0].location[1]
 *                         z2m = in_cell.points[0].location[2]
 */
          __Pyx_TraceLine(6395,0,__PYX_ERR(0, 6395, __pyx_L1_error))
          __pyx_v_x2m = ((__pyx_v_in_cell->points[0])->location[0]);

          /* "discretize/_extensions/tree_ext.pyx":6396
 *                         in_cell = self.tree.cells[in_cell_ind]
 *                         x2m = in_cell.points[0].location[0]
 *                         y2m = in_cell.points[0].location[1]             # <<<<<<<<<<<<<<
 *                         z2m = in_cell.points[0].location[2]
 *                         x2p = in_cell.points[3].location[0]
 */
          __Pyx_TraceLine(6396,0,__PYX_ERR(0, 6396, __pyx_L1_error))
          __pyx_v_y2m = ((__pyx_v_in_cell->points[0])->location[1]);

          /* "discretize/_extensions/tree_ext.pyx":6397
 *                         x2m = in_cell.points[0].location[0]
 *                         y2m = in_cell.points[0].location[1]
 *                         z2m = in_cell.points[0].location[2]             # <<<<<<<<<<<<<<
 *                         x2p = in_cell.points[3].location[0]
 *                         y2p = in_cell.points[3].location[1]
 */
          __Pyx_TraceLine(6397,0,__PYX_ERR(0, 6397, __pyx_L1_error))
          __pyx_v_z2m = ((__pyx_v_in_cell->points[0])->location[2]);

          /* "discretize/_extensions/tree_ext.pyx":6398
 *                         y2m = in_cell.points[0].location[1]
 *                         z2m = in_cell.points[0].location[2]
 *                         x2p = in_cell.points[3].location[0]             # <<<<<<<<<<<<<<
 *                         y2p = in_cell.points[3].location[1]
 *                         z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 */
          __Pyx_TraceLine(6398,0,__PYX_ERR(0, 6398, __pyx_L1_error))
          __pyx_v_x2p = ((__pyx_v_in_cell->points[3])->location[0]);

          /* "discretize/_extensions/tree_ext.pyx":6399
 *                         z2m = in_cell.points[0].location[2]
 *                         x2p = in_cell.points[3].location[0]
 *                         y2p = in_cell.points[3].location[1]             # <<<<<<<<<<<<<<
 *                         z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 */
          __Pyx_TraceLine(6399,0,__PYX_ERR(0, 6399, __pyx_L1_error))
          __pyx_v_y2p = ((__pyx_v_in_cell->points[3])->location[1]);

          /* "discretize/_extensions/tree_ext.pyx":6400
 *                         x2p = in_cell.points[3].location[0]
 *                         y2p = in_cell.points[3].location[1]
 *                         z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0             # <<<<<<<<<<<<<<
 * 
 *                         if x1m == xF[0] or x1p == origin[0]:
 */
          __Pyx_TraceLine(6400,0,__PYX_ERR(0, 6400, __pyx_L1_error))
          if (((__pyx_v_self->_dim == 3) != 0)) {
            __pyx_t_21 = ((__pyx_v_in_cell->points[7])->location[2]);
          } else {
            __pyx_t_21 = 0.0;
          }
          __pyx_v_z2p = __pyx_t_21;

          /* "discretize/_extensions/tree_ext.pyx":6402
 *                         z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 *                         if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                             over_lap_vol = 1.0
 *                         else:
 */
          __Pyx_TraceLine(6402,0,__PYX_ERR(0, 6402, __pyx_L1_error))
          __pyx_t_16 = 0;
          if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
          __pyx_t_14 = ((__pyx_v_x1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )))) != 0);
          if (!__pyx_t_14) {
          } else {
            __pyx_t_12 = __pyx_t_14;
            goto __pyx_L32_bool_binop_done;
          }
          __pyx_t_16 = 0;
          if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
          __pyx_t_14 = ((__pyx_v_x1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )))) != 0);
          __pyx_t_12 = __pyx_t_14;
          __pyx_L32_bool_binop_done:;
          if (__pyx_t_12) {

            /* "discretize/_extensions/tree_ext.pyx":6403
 * 
 *                         if x1m == xF[0] or x1p == origin[0]:
 *                             over_lap_vol = 1.0             # <<<<<<<<<<<<<<
 *                         else:
 *                             over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 */
            __Pyx_TraceLine(6403,0,__PYX_ERR(0, 6403, __pyx_L1_error))
            __pyx_v_over_lap_vol = 1.0;

            /* "discretize/_extensions/tree_ext.pyx":6402
 *                         z2p = in_cell.points[7].location[2] if self._dim==3 else 0.0
 * 
 *                         if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                             over_lap_vol = 1.0
 *                         else:
 */
            goto __pyx_L31;
          }

          /* "discretize/_extensions/tree_ext.pyx":6405
 *                             over_lap_vol = 1.0
 *                         else:
 *                             over_lap_vol = min(x1p, x2p) - max(x1m, x2m)             # <<<<<<<<<<<<<<
 *                         if y1m == xF[1] or y1p == origin[1]:
 *                             over_lap_vol *= 1.0
 */
          __Pyx_TraceLine(6405,0,__PYX_ERR(0, 6405, __pyx_L1_error))
          /*else*/ {
            __pyx_t_21 = __pyx_v_x2p;
            __pyx_t_22 = __pyx_v_x1p;
            if (((__pyx_t_21 < __pyx_t_22) != 0)) {
              __pyx_t_23 = __pyx_t_21;
            } else {
              __pyx_t_23 = __pyx_t_22;
            }
            __pyx_t_21 = __pyx_v_x2m;
            __pyx_t_22 = __pyx_v_x1m;
            if (((__pyx_t_21 > __pyx_t_22) != 0)) {
              __pyx_t_32 = __pyx_t_21;
            } else {
              __pyx_t_32 = __pyx_t_22;
            }
            __pyx_v_over_lap_vol = (__pyx_t_23 - __pyx_t_32);
          }
          __pyx_L31:;

          /* "discretize/_extensions/tree_ext.pyx":6406
 *                         else:
 *                             over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                         if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                             over_lap_vol *= 1.0
 *                         else:
 */
          __Pyx_TraceLine(6406,0,__PYX_ERR(0, 6406, __pyx_L1_error))
          __pyx_t_16 = 1;
          if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
          __pyx_t_14 = ((__pyx_v_y1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )))) != 0);
          if (!__pyx_t_14) {
          } else {
            __pyx_t_12 = __pyx_t_14;
            goto __pyx_L35_bool_binop_done;
          }
          __pyx_t_16 = 1;
          if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
          __pyx_t_14 = ((__pyx_v_y1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )))) != 0);
          __pyx_t_12 = __pyx_t_14;
          __pyx_L35_bool_binop_done:;
          if (__pyx_t_12) {

            /* "discretize/_extensions/tree_ext.pyx":6407
 *                             over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                         if y1m == xF[1] or y1p == origin[1]:
 *                             over_lap_vol *= 1.0             # <<<<<<<<<<<<<<
 *                         else:
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 */
            __Pyx_TraceLine(6407,0,__PYX_ERR(0, 6407, __pyx_L1_error))
            __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * 1.0);

            /* "discretize/_extensions/tree_ext.pyx":6406
 *                         else:
 *                             over_lap_vol = min(x1p, x2p) - max(x1m, x2m)
 *                         if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                             over_lap_vol *= 1.0
 *                         else:
 */
            goto __pyx_L34;
          }

          /* "discretize/_extensions/tree_ext.pyx":6409
 *                             over_lap_vol *= 1.0
 *                         else:
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)             # <<<<<<<<<<<<<<
 *                         if self._dim==3:
 *                             if z1m == xF[2] or z1p == origin[2]:
 */
          __Pyx_TraceLine(6409,0,__PYX_ERR(0, 6409, __pyx_L1_error))
          /*else*/ {
            __pyx_t_32 = __pyx_v_y2p;
            __pyx_t_23 = __pyx_v_y1p;
            if (((__pyx_t_32 < __pyx_t_23) != 0)) {
              __pyx_t_21 = __pyx_t_32;
            } else {
              __pyx_t_21 = __pyx_t_23;
            }
            __pyx_t_32 = __pyx_v_y2m;
            __pyx_t_23 = __pyx_v_y1m;
            if (((__pyx_t_32 > __pyx_t_23) != 0)) {
              __pyx_t_22 = __pyx_t_32;
            } else {
              __pyx_t_22 = __pyx_t_23;
            }
            __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * (__pyx_t_21 - __pyx_t_22));
          }
          __pyx_L34:;

          /* "discretize/_extensions/tree_ext.pyx":6410
 *                         else:
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                         if self._dim==3:             # <<<<<<<<<<<<<<
 *                             if z1m == xF[2] or z1p == origin[2]:
 *                                 over_lap_vol *= 1.0
 */
          __Pyx_TraceLine(6410,0,__PYX_ERR(0, 6410, __pyx_L1_error))
          __pyx_t_12 = ((__pyx_v_self->_dim == 3) != 0);
          if (__pyx_t_12) {

            /* "discretize/_extensions/tree_ext.pyx":6411
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                         if self._dim==3:
 *                             if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                                 over_lap_vol *= 1.0
 *                             else:
 */
            __Pyx_TraceLine(6411,0,__PYX_ERR(0, 6411, __pyx_L1_error))
            __pyx_t_16 = 2;
            if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_xF.shape[0];
            __pyx_t_14 = ((__pyx_v_z1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_16 * __pyx_v_xF.strides[0]) )))) != 0);
            if (!__pyx_t_14) {
            } else {
              __pyx_t_12 = __pyx_t_14;
              goto __pyx_L39_bool_binop_done;
            }
            __pyx_t_16 = 2;
            if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_origin.shape[0];
            __pyx_t_14 = ((__pyx_v_z1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_16 * __pyx_v_origin.strides[0]) )))) != 0);
            __pyx_t_12 = __pyx_t_14;
            __pyx_L39_bool_binop_done:;
            if (__pyx_t_12) {

              /* "discretize/_extensions/tree_ext.pyx":6412
 *                         if self._dim==3:
 *                             if z1m == xF[2] or z1p == origin[2]:
 *                                 over_lap_vol *= 1.0             # <<<<<<<<<<<<<<
 *                             else:
 *                                 over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)
 */
              __Pyx_TraceLine(6412,0,__PYX_ERR(0, 6412, __pyx_L1_error))
              __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * 1.0);

              /* "discretize/_extensions/tree_ext.pyx":6411
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                         if self._dim==3:
 *                             if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                                 over_lap_vol *= 1.0
 *                             else:
 */
              goto __pyx_L38;
            }

            /* "discretize/_extensions/tree_ext.pyx":6414
 *                                 over_lap_vol *= 1.0
 *                             else:
 *                                 over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)             # <<<<<<<<<<<<<<
 * 
 *                         weights[i] = over_lap_vol
 */
            __Pyx_TraceLine(6414,0,__PYX_ERR(0, 6414, __pyx_L1_error))
            /*else*/ {
              __pyx_t_22 = __pyx_v_z2p;
              __pyx_t_21 = __pyx_v_z1p;
              if (((__pyx_t_22 < __pyx_t_21) != 0)) {
                __pyx_t_32 = __pyx_t_22;
              } else {
                __pyx_t_32 = __pyx_t_21;
              }
              __pyx_t_22 = __pyx_v_z2m;
              __pyx_t_21 = __pyx_v_z1m;
              if (((__pyx_t_22 > __pyx_t_21) != 0)) {
                __pyx_t_23 = __pyx_t_22;
              } else {
                __pyx_t_23 = __pyx_t_21;
              }
              __pyx_v_over_lap_vol = (__pyx_v_over_lap_vol * (__pyx_t_32 - __pyx_t_23));
            }
            __pyx_L38:;

            /* "discretize/_extensions/tree_ext.pyx":6410
 *                         else:
 *                             over_lap_vol *= min(y1p, y2p) - max(y1m, y2m)
 *                         if self._dim==3:             # <<<<<<<<<<<<<<
 *                             if z1m == xF[2] or z1p == origin[2]:
 *                                 over_lap_vol *= 1.0
 */
          }

          /* "discretize/_extensions/tree_ext.pyx":6416
 *                                 over_lap_vol *= min(z1p, z2p) - max(z1m, z2m)
 * 
 *                         weights[i] = over_lap_vol             # <<<<<<<<<<<<<<
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1
 */
          __Pyx_TraceLine(6416,0,__PYX_ERR(0, 6416, __pyx_L1_error))
          (__pyx_v_weights[__pyx_v_i]) = __pyx_v_over_lap_vol;

          /* "discretize/_extensions/tree_ext.pyx":6417
 * 
 *                         weights[i] = over_lap_vol
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)
 */
          __Pyx_TraceLine(6417,0,__PYX_ERR(0, 6417, __pyx_L1_error))
          __pyx_t_14 = (__pyx_v_build_mat != 0);
          if (__pyx_t_14) {
          } else {
            __pyx_t_12 = __pyx_t_14;
            goto __pyx_L42_bool_binop_done;
          }
          __pyx_t_14 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
          __pyx_t_12 = __pyx_t_14;
          __pyx_L42_bool_binop_done:;
          if (__pyx_t_12) {

            /* "discretize/_extensions/tree_ext.pyx":6418
 *                         weights[i] = over_lap_vol
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1             # <<<<<<<<<<<<<<
 *                             row_inds.push_back(in_cell_ind)
 *                         weight_sum += weights[i]
 */
            __Pyx_TraceLine(6418,0,__PYX_ERR(0, 6418, __pyx_L1_error))
            __pyx_v_nnz_row = (__pyx_v_nnz_row + 1);

            /* "discretize/_extensions/tree_ext.pyx":6419
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)             # <<<<<<<<<<<<<<
 *                         weight_sum += weights[i]
 *                         i += 1
 */
            __Pyx_TraceLine(6419,0,__PYX_ERR(0, 6419, __pyx_L1_error))
            try {
              __pyx_v_row_inds.push_back(__pyx_v_in_cell_ind);
            } catch(...) {
              __Pyx_CppExn2PyErr();
              __PYX_ERR(0, 6419, __pyx_L1_error)
            }

            /* "discretize/_extensions/tree_ext.pyx":6417
 * 
 *                         weights[i] = over_lap_vol
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)
 */
          }

          /* "discretize/_extensions/tree_ext.pyx":6420
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)
 *                         weight_sum += weights[i]             # <<<<<<<<<<<<<<
 *                         i += 1
 *                     for i in range(n_overlap):
 */
          __Pyx_TraceLine(6420,0,__PYX_ERR(0, 6420, __pyx_L1_error))
          __pyx_v_weight_sum = (__pyx_v_weight_sum + (__pyx_v_weights[__pyx_v_i]));

          /* "discretize/_extensions/tree_ext.pyx":6421
 *                             row_inds.push_back(in_cell_ind)
 *                         weight_sum += weights[i]
 *                         i += 1             # <<<<<<<<<<<<<<
 *                     for i in range(n_overlap):
 *                         weights[i] /= weight_sum
 */
          __Pyx_TraceLine(6421,0,__PYX_ERR(0, 6421, __pyx_L1_error))
          __pyx_v_i = (__pyx_v_i + 1);

          /* "discretize/_extensions/tree_ext.pyx":6393
 *                     weight_sum = 0.0
 *                     nnz_row = 0
 *                     for in_cell_ind in overlapping_cell_inds:             # <<<<<<<<<<<<<<
 *                         in_cell = self.tree.cells[in_cell_ind]
 *                         x2m = in_cell.points[0].location[0]
 */
          __Pyx_TraceLine(6393,0,__PYX_ERR(0, 6393, __pyx_L1_error))
        }

        /* "discretize/_extensions/tree_ext.pyx":6422
 *                         weight_sum += weights[i]
 *                         i += 1
 *                     for i in range(n_overlap):             # <<<<<<<<<<<<<<
 *                         weights[i] /= weight_sum
 *                         if build_mat and weights[i] != 0.0:
 */
        __Pyx_TraceLine(6422,0,__PYX_ERR(0, 6422, __pyx_L1_error))
        __pyx_t_31 = __pyx_v_n_overlap;
        __pyx_t_33 = __pyx_t_31;
        for (__pyx_t_34 = 0; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) {
          __pyx_v_i = __pyx_t_34;

          /* "discretize/_extensions/tree_ext.pyx":6423
 *                         i += 1
 *                     for i in range(n_overlap):
 *                         weights[i] /= weight_sum             # <<<<<<<<<<<<<<
 *                         if build_mat and weights[i] != 0.0:
 *                             all_weights.push_back(weights[i])
 */
          __Pyx_TraceLine(6423,0,__PYX_ERR(0, 6423, __pyx_L1_error))
          __pyx_t_35 = __pyx_v_i;
          (__pyx_v_weights[__pyx_t_35]) = ((__pyx_v_weights[__pyx_t_35]) / __pyx_v_weight_sum);

          /* "discretize/_extensions/tree_ext.pyx":6424
 *                     for i in range(n_overlap):
 *                         weights[i] /= weight_sum
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             all_weights.push_back(weights[i])
 * 
 */
          __Pyx_TraceLine(6424,0,__PYX_ERR(0, 6424, __pyx_L1_error))
          __pyx_t_14 = (__pyx_v_build_mat != 0);
          if (__pyx_t_14) {
          } else {
            __pyx_t_12 = __pyx_t_14;
            goto __pyx_L47_bool_binop_done;
          }
          __pyx_t_14 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
          __pyx_t_12 = __pyx_t_14;
          __pyx_L47_bool_binop_done:;
          if (__pyx_t_12) {

            /* "discretize/_extensions/tree_ext.pyx":6425
 *                         weights[i] /= weight_sum
 *                         if build_mat and weights[i] != 0.0:
 *                             all_weights.push_back(weights[i])             # <<<<<<<<<<<<<<
 * 
 *                     if not build_mat:
 */
            __Pyx_TraceLine(6425,0,__PYX_ERR(0, 6425, __pyx_L1_error))
            try {
              __pyx_v_all_weights.push_back((__pyx_v_weights[__pyx_v_i]));
            } catch(...) {
              __Pyx_CppExn2PyErr();
              __PYX_ERR(0, 6425, __pyx_L1_error)
            }

            /* "discretize/_extensions/tree_ext.pyx":6424
 *                     for i in range(n_overlap):
 *                         weights[i] /= weight_sum
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             all_weights.push_back(weights[i])
 * 
 */
          }
        }

        /* "discretize/_extensions/tree_ext.pyx":6427
 *                             all_weights.push_back(weights[i])
 * 
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         for i in range(n_overlap):
 *                             outs[ix, iy, iz] += vals[overlapping_cell_inds[i]]*weights[i]
 */
        __Pyx_TraceLine(6427,0,__PYX_ERR(0, 6427, __pyx_L1_error))
        __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
        if (__pyx_t_12) {

          /* "discretize/_extensions/tree_ext.pyx":6428
 * 
 *                     if not build_mat:
 *                         for i in range(n_overlap):             # <<<<<<<<<<<<<<
 *                             outs[ix, iy, iz] += vals[overlapping_cell_inds[i]]*weights[i]
 *                     else:
 */
          __Pyx_TraceLine(6428,0,__PYX_ERR(0, 6428, __pyx_L1_error))
          __pyx_t_31 = __pyx_v_n_overlap;
          __pyx_t_33 = __pyx_t_31;
          for (__pyx_t_34 = 0; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) {
            __pyx_v_i = __pyx_t_34;

            /* "discretize/_extensions/tree_ext.pyx":6429
 *                     if not build_mat:
 *                         for i in range(n_overlap):
 *                             outs[ix, iy, iz] += vals[overlapping_cell_inds[i]]*weights[i]             # <<<<<<<<<<<<<<
 *                     else:
 *                         nnz_counter += nnz_row
 */
            __Pyx_TraceLine(6429,0,__PYX_ERR(0, 6429, __pyx_L1_error))
            __pyx_t_16 = (__pyx_v_overlapping_cell_inds[__pyx_v_i]);
            if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_v_vals.shape[0];
            __pyx_t_36 = __pyx_v_ix;
            __pyx_t_37 = __pyx_v_iy;
            __pyx_t_38 = __pyx_v_iz;
            if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_v_outs.shape[0];
            if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_v_outs.shape[1];
            if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_v_outs.shape[2];
            *((__pyx_t_5numpy_float64_t *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ ((char *) (((__pyx_t_5numpy_float64_t *) __pyx_v_outs.data) + __pyx_t_36)) ) + __pyx_t_37 * __pyx_v_outs.strides[1]) ) + __pyx_t_38 * __pyx_v_outs.strides[2]) )) += ((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_vals.data + __pyx_t_16 * __pyx_v_vals.strides[0]) ))) * (__pyx_v_weights[__pyx_v_i]));
          }

          /* "discretize/_extensions/tree_ext.pyx":6427
 *                             all_weights.push_back(weights[i])
 * 
 *                     if not build_mat:             # <<<<<<<<<<<<<<
 *                         for i in range(n_overlap):
 *                             outs[ix, iy, iz] += vals[overlapping_cell_inds[i]]*weights[i]
 */
          goto __pyx_L49;
        }

        /* "discretize/_extensions/tree_ext.pyx":6431
 *                             outs[ix, iy, iz] += vals[overlapping_cell_inds[i]]*weights[i]
 *                     else:
 *                         nnz_counter += nnz_row             # <<<<<<<<<<<<<<
 *                         indptr.push_back(nnz_counter)
 * 
 */
        __Pyx_TraceLine(6431,0,__PYX_ERR(0, 6431, __pyx_L1_error))
        /*else*/ {
          __pyx_v_nnz_counter = (__pyx_v_nnz_counter + __pyx_v_nnz_row);

          /* "discretize/_extensions/tree_ext.pyx":6432
 *                     else:
 *                         nnz_counter += nnz_row
 *                         indptr.push_back(nnz_counter)             # <<<<<<<<<<<<<<
 * 
 *                     free(weights)
 */
          __Pyx_TraceLine(6432,0,__PYX_ERR(0, 6432, __pyx_L1_error))
          try {
            __pyx_v_indptr.push_back(__pyx_v_nnz_counter);
          } catch(...) {
            __Pyx_CppExn2PyErr();
            __PYX_ERR(0, 6432, __pyx_L1_error)
          }
        }
        __pyx_L49:;

        /* "discretize/_extensions/tree_ext.pyx":6434
 *                         indptr.push_back(nnz_counter)
 * 
 *                     free(weights)             # <<<<<<<<<<<<<<
 *                     overlapping_cell_inds.clear()
 * 
 */
        __Pyx_TraceLine(6434,0,__PYX_ERR(0, 6434, __pyx_L1_error))
        free(__pyx_v_weights);

        /* "discretize/_extensions/tree_ext.pyx":6435
 * 
 *                     free(weights)
 *                     overlapping_cell_inds.clear()             # <<<<<<<<<<<<<<
 * 
 *         if not build_mat:
 */
        __Pyx_TraceLine(6435,0,__PYX_ERR(0, 6435, __pyx_L1_error))
        __pyx_v_overlapping_cell_inds.clear();
      }
    }
  }

  /* "discretize/_extensions/tree_ext.pyx":6437
 *                     overlapping_cell_inds.clear()
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output.reshape(-1, order='F')
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(out_tens_mesh.n_cells, self.n_cells))
 */
  __Pyx_TraceLine(6437,0,__PYX_ERR(0, 6437, __pyx_L1_error))
  __pyx_t_12 = ((!(__pyx_v_build_mat != 0)) != 0);
  if (__pyx_t_12) {

    /* "discretize/_extensions/tree_ext.pyx":6438
 * 
 *         if not build_mat:
 *             return output.reshape(-1, order='F')             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(out_tens_mesh.n_cells, self.n_cells))
 * 
 */
    __Pyx_TraceLine(6438,0,__PYX_ERR(0, 6438, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_reshape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6438, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6438, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 6438, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__44, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6438, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6437
 *                     overlapping_cell_inds.clear()
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output.reshape(-1, order='F')
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(out_tens_mesh.n_cells, self.n_cells))
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6439
 *         if not build_mat:
 *             return output.reshape(-1, order='F')
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(out_tens_mesh.n_cells, self.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __Pyx_TraceLine(6439,0,__PYX_ERR(0, 6439, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_sp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __pyx_convert_vector_to_py_double(__pyx_v_all_weights); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __pyx_convert_vector_to_py_int_t(__pyx_v_row_inds); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_9 = __pyx_convert_vector_to_py_int_t(__pyx_v_indptr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_9);
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11);
  __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_out_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6439, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6299
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_to_tens(self, out_tens_mesh, values=None, output=None):             # <<<<<<<<<<<<<<
 *         cdef vector[int_t] *overlapping_cells
 *         cdef double *weights
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_to_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_origin, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_xF, 1);
  __Pyx_XDECREF(__pyx_v_in_cell_inds);
  __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_x, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_y, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_z, 1);
  __Pyx_XDECREF(__pyx_v_output);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6443
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_from_tens(self, in_tens_mesh, values=None, output=None):             # <<<<<<<<<<<<<<
 *         cdef double *weights
 *         cdef double over_lap_vol
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_101_vol_avg_from_tens(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_100_vol_avg_from_tens[] = "_TreeMesh._vol_avg_from_tens(self, in_tens_mesh, values=None, output=None)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_101_vol_avg_from_tens(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_in_tens_mesh = 0;
  PyObject *__pyx_v_values = 0;
  PyObject *__pyx_v_output = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_vol_avg_from_tens (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_in_tens_mesh,&__pyx_n_s_values,&__pyx_n_s_output,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    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_in_tens_mesh)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_values);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_output);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_vol_avg_from_tens") < 0)) __PYX_ERR(0, 6443, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_in_tens_mesh = values[0];
    __pyx_v_values = values[1];
    __pyx_v_output = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_vol_avg_from_tens", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 6443, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_100_vol_avg_from_tens(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), __pyx_v_in_tens_mesh, __pyx_v_values, __pyx_v_output);

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_100_vol_avg_from_tens(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_in_tens_mesh, PyObject *__pyx_v_values, PyObject *__pyx_v_output) {
  double *__pyx_v_weights;
  double __pyx_v_x1m;
  double __pyx_v_x1p;
  double __pyx_v_y1m;
  double __pyx_v_y1p;
  double __pyx_v_z1m;
  double __pyx_v_z1p;
  double __pyx_v_x2m;
  double __pyx_v_x2p;
  double __pyx_v_y2m;
  double __pyx_v_y2p;
  double __pyx_v_z2m;
  double __pyx_v_z2p;
  int_t __pyx_v_ix;
  int_t __pyx_v_ix1;
  int_t __pyx_v_ix2;
  int_t __pyx_v_iy;
  int_t __pyx_v_iy1;
  int_t __pyx_v_iy2;
  int_t __pyx_v_iz;
  int_t __pyx_v_iz1;
  int_t __pyx_v_iz2;
  __Pyx_memviewslice __pyx_v_origin = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_xF = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_same_base;
  PyObject *__pyx_v_out_cell_inds = NULL;
  PyObject *__pyx_v_ws = NULL;
  __Pyx_memviewslice __pyx_v_nodes_x = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_nodes_y = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_nodes_z = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_nx;
  int_t __pyx_v_ny;
  int_t __pyx_v_nz;
  double *__pyx_v_dx;
  double *__pyx_v_dy;
  double *__pyx_v_dz;
  __Pyx_memviewslice __pyx_v_vals = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_outs = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_build_mat;
  std::vector<int_t>  __pyx_v_row_inds;
  std::vector<double>  __pyx_v_all_weights;
  __Pyx_memviewslice __pyx_v_indptr = { 0, 0, { 0 }, { 0 }, { 0 } };
  int_t __pyx_v_nnz_counter;
  int_t __pyx_v_nnz_row;
  int_t __pyx_v_nx_overlap;
  int_t __pyx_v_ny_overlap;
  int_t __pyx_v_nz_overlap;
  int_t __pyx_v_n_overlap;
  int_t __pyx_v_i;
  double __pyx_v_weight_sum;
  Cell *__pyx_v_cell;
  int_t __pyx_v_in_cell_ind;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_memviewslice __pyx_t_2 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  int_t __pyx_t_14;
  int __pyx_t_15;
  __Pyx_memviewslice __pyx_t_16 = { 0, 0, { 0 }, { 0 }, { 0 } };
  size_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  __Pyx_memviewslice __pyx_t_19 = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_t_20 = { 0, 0, { 0 }, { 0 }, { 0 } };
  std::vector<Cell *> ::iterator __pyx_t_21;
  std::vector<Cell *>  *__pyx_t_22;
  Cell *__pyx_t_23;
  double __pyx_t_24;
  double __pyx_t_25;
  double __pyx_t_26;
  long __pyx_t_27;
  __pyx_t_5numpy_int64_t __pyx_t_28;
  __pyx_t_5numpy_int64_t __pyx_t_29;
  int_t __pyx_t_30;
  double __pyx_t_31;
  int_t __pyx_t_32;
  int_t __pyx_t_33;
  int_t __pyx_t_34;
  int_t __pyx_t_35;
  int_t __pyx_t_36;
  int_t __pyx_t_37;
  Py_ssize_t __pyx_t_38;
  Py_ssize_t __pyx_t_39;
  PY_LONG_LONG __pyx_t_40;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_vol_avg_from_tens", 0);
  __Pyx_TraceCall("_vol_avg_from_tens", __pyx_f[0], 6443, 0, __PYX_ERR(0, 6443, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_output);

  /* "discretize/_extensions/tree_ext.pyx":6449
 *         cdef double x2m, x2p, y2m, y2p, z2m, z2p
 *         cdef int_t ix, ix1, ix2, iy, iy1, iy2, iz, iz1, iz2
 *         cdef double[:] origin = in_tens_mesh.origin             # <<<<<<<<<<<<<<
 *         cdef double[:] xF
 * 
 */
  __Pyx_TraceLine(6449,0,__PYX_ERR(0, 6449, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_origin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 6449, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_origin = __pyx_t_2;
  __pyx_t_2.memview = NULL;
  __pyx_t_2.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6454
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)
 */
  __Pyx_TraceLine(6454,0,__PYX_ERR(0, 6454, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_5);
    /*try:*/ {

      /* "discretize/_extensions/tree_ext.pyx":6456
 *         try:
 *             same_base = (
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)             # <<<<<<<<<<<<<<
 *                 and np.allclose(self.nodes_y, in_tens_mesh.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, in_tens_mesh.nodes_z))
 */
      __Pyx_TraceLine(6456,0,__PYX_ERR(0, 6456, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6456, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_allclose); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6456, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6456, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6456, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_7, __pyx_t_9};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6456, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_7, __pyx_t_9};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6456, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6456, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_10) {
          __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_9);
        __pyx_t_7 = 0;
        __pyx_t_9 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6456, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 6456, __pyx_L3_error)
      if (__pyx_t_13) {
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        __pyx_t_14 = __Pyx_PyInt_As_int_t(__pyx_t_1); if (unlikely((__pyx_t_14 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6456, __pyx_L3_error)
        __pyx_t_6 = __pyx_t_14;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6457
 *             same_base = (
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)
 *                 and np.allclose(self.nodes_y, in_tens_mesh.nodes_y)             # <<<<<<<<<<<<<<
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, in_tens_mesh.nodes_z))
 *             )
 */
      __Pyx_TraceLine(6457,0,__PYX_ERR(0, 6457, __pyx_L3_error))
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6457, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_allclose); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6457, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6457, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6457, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_9};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6457, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_9};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6457, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6457, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_11, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_11, __pyx_t_9);
        __pyx_t_8 = 0;
        __pyx_t_9 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6457, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 6457, __pyx_L3_error)
      if (__pyx_t_13) {
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        __pyx_t_14 = __Pyx_PyInt_As_int_t(__pyx_t_1); if (unlikely((__pyx_t_14 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6457, __pyx_L3_error)
        __pyx_t_6 = __pyx_t_14;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L9_bool_binop_done;
      }

      /* "discretize/_extensions/tree_ext.pyx":6458
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)
 *                 and np.allclose(self.nodes_y, in_tens_mesh.nodes_y)
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, in_tens_mesh.nodes_z))             # <<<<<<<<<<<<<<
 *             )
 *         except ValueError:
 */
      __Pyx_TraceLine(6458,0,__PYX_ERR(0, 6458, __pyx_L3_error))
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 6458, __pyx_L3_error)
      if (!__pyx_t_13) {
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } else {
        __pyx_t_14 = __Pyx_PyInt_As_int_t(__pyx_t_12); if (unlikely((__pyx_t_14 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6458, __pyx_L3_error)
        __pyx_t_6 = __pyx_t_14;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_allclose); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6458, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_10)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
        __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6458, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
        __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6458, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6458, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (__pyx_t_8) {
          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_t_9);
        __pyx_t_1 = 0;
        __pyx_t_9 = 0;
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6458, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_14 = __Pyx_PyInt_As_int_t(__pyx_t_12); if (unlikely((__pyx_t_14 == ((int_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 6458, __pyx_L3_error)
      __pyx_t_6 = __pyx_t_14;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_v_same_base = __pyx_t_6;

      /* "discretize/_extensions/tree_ext.pyx":6454
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)
 */
    }
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
    __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;

    /* "discretize/_extensions/tree_ext.pyx":6460
 *                 and (self.dim == 2 or np.allclose(self.nodes_z, in_tens_mesh.nodes_z))
 *             )
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             same_base = False
 * 
 */
    __Pyx_TraceLine(6460,0,__PYX_ERR(0, 6460, __pyx_L5_except_error))
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_11) {
      __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_12, &__pyx_t_10, &__pyx_t_7) < 0) __PYX_ERR(0, 6460, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GOTREF(__pyx_t_7);

      /* "discretize/_extensions/tree_ext.pyx":6461
 *             )
 *         except ValueError:
 *             same_base = False             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(6461,0,__PYX_ERR(0, 6461, __pyx_L5_except_error))
      __pyx_v_same_base = 0;
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "discretize/_extensions/tree_ext.pyx":6454
 *         # first check if they have the same tensor base, as it makes it a lot easier...
 *         cdef int_t same_base
 *         try:             # <<<<<<<<<<<<<<
 *             same_base = (
 *                 np.allclose(self.nodes_x, in_tens_mesh.nodes_x)
 */
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
    __pyx_L8_try_end:;
  }

  /* "discretize/_extensions/tree_ext.pyx":6464
 * 
 * 
 *         if same_base:             # <<<<<<<<<<<<<<
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 */
  __Pyx_TraceLine(6464,0,__PYX_ERR(0, 6464, __pyx_L1_error))
  __pyx_t_13 = (__pyx_v_same_base != 0);
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":6465
 * 
 *         if same_base:
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)             # <<<<<<<<<<<<<<
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 *             if values is not None:
 */
    __Pyx_TraceLine(6465,0,__PYX_ERR(0, 6465, __pyx_L1_error))
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_containing_cell_indexes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_cell_centers); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    __pyx_t_7 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_9, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_12);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_v_out_cell_inds = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6466
 *         if same_base:
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]             # <<<<<<<<<<<<<<
 *             if values is not None:
 *                 if output is None:
 */
    __Pyx_TraceLine(6466,0,__PYX_ERR(0, 6466, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_cell_volumes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cell_volumes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_t_10, __pyx_v_out_cell_inds); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_v_ws = __pyx_t_10;
    __pyx_t_10 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6467
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 *             if values is not None:             # <<<<<<<<<<<<<<
 *                 if output is None:
 *                     output = np.empty(self.n_cells)
 */
    __Pyx_TraceLine(6467,0,__PYX_ERR(0, 6467, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_values != Py_None);
    __pyx_t_15 = (__pyx_t_13 != 0);
    if (__pyx_t_15) {

      /* "discretize/_extensions/tree_ext.pyx":6468
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 *             if values is not None:
 *                 if output is None:             # <<<<<<<<<<<<<<
 *                     output = np.empty(self.n_cells)
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 */
      __Pyx_TraceLine(6468,0,__PYX_ERR(0, 6468, __pyx_L1_error))
      __pyx_t_15 = (__pyx_v_output == Py_None);
      __pyx_t_13 = (__pyx_t_15 != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":6469
 *             if values is not None:
 *                 if output is None:
 *                     output = np.empty(self.n_cells)             # <<<<<<<<<<<<<<
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 *                 return output
 */
        __Pyx_TraceLine(6469,0,__PYX_ERR(0, 6469, __pyx_L1_error))
        __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6469, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6469, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6469, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_9 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        __pyx_t_10 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_12);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6469, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "discretize/_extensions/tree_ext.pyx":6468
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 *             if values is not None:
 *                 if output is None:             # <<<<<<<<<<<<<<
 *                     output = np.empty(self.n_cells)
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 */
      }

      /* "discretize/_extensions/tree_ext.pyx":6470
 *                 if output is None:
 *                     output = np.empty(self.n_cells)
 *                 output[:] = np.bincount(out_cell_inds, ws*values)             # <<<<<<<<<<<<<<
 *                 return output
 *             return sp.csr_matrix(
 */
      __Pyx_TraceLine(6470,0,__PYX_ERR(0, 6470, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_bincount); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyNumber_Multiply(__pyx_v_ws, __pyx_v_values); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_out_cell_inds, __pyx_t_7};
        __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6470, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_out_cell_inds, __pyx_t_7};
        __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6470, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6470, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_INCREF(__pyx_v_out_cell_inds);
        __Pyx_GIVEREF(__pyx_v_out_cell_inds);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_v_out_cell_inds);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6470, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (__Pyx_PyObject_SetSlice(__pyx_v_output, __pyx_t_10, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 6470, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6471
 *                     output = np.empty(self.n_cells)
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 *                 return output             # <<<<<<<<<<<<<<
 *             return sp.csr_matrix(
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),
 */
      __Pyx_TraceLine(6471,0,__PYX_ERR(0, 6471, __pyx_L1_error))
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_output);
      __pyx_r = __pyx_v_output;
      goto __pyx_L0;

      /* "discretize/_extensions/tree_ext.pyx":6467
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 *             if values is not None:             # <<<<<<<<<<<<<<
 *                 if output is None:
 *                     output = np.empty(self.n_cells)
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6472
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),
 *                 shape=(self.n_cells, in_tens_mesh.n_cells)
 */
    __Pyx_TraceLine(6472,0,__PYX_ERR(0, 6472, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_sp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6472, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6472, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6473
 *                 return output
 *             return sp.csr_matrix(
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),             # <<<<<<<<<<<<<<
 *                 shape=(self.n_cells, in_tens_mesh.n_cells)
 *             )
 */
    __Pyx_TraceLine(6473,0,__PYX_ERR(0, 6473, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_arange); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_10 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_out_cell_inds);
    __Pyx_GIVEREF(__pyx_v_out_cell_inds);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_out_cell_inds);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_INCREF(__pyx_v_ws);
    __Pyx_GIVEREF(__pyx_v_ws);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_ws);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6472
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),
 *                 shape=(self.n_cells, in_tens_mesh.n_cells)
 */
    __Pyx_TraceLine(6472,0,__PYX_ERR(0, 6472, __pyx_L1_error))
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6472, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_10);
    __pyx_t_10 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6474
 *             return sp.csr_matrix(
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),
 *                 shape=(self.n_cells, in_tens_mesh.n_cells)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
    __Pyx_TraceLine(6474,0,__PYX_ERR(0, 6474, __pyx_L1_error))
    __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6474, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
    __pyx_t_1 = 0;
    __pyx_t_9 = 0;
    if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_shape, __pyx_t_8) < 0) __PYX_ERR(0, 6474, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discretize/_extensions/tree_ext.pyx":6472
 *                 output[:] = np.bincount(out_cell_inds, ws*values)
 *                 return output
 *             return sp.csr_matrix(             # <<<<<<<<<<<<<<
 *                 (ws, (out_cell_inds, np.arange(in_tens_mesh.n_cells))),
 *                 shape=(self.n_cells, in_tens_mesh.n_cells)
 */
    __Pyx_TraceLine(6472,0,__PYX_ERR(0, 6472, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6472, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_r = __pyx_t_8;
    __pyx_t_8 = 0;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6464
 * 
 * 
 *         if same_base:             # <<<<<<<<<<<<<<
 *             out_cell_inds = self._get_containing_cell_indexes(in_tens_mesh.cell_centers)
 *             ws = in_tens_mesh.cell_volumes/self.cell_volumes[out_cell_inds]
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6478
 * 
 * 
 *         cdef np.float64_t[:] nodes_x = in_tens_mesh.nodes_x             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] nodes_y = in_tens_mesh.nodes_y
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])
 */
  __Pyx_TraceLine(6478,0,__PYX_ERR(0, 6478, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6478, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_x = __pyx_t_16;
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6479
 * 
 *         cdef np.float64_t[:] nodes_x = in_tens_mesh.nodes_x
 *         cdef np.float64_t[:] nodes_y = in_tens_mesh.nodes_y             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim == 3:
 */
  __Pyx_TraceLine(6479,0,__PYX_ERR(0, 6479, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6479, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6479, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_y = __pyx_t_16;
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6480
 *         cdef np.float64_t[:] nodes_x = in_tens_mesh.nodes_x
 *         cdef np.float64_t[:] nodes_y = in_tens_mesh.nodes_y
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])             # <<<<<<<<<<<<<<
 *         if self._dim == 3:
 *             nodes_z = in_tens_mesh.nodes_z
 */
  __Pyx_TraceLine(6480,0,__PYX_ERR(0, 6480, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyList_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_float_0_0);
  __Pyx_GIVEREF(__pyx_float_0_0);
  PyList_SET_ITEM(__pyx_t_10, 0, __pyx_float_0_0);
  __Pyx_INCREF(__pyx_float_0_0);
  __Pyx_GIVEREF(__pyx_float_0_0);
  PyList_SET_ITEM(__pyx_t_10, 1, __pyx_float_0_0);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_8 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6480, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_nodes_z = __pyx_t_16;
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6481
 *         cdef np.float64_t[:] nodes_y = in_tens_mesh.nodes_y
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             nodes_z = in_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 */
  __Pyx_TraceLine(6481,0,__PYX_ERR(0, 6481, __pyx_L1_error))
  __pyx_t_13 = ((__pyx_v_self->_dim == 3) != 0);
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":6482
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim == 3:
 *             nodes_z = in_tens_mesh.nodes_z             # <<<<<<<<<<<<<<
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1
 */
    __Pyx_TraceLine(6482,0,__PYX_ERR(0, 6482, __pyx_L1_error))
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_nodes_z); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_8, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6482, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_z, 1);
    __pyx_v_nodes_z = __pyx_t_16;
    __pyx_t_16.memview = NULL;
    __pyx_t_16.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6481
 *         cdef np.float64_t[:] nodes_y = in_tens_mesh.nodes_y
 *         cdef np.float64_t[:] nodes_z = np.array([0.0, 0.0])
 *         if self._dim == 3:             # <<<<<<<<<<<<<<
 *             nodes_z = in_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6483
 *         if self._dim == 3:
 *             nodes_z = in_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1             # <<<<<<<<<<<<<<
 *         cdef int_t ny = len(nodes_y)-1
 *         cdef int_t nz = len(nodes_z)-1
 */
  __Pyx_TraceLine(6483,0,__PYX_ERR(0, 6483, __pyx_L1_error))
  __pyx_t_17 = __Pyx_MemoryView_Len(__pyx_v_nodes_x); 
  __pyx_v_nx = (__pyx_t_17 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6484
 *             nodes_z = in_tens_mesh.nodes_z
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1             # <<<<<<<<<<<<<<
 *         cdef int_t nz = len(nodes_z)-1
 * 
 */
  __Pyx_TraceLine(6484,0,__PYX_ERR(0, 6484, __pyx_L1_error))
  __pyx_t_17 = __Pyx_MemoryView_Len(__pyx_v_nodes_y); 
  __pyx_v_ny = (__pyx_t_17 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6485
 *         cdef int_t nx = len(nodes_x)-1
 *         cdef int_t ny = len(nodes_y)-1
 *         cdef int_t nz = len(nodes_z)-1             # <<<<<<<<<<<<<<
 * 
 *         cdef double * dx
 */
  __Pyx_TraceLine(6485,0,__PYX_ERR(0, 6485, __pyx_L1_error))
  __pyx_t_17 = __Pyx_MemoryView_Len(__pyx_v_nodes_z); 
  __pyx_v_nz = (__pyx_t_17 - 1);

  /* "discretize/_extensions/tree_ext.pyx":6491
 *         cdef double * dz
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([nodes_x[-1], nodes_y[-1]])
 *         else:
 */
  __Pyx_TraceLine(6491,0,__PYX_ERR(0, 6491, __pyx_L1_error))
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_8, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 6491, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":6492
 * 
 *         if self.dim == 2:
 *             xF = np.array([nodes_x[-1], nodes_y[-1]])             # <<<<<<<<<<<<<<
 *         else:
 *             xF = np.array([nodes_x[-1], nodes_y[-1], nodes_z[-1]])
 */
    __Pyx_TraceLine(6492,0,__PYX_ERR(0, 6492, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_array); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_18 = -1L;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_x.shape[0];
    __pyx_t_8 = PyFloat_FromDouble((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_18 * __pyx_v_nodes_x.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_18 = -1L;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_y.shape[0];
    __pyx_t_12 = PyFloat_FromDouble((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_18 * __pyx_v_nodes_y.strides[0]) )))); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_9 = PyList_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_12);
    PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_12);
    __pyx_t_8 = 0;
    __pyx_t_12 = 0;
    __pyx_t_12 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    __pyx_t_7 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_12, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 6492, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_xF = __pyx_t_2;
    __pyx_t_2.memview = NULL;
    __pyx_t_2.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6491
 *         cdef double * dz
 * 
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([nodes_x[-1], nodes_y[-1]])
 *         else:
 */
    goto __pyx_L19;
  }

  /* "discretize/_extensions/tree_ext.pyx":6494
 *             xF = np.array([nodes_x[-1], nodes_y[-1]])
 *         else:
 *             xF = np.array([nodes_x[-1], nodes_y[-1], nodes_z[-1]])             # <<<<<<<<<<<<<<
 * 
 *         cdef np.float64_t[::1, :, :] vals = np.array([[[]]])
 */
  __Pyx_TraceLine(6494,0,__PYX_ERR(0, 6494, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_18 = -1L;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_x.shape[0];
    __pyx_t_10 = PyFloat_FromDouble((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_18 * __pyx_v_nodes_x.strides[0]) )))); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_18 = -1L;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_y.shape[0];
    __pyx_t_12 = PyFloat_FromDouble((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_18 * __pyx_v_nodes_y.strides[0]) )))); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_18 = -1L;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_z.shape[0];
    __pyx_t_8 = PyFloat_FromDouble((*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_z.data + __pyx_t_18 * __pyx_v_nodes_z.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_12);
    PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
    __pyx_t_10 = 0;
    __pyx_t_12 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 6494, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_xF = __pyx_t_2;
    __pyx_t_2.memview = NULL;
    __pyx_t_2.data = NULL;
  }
  __pyx_L19:;

  /* "discretize/_extensions/tree_ext.pyx":6496
 *             xF = np.array([nodes_x[-1], nodes_y[-1], nodes_z[-1]])
 * 
 *         cdef np.float64_t[::1, :, :] vals = np.array([[[]]])             # <<<<<<<<<<<<<<
 *         cdef np.float64_t[:] outs = np.array([])
 * 
 */
  __Pyx_TraceLine(6496,0,__PYX_ERR(0, 6496, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_19 = __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_19.memview)) __PYX_ERR(0, 6496, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_vals = __pyx_t_19;
  __pyx_t_19.memview = NULL;
  __pyx_t_19.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6497
 * 
 *         cdef np.float64_t[::1, :, :] vals = np.array([[[]]])
 *         cdef np.float64_t[:] outs = np.array([])             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t build_mat = 1
 */
  __Pyx_TraceLine(6497,0,__PYX_ERR(0, 6497, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_t_7, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6497, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_outs = __pyx_t_16;
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6499
 *         cdef np.float64_t[:] outs = np.array([])
 * 
 *         cdef int_t build_mat = 1             # <<<<<<<<<<<<<<
 *         if values is not None:
 *             vals = values.reshape((nx, ny, nz), order='F')
 */
  __Pyx_TraceLine(6499,0,__PYX_ERR(0, 6499, __pyx_L1_error))
  __pyx_v_build_mat = 1;

  /* "discretize/_extensions/tree_ext.pyx":6500
 * 
 *         cdef int_t build_mat = 1
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values.reshape((nx, ny, nz), order='F')
 *             if output is None:
 */
  __Pyx_TraceLine(6500,0,__PYX_ERR(0, 6500, __pyx_L1_error))
  __pyx_t_13 = (__pyx_v_values != Py_None);
  __pyx_t_15 = (__pyx_t_13 != 0);
  if (__pyx_t_15) {

    /* "discretize/_extensions/tree_ext.pyx":6501
 *         cdef int_t build_mat = 1
 *         if values is not None:
 *             vals = values.reshape((nx, ny, nz), order='F')             # <<<<<<<<<<<<<<
 *             if output is None:
 *                 output = np.empty(self.n_cells)
 */
    __Pyx_TraceLine(6501,0,__PYX_ERR(0, 6501, __pyx_L1_error))
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_values, __pyx_n_s_reshape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyInt_From_int_t(__pyx_v_nx); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyInt_From_int_t(__pyx_v_ny); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyInt_From_int_t(__pyx_v_nz); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_8);
    __pyx_t_9 = 0;
    __pyx_t_1 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_12);
    __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 6501, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, __pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_19 = __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_19.memview)) __PYX_ERR(0, 6501, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
    __pyx_v_vals = __pyx_t_19;
    __pyx_t_19.memview = NULL;
    __pyx_t_19.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6502
 *         if values is not None:
 *             vals = values.reshape((nx, ny, nz), order='F')
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 */
    __Pyx_TraceLine(6502,0,__PYX_ERR(0, 6502, __pyx_L1_error))
    __pyx_t_15 = (__pyx_v_output == Py_None);
    __pyx_t_13 = (__pyx_t_15 != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":6503
 *             vals = values.reshape((nx, ny, nz), order='F')
 *             if output is None:
 *                 output = np.empty(self.n_cells)             # <<<<<<<<<<<<<<
 *             output[:] = 0
 *             outs = output
 */
      __Pyx_TraceLine(6503,0,__PYX_ERR(0, 6503, __pyx_L1_error))
      __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6503, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6503, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6503, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_12);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6503, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF_SET(__pyx_v_output, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6502
 *         if values is not None:
 *             vals = values.reshape((nx, ny, nz), order='F')
 *             if output is None:             # <<<<<<<<<<<<<<
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6504
 *             if output is None:
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0             # <<<<<<<<<<<<<<
 *             outs = output
 * 
 */
    __Pyx_TraceLine(6504,0,__PYX_ERR(0, 6504, __pyx_L1_error))
    if (__Pyx_PyObject_SetSlice(__pyx_v_output, __pyx_int_0, 0, 0, NULL, NULL, &__pyx_slice__20, 0, 0, 1) < 0) __PYX_ERR(0, 6504, __pyx_L1_error)

    /* "discretize/_extensions/tree_ext.pyx":6505
 *                 output = np.empty(self.n_cells)
 *             output[:] = 0
 *             outs = output             # <<<<<<<<<<<<<<
 * 
 *             build_mat = 0
 */
    __Pyx_TraceLine(6505,0,__PYX_ERR(0, 6505, __pyx_L1_error))
    __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_output, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 6505, __pyx_L1_error)
    __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
    __pyx_v_outs = __pyx_t_16;
    __pyx_t_16.memview = NULL;
    __pyx_t_16.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6507
 *             outs = output
 * 
 *             build_mat = 0             # <<<<<<<<<<<<<<
 * 
 *         cdef vector[int_t] row_inds
 */
    __Pyx_TraceLine(6507,0,__PYX_ERR(0, 6507, __pyx_L1_error))
    __pyx_v_build_mat = 0;

    /* "discretize/_extensions/tree_ext.pyx":6500
 * 
 *         cdef int_t build_mat = 1
 *         if values is not None:             # <<<<<<<<<<<<<<
 *             vals = values.reshape((nx, ny, nz), order='F')
 *             if output is None:
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6511
 *         cdef vector[int_t] row_inds
 *         cdef vector[double] all_weights
 *         cdef np.int64_t[:] indptr = np.zeros(self.n_cells+1, dtype=np.int64)             # <<<<<<<<<<<<<<
 *         cdef int_t nnz_counter = 0
 *         cdef int_t nnz_row = 0
 */
  __Pyx_TraceLine(6511,0,__PYX_ERR(0, 6511, __pyx_L1_error))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12);
  __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, __pyx_t_9) < 0) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_12); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_t_9, PyBUF_WRITABLE); if (unlikely(!__pyx_t_20.memview)) __PYX_ERR(0, 6511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_indptr = __pyx_t_20;
  __pyx_t_20.memview = NULL;
  __pyx_t_20.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6512
 *         cdef vector[double] all_weights
 *         cdef np.int64_t[:] indptr = np.zeros(self.n_cells+1, dtype=np.int64)
 *         cdef int_t nnz_counter = 0             # <<<<<<<<<<<<<<
 *         cdef int_t nnz_row = 0
 * 
 */
  __Pyx_TraceLine(6512,0,__PYX_ERR(0, 6512, __pyx_L1_error))
  __pyx_v_nnz_counter = 0;

  /* "discretize/_extensions/tree_ext.pyx":6513
 *         cdef np.int64_t[:] indptr = np.zeros(self.n_cells+1, dtype=np.int64)
 *         cdef int_t nnz_counter = 0
 *         cdef int_t nnz_row = 0             # <<<<<<<<<<<<<<
 * 
 *         cdef int_t nx_overlap, ny_overlap, nz_overlap, n_overlap
 */
  __Pyx_TraceLine(6513,0,__PYX_ERR(0, 6513, __pyx_L1_error))
  __pyx_v_nnz_row = 0;

  /* "discretize/_extensions/tree_ext.pyx":6519
 *         cdef double weight_sum
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])
 */
  __Pyx_TraceLine(6519,0,__PYX_ERR(0, 6519, __pyx_L1_error))
  __pyx_t_22 = &__pyx_v_self->tree->cells;
  __pyx_t_21 = __pyx_t_22->begin();
  for (;;) {
    if (!(__pyx_t_21 != __pyx_t_22->end())) break;
    __pyx_t_23 = *__pyx_t_21;
    ++__pyx_t_21;
    __pyx_v_cell = __pyx_t_23;

    /* "discretize/_extensions/tree_ext.pyx":6520
 * 
 *         for cell in self.tree.cells:
 *             x1m = min(cell.points[0].location[0], xF[0])             # <<<<<<<<<<<<<<
 *             y1m = min(cell.points[0].location[1], xF[1])
 * 
 */
    __Pyx_TraceLine(6520,0,__PYX_ERR(0, 6520, __pyx_L1_error))
    __pyx_t_18 = 0;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
    __pyx_t_24 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )));
    __pyx_t_25 = ((__pyx_v_cell->points[0])->location[0]);
    if (((__pyx_t_24 < __pyx_t_25) != 0)) {
      __pyx_t_26 = __pyx_t_24;
    } else {
      __pyx_t_26 = __pyx_t_25;
    }
    __pyx_v_x1m = __pyx_t_26;

    /* "discretize/_extensions/tree_ext.pyx":6521
 *         for cell in self.tree.cells:
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])             # <<<<<<<<<<<<<<
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])
 */
    __Pyx_TraceLine(6521,0,__PYX_ERR(0, 6521, __pyx_L1_error))
    __pyx_t_18 = 1;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
    __pyx_t_26 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )));
    __pyx_t_24 = ((__pyx_v_cell->points[0])->location[1]);
    if (((__pyx_t_26 < __pyx_t_24) != 0)) {
      __pyx_t_25 = __pyx_t_26;
    } else {
      __pyx_t_25 = __pyx_t_24;
    }
    __pyx_v_y1m = __pyx_t_25;

    /* "discretize/_extensions/tree_ext.pyx":6523
 *             y1m = min(cell.points[0].location[1], xF[1])
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])             # <<<<<<<<<<<<<<
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:
 */
    __Pyx_TraceLine(6523,0,__PYX_ERR(0, 6523, __pyx_L1_error))
    __pyx_t_18 = 0;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
    __pyx_t_25 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )));
    __pyx_t_26 = ((__pyx_v_cell->points[3])->location[0]);
    if (((__pyx_t_25 > __pyx_t_26) != 0)) {
      __pyx_t_24 = __pyx_t_25;
    } else {
      __pyx_t_24 = __pyx_t_26;
    }
    __pyx_v_x1p = __pyx_t_24;

    /* "discretize/_extensions/tree_ext.pyx":6524
 * 
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])             # <<<<<<<<<<<<<<
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])
 */
    __Pyx_TraceLine(6524,0,__PYX_ERR(0, 6524, __pyx_L1_error))
    __pyx_t_18 = 1;
    if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
    __pyx_t_24 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )));
    __pyx_t_25 = ((__pyx_v_cell->points[3])->location[1]);
    if (((__pyx_t_24 > __pyx_t_25) != 0)) {
      __pyx_t_26 = __pyx_t_24;
    } else {
      __pyx_t_26 = __pyx_t_25;
    }
    __pyx_v_y1p = __pyx_t_26;

    /* "discretize/_extensions/tree_ext.pyx":6525
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])
 */
    __Pyx_TraceLine(6525,0,__PYX_ERR(0, 6525, __pyx_L1_error))
    __pyx_t_13 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":6526
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])             # <<<<<<<<<<<<<<
 *                 z1p = max(cell.points[7].location[2], origin[2])
 *             # then need to find overlapping cells of TensorMesh...
 */
      __Pyx_TraceLine(6526,0,__PYX_ERR(0, 6526, __pyx_L1_error))
      __pyx_t_18 = 2;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
      __pyx_t_26 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )));
      __pyx_t_24 = ((__pyx_v_cell->points[0])->location[2]);
      if (((__pyx_t_26 < __pyx_t_24) != 0)) {
        __pyx_t_25 = __pyx_t_26;
      } else {
        __pyx_t_25 = __pyx_t_24;
      }
      __pyx_v_z1m = __pyx_t_25;

      /* "discretize/_extensions/tree_ext.pyx":6527
 *             if self._dim==3:
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])             # <<<<<<<<<<<<<<
 *             # then need to find overlapping cells of TensorMesh...
 *             ix1 = max(_bisect_left(nodes_x, x1m) - 1, 0)
 */
      __Pyx_TraceLine(6527,0,__PYX_ERR(0, 6527, __pyx_L1_error))
      __pyx_t_18 = 2;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
      __pyx_t_25 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )));
      __pyx_t_26 = ((__pyx_v_cell->points[7])->location[2]);
      if (((__pyx_t_25 > __pyx_t_26) != 0)) {
        __pyx_t_24 = __pyx_t_25;
      } else {
        __pyx_t_24 = __pyx_t_26;
      }
      __pyx_v_z1p = __pyx_t_24;

      /* "discretize/_extensions/tree_ext.pyx":6525
 *             x1p = max(cell.points[3].location[0], origin[0])
 *             y1p = max(cell.points[3].location[1], origin[1])
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 z1m = min(cell.points[0].location[2], xF[2])
 *                 z1p = max(cell.points[7].location[2], origin[2])
 */
    }

    /* "discretize/_extensions/tree_ext.pyx":6529
 *                 z1p = max(cell.points[7].location[2], origin[2])
 *             # then need to find overlapping cells of TensorMesh...
 *             ix1 = max(_bisect_left(nodes_x, x1m) - 1, 0)             # <<<<<<<<<<<<<<
 *             ix2 = min(_bisect_right(nodes_x, x1p), nx)
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)
 */
    __Pyx_TraceLine(6529,0,__PYX_ERR(0, 6529, __pyx_L1_error))
    __pyx_t_27 = 0;
    __pyx_t_28 = (__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_left(__pyx_v_nodes_x, __pyx_v_x1m) - 1);
    if (((__pyx_t_27 > __pyx_t_28) != 0)) {
      __pyx_t_29 = __pyx_t_27;
    } else {
      __pyx_t_29 = __pyx_t_28;
    }
    __pyx_v_ix1 = __pyx_t_29;

    /* "discretize/_extensions/tree_ext.pyx":6530
 *             # then need to find overlapping cells of TensorMesh...
 *             ix1 = max(_bisect_left(nodes_x, x1m) - 1, 0)
 *             ix2 = min(_bisect_right(nodes_x, x1p), nx)             # <<<<<<<<<<<<<<
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)
 */
    __Pyx_TraceLine(6530,0,__PYX_ERR(0, 6530, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_nx;
    __pyx_t_29 = __pyx_f_10discretize_11_extensions_18interputils_cython__bisect_right(__pyx_v_nodes_x, __pyx_v_x1p);
    if (((__pyx_t_6 < __pyx_t_29) != 0)) {
      __pyx_t_28 = __pyx_t_6;
    } else {
      __pyx_t_28 = __pyx_t_29;
    }
    __pyx_v_ix2 = __pyx_t_28;

    /* "discretize/_extensions/tree_ext.pyx":6531
 *             ix1 = max(_bisect_left(nodes_x, x1m) - 1, 0)
 *             ix2 = min(_bisect_right(nodes_x, x1p), nx)
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)             # <<<<<<<<<<<<<<
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)
 *             if self._dim==3:
 */
    __Pyx_TraceLine(6531,0,__PYX_ERR(0, 6531, __pyx_L1_error))
    __pyx_t_27 = 0;
    __pyx_t_28 = (__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_left(__pyx_v_nodes_y, __pyx_v_y1m) - 1);
    if (((__pyx_t_27 > __pyx_t_28) != 0)) {
      __pyx_t_29 = __pyx_t_27;
    } else {
      __pyx_t_29 = __pyx_t_28;
    }
    __pyx_v_iy1 = __pyx_t_29;

    /* "discretize/_extensions/tree_ext.pyx":6532
 *             ix2 = min(_bisect_right(nodes_x, x1p), nx)
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)             # <<<<<<<<<<<<<<
 *             if self._dim==3:
 *                 iz1 = max(_bisect_left(nodes_z, z1m) - 1, 0)
 */
    __Pyx_TraceLine(6532,0,__PYX_ERR(0, 6532, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_ny;
    __pyx_t_29 = __pyx_f_10discretize_11_extensions_18interputils_cython__bisect_right(__pyx_v_nodes_y, __pyx_v_y1p);
    if (((__pyx_t_6 < __pyx_t_29) != 0)) {
      __pyx_t_28 = __pyx_t_6;
    } else {
      __pyx_t_28 = __pyx_t_29;
    }
    __pyx_v_iy2 = __pyx_t_28;

    /* "discretize/_extensions/tree_ext.pyx":6533
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 iz1 = max(_bisect_left(nodes_z, z1m) - 1, 0)
 *                 iz2 = min(_bisect_right(nodes_z, z1p), nz)
 */
    __Pyx_TraceLine(6533,0,__PYX_ERR(0, 6533, __pyx_L1_error))
    __pyx_t_13 = ((__pyx_v_self->_dim == 3) != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":6534
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)
 *             if self._dim==3:
 *                 iz1 = max(_bisect_left(nodes_z, z1m) - 1, 0)             # <<<<<<<<<<<<<<
 *                 iz2 = min(_bisect_right(nodes_z, z1p), nz)
 *             else:
 */
      __Pyx_TraceLine(6534,0,__PYX_ERR(0, 6534, __pyx_L1_error))
      __pyx_t_27 = 0;
      __pyx_t_28 = (__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_left(__pyx_v_nodes_z, __pyx_v_z1m) - 1);
      if (((__pyx_t_27 > __pyx_t_28) != 0)) {
        __pyx_t_29 = __pyx_t_27;
      } else {
        __pyx_t_29 = __pyx_t_28;
      }
      __pyx_v_iz1 = __pyx_t_29;

      /* "discretize/_extensions/tree_ext.pyx":6535
 *             if self._dim==3:
 *                 iz1 = max(_bisect_left(nodes_z, z1m) - 1, 0)
 *                 iz2 = min(_bisect_right(nodes_z, z1p), nz)             # <<<<<<<<<<<<<<
 *             else:
 *                 iz1 = 0
 */
      __Pyx_TraceLine(6535,0,__PYX_ERR(0, 6535, __pyx_L1_error))
      __pyx_t_6 = __pyx_v_nz;
      __pyx_t_29 = __pyx_f_10discretize_11_extensions_18interputils_cython__bisect_right(__pyx_v_nodes_z, __pyx_v_z1p);
      if (((__pyx_t_6 < __pyx_t_29) != 0)) {
        __pyx_t_28 = __pyx_t_6;
      } else {
        __pyx_t_28 = __pyx_t_29;
      }
      __pyx_v_iz2 = __pyx_t_28;

      /* "discretize/_extensions/tree_ext.pyx":6533
 *             iy1 = max(_bisect_left(nodes_y, y1m) - 1, 0)
 *             iy2 = min(_bisect_right(nodes_y, y1p), ny)
 *             if self._dim==3:             # <<<<<<<<<<<<<<
 *                 iz1 = max(_bisect_left(nodes_z, z1m) - 1, 0)
 *                 iz2 = min(_bisect_right(nodes_z, z1p), nz)
 */
      goto __pyx_L25;
    }

    /* "discretize/_extensions/tree_ext.pyx":6537
 *                 iz2 = min(_bisect_right(nodes_z, z1p), nz)
 *             else:
 *                 iz1 = 0             # <<<<<<<<<<<<<<
 *                 iz2 = 1
 *             nx_overlap = ix2-ix1
 */
    __Pyx_TraceLine(6537,0,__PYX_ERR(0, 6537, __pyx_L1_error))
    /*else*/ {
      __pyx_v_iz1 = 0;

      /* "discretize/_extensions/tree_ext.pyx":6538
 *             else:
 *                 iz1 = 0
 *                 iz2 = 1             # <<<<<<<<<<<<<<
 *             nx_overlap = ix2-ix1
 *             ny_overlap = iy2-iy1
 */
      __Pyx_TraceLine(6538,0,__PYX_ERR(0, 6538, __pyx_L1_error))
      __pyx_v_iz2 = 1;
    }
    __pyx_L25:;

    /* "discretize/_extensions/tree_ext.pyx":6539
 *                 iz1 = 0
 *                 iz2 = 1
 *             nx_overlap = ix2-ix1             # <<<<<<<<<<<<<<
 *             ny_overlap = iy2-iy1
 *             nz_overlap = iz2-iz1
 */
    __Pyx_TraceLine(6539,0,__PYX_ERR(0, 6539, __pyx_L1_error))
    __pyx_v_nx_overlap = (__pyx_v_ix2 - __pyx_v_ix1);

    /* "discretize/_extensions/tree_ext.pyx":6540
 *                 iz2 = 1
 *             nx_overlap = ix2-ix1
 *             ny_overlap = iy2-iy1             # <<<<<<<<<<<<<<
 *             nz_overlap = iz2-iz1
 *             n_overlap = nx_overlap*ny_overlap*nz_overlap
 */
    __Pyx_TraceLine(6540,0,__PYX_ERR(0, 6540, __pyx_L1_error))
    __pyx_v_ny_overlap = (__pyx_v_iy2 - __pyx_v_iy1);

    /* "discretize/_extensions/tree_ext.pyx":6541
 *             nx_overlap = ix2-ix1
 *             ny_overlap = iy2-iy1
 *             nz_overlap = iz2-iz1             # <<<<<<<<<<<<<<
 *             n_overlap = nx_overlap*ny_overlap*nz_overlap
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 */
    __Pyx_TraceLine(6541,0,__PYX_ERR(0, 6541, __pyx_L1_error))
    __pyx_v_nz_overlap = (__pyx_v_iz2 - __pyx_v_iz1);

    /* "discretize/_extensions/tree_ext.pyx":6542
 *             ny_overlap = iy2-iy1
 *             nz_overlap = iz2-iz1
 *             n_overlap = nx_overlap*ny_overlap*nz_overlap             # <<<<<<<<<<<<<<
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 * 
 */
    __Pyx_TraceLine(6542,0,__PYX_ERR(0, 6542, __pyx_L1_error))
    __pyx_v_n_overlap = ((__pyx_v_nx_overlap * __pyx_v_ny_overlap) * __pyx_v_nz_overlap);

    /* "discretize/_extensions/tree_ext.pyx":6543
 *             nz_overlap = iz2-iz1
 *             n_overlap = nx_overlap*ny_overlap*nz_overlap
 *             weights = <double *> malloc(n_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 * 
 *             dx = <double *> malloc(nx_overlap*sizeof(double))
 */
    __Pyx_TraceLine(6543,0,__PYX_ERR(0, 6543, __pyx_L1_error))
    __pyx_v_weights = ((double *)malloc((__pyx_v_n_overlap * (sizeof(double)))));

    /* "discretize/_extensions/tree_ext.pyx":6545
 *             weights = <double *> malloc(n_overlap*sizeof(double))
 * 
 *             dx = <double *> malloc(nx_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 *             for ix in range(ix1, ix2):
 *                 x2m = nodes_x[ix]
 */
    __Pyx_TraceLine(6545,0,__PYX_ERR(0, 6545, __pyx_L1_error))
    __pyx_v_dx = ((double *)malloc((__pyx_v_nx_overlap * (sizeof(double)))));

    /* "discretize/_extensions/tree_ext.pyx":6546
 * 
 *             dx = <double *> malloc(nx_overlap*sizeof(double))
 *             for ix in range(ix1, ix2):             # <<<<<<<<<<<<<<
 *                 x2m = nodes_x[ix]
 *                 x2p = nodes_x[ix+1]
 */
    __Pyx_TraceLine(6546,0,__PYX_ERR(0, 6546, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_ix2;
    __pyx_t_14 = __pyx_t_6;
    for (__pyx_t_30 = __pyx_v_ix1; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
      __pyx_v_ix = __pyx_t_30;

      /* "discretize/_extensions/tree_ext.pyx":6547
 *             dx = <double *> malloc(nx_overlap*sizeof(double))
 *             for ix in range(ix1, ix2):
 *                 x2m = nodes_x[ix]             # <<<<<<<<<<<<<<
 *                 x2p = nodes_x[ix+1]
 *                 if x1m == xF[0] or x1p == origin[0]:
 */
      __Pyx_TraceLine(6547,0,__PYX_ERR(0, 6547, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_ix;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_x.shape[0];
      __pyx_v_x2m = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_18 * __pyx_v_nodes_x.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6548
 *             for ix in range(ix1, ix2):
 *                 x2m = nodes_x[ix]
 *                 x2p = nodes_x[ix+1]             # <<<<<<<<<<<<<<
 *                 if x1m == xF[0] or x1p == origin[0]:
 *                     dx[ix-ix1] = 1.0
 */
      __Pyx_TraceLine(6548,0,__PYX_ERR(0, 6548, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_ix + 1);
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_x.shape[0];
      __pyx_v_x2p = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_x.data + __pyx_t_18 * __pyx_v_nodes_x.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6549
 *                 x2m = nodes_x[ix]
 *                 x2p = nodes_x[ix+1]
 *                 if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                     dx[ix-ix1] = 1.0
 *                 else:
 */
      __Pyx_TraceLine(6549,0,__PYX_ERR(0, 6549, __pyx_L1_error))
      __pyx_t_18 = 0;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
      __pyx_t_15 = ((__pyx_v_x1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )))) != 0);
      if (!__pyx_t_15) {
      } else {
        __pyx_t_13 = __pyx_t_15;
        goto __pyx_L29_bool_binop_done;
      }
      __pyx_t_18 = 0;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
      __pyx_t_15 = ((__pyx_v_x1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )))) != 0);
      __pyx_t_13 = __pyx_t_15;
      __pyx_L29_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":6550
 *                 x2p = nodes_x[ix+1]
 *                 if x1m == xF[0] or x1p == origin[0]:
 *                     dx[ix-ix1] = 1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     dx[ix-ix1] = min(x1p, x2p) - max(x1m, x2m)
 */
        __Pyx_TraceLine(6550,0,__PYX_ERR(0, 6550, __pyx_L1_error))
        (__pyx_v_dx[(__pyx_v_ix - __pyx_v_ix1)]) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":6549
 *                 x2m = nodes_x[ix]
 *                 x2p = nodes_x[ix+1]
 *                 if x1m == xF[0] or x1p == origin[0]:             # <<<<<<<<<<<<<<
 *                     dx[ix-ix1] = 1.0
 *                 else:
 */
        goto __pyx_L28;
      }

      /* "discretize/_extensions/tree_ext.pyx":6552
 *                     dx[ix-ix1] = 1.0
 *                 else:
 *                     dx[ix-ix1] = min(x1p, x2p) - max(x1m, x2m)             # <<<<<<<<<<<<<<
 * 
 *             dy = <double *> malloc(ny_overlap*sizeof(double))
 */
      __Pyx_TraceLine(6552,0,__PYX_ERR(0, 6552, __pyx_L1_error))
      /*else*/ {
        __pyx_t_24 = __pyx_v_x2p;
        __pyx_t_25 = __pyx_v_x1p;
        if (((__pyx_t_24 < __pyx_t_25) != 0)) {
          __pyx_t_26 = __pyx_t_24;
        } else {
          __pyx_t_26 = __pyx_t_25;
        }
        __pyx_t_24 = __pyx_v_x2m;
        __pyx_t_25 = __pyx_v_x1m;
        if (((__pyx_t_24 > __pyx_t_25) != 0)) {
          __pyx_t_31 = __pyx_t_24;
        } else {
          __pyx_t_31 = __pyx_t_25;
        }
        (__pyx_v_dx[(__pyx_v_ix - __pyx_v_ix1)]) = (__pyx_t_26 - __pyx_t_31);
      }
      __pyx_L28:;
    }

    /* "discretize/_extensions/tree_ext.pyx":6554
 *                     dx[ix-ix1] = min(x1p, x2p) - max(x1m, x2m)
 * 
 *             dy = <double *> malloc(ny_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 *             for iy in range(iy1, iy2):
 *                 y2m = nodes_y[iy]
 */
    __Pyx_TraceLine(6554,0,__PYX_ERR(0, 6554, __pyx_L1_error))
    __pyx_v_dy = ((double *)malloc((__pyx_v_ny_overlap * (sizeof(double)))));

    /* "discretize/_extensions/tree_ext.pyx":6555
 * 
 *             dy = <double *> malloc(ny_overlap*sizeof(double))
 *             for iy in range(iy1, iy2):             # <<<<<<<<<<<<<<
 *                 y2m = nodes_y[iy]
 *                 y2p = nodes_y[iy+1]
 */
    __Pyx_TraceLine(6555,0,__PYX_ERR(0, 6555, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_iy2;
    __pyx_t_14 = __pyx_t_6;
    for (__pyx_t_30 = __pyx_v_iy1; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
      __pyx_v_iy = __pyx_t_30;

      /* "discretize/_extensions/tree_ext.pyx":6556
 *             dy = <double *> malloc(ny_overlap*sizeof(double))
 *             for iy in range(iy1, iy2):
 *                 y2m = nodes_y[iy]             # <<<<<<<<<<<<<<
 *                 y2p = nodes_y[iy+1]
 *                 if y1m == xF[1] or y1p == origin[1]:
 */
      __Pyx_TraceLine(6556,0,__PYX_ERR(0, 6556, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_iy;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_y.shape[0];
      __pyx_v_y2m = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_18 * __pyx_v_nodes_y.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6557
 *             for iy in range(iy1, iy2):
 *                 y2m = nodes_y[iy]
 *                 y2p = nodes_y[iy+1]             # <<<<<<<<<<<<<<
 *                 if y1m == xF[1] or y1p == origin[1]:
 *                     dy[iy-iy1] = 1.0
 */
      __Pyx_TraceLine(6557,0,__PYX_ERR(0, 6557, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_iy + 1);
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_y.shape[0];
      __pyx_v_y2p = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_y.data + __pyx_t_18 * __pyx_v_nodes_y.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6558
 *                 y2m = nodes_y[iy]
 *                 y2p = nodes_y[iy+1]
 *                 if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                     dy[iy-iy1] = 1.0
 *                 else:
 */
      __Pyx_TraceLine(6558,0,__PYX_ERR(0, 6558, __pyx_L1_error))
      __pyx_t_18 = 1;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
      __pyx_t_15 = ((__pyx_v_y1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )))) != 0);
      if (!__pyx_t_15) {
      } else {
        __pyx_t_13 = __pyx_t_15;
        goto __pyx_L34_bool_binop_done;
      }
      __pyx_t_18 = 1;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
      __pyx_t_15 = ((__pyx_v_y1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )))) != 0);
      __pyx_t_13 = __pyx_t_15;
      __pyx_L34_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":6559
 *                 y2p = nodes_y[iy+1]
 *                 if y1m == xF[1] or y1p == origin[1]:
 *                     dy[iy-iy1] = 1.0             # <<<<<<<<<<<<<<
 *                 else:
 *                     dy[iy-iy1] = min(y1p, y2p) - max(y1m, y2m)
 */
        __Pyx_TraceLine(6559,0,__PYX_ERR(0, 6559, __pyx_L1_error))
        (__pyx_v_dy[(__pyx_v_iy - __pyx_v_iy1)]) = 1.0;

        /* "discretize/_extensions/tree_ext.pyx":6558
 *                 y2m = nodes_y[iy]
 *                 y2p = nodes_y[iy+1]
 *                 if y1m == xF[1] or y1p == origin[1]:             # <<<<<<<<<<<<<<
 *                     dy[iy-iy1] = 1.0
 *                 else:
 */
        goto __pyx_L33;
      }

      /* "discretize/_extensions/tree_ext.pyx":6561
 *                     dy[iy-iy1] = 1.0
 *                 else:
 *                     dy[iy-iy1] = min(y1p, y2p) - max(y1m, y2m)             # <<<<<<<<<<<<<<
 * 
 *             dz = <double *> malloc(nz_overlap*sizeof(double))
 */
      __Pyx_TraceLine(6561,0,__PYX_ERR(0, 6561, __pyx_L1_error))
      /*else*/ {
        __pyx_t_31 = __pyx_v_y2p;
        __pyx_t_26 = __pyx_v_y1p;
        if (((__pyx_t_31 < __pyx_t_26) != 0)) {
          __pyx_t_24 = __pyx_t_31;
        } else {
          __pyx_t_24 = __pyx_t_26;
        }
        __pyx_t_31 = __pyx_v_y2m;
        __pyx_t_26 = __pyx_v_y1m;
        if (((__pyx_t_31 > __pyx_t_26) != 0)) {
          __pyx_t_25 = __pyx_t_31;
        } else {
          __pyx_t_25 = __pyx_t_26;
        }
        (__pyx_v_dy[(__pyx_v_iy - __pyx_v_iy1)]) = (__pyx_t_24 - __pyx_t_25);
      }
      __pyx_L33:;
    }

    /* "discretize/_extensions/tree_ext.pyx":6563
 *                     dy[iy-iy1] = min(y1p, y2p) - max(y1m, y2m)
 * 
 *             dz = <double *> malloc(nz_overlap*sizeof(double))             # <<<<<<<<<<<<<<
 *             for iz in range(iz1, iz2):
 *                 z2m = nodes_z[iz]
 */
    __Pyx_TraceLine(6563,0,__PYX_ERR(0, 6563, __pyx_L1_error))
    __pyx_v_dz = ((double *)malloc((__pyx_v_nz_overlap * (sizeof(double)))));

    /* "discretize/_extensions/tree_ext.pyx":6564
 * 
 *             dz = <double *> malloc(nz_overlap*sizeof(double))
 *             for iz in range(iz1, iz2):             # <<<<<<<<<<<<<<
 *                 z2m = nodes_z[iz]
 *                 z2p = nodes_z[iz+1]
 */
    __Pyx_TraceLine(6564,0,__PYX_ERR(0, 6564, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_iz2;
    __pyx_t_14 = __pyx_t_6;
    for (__pyx_t_30 = __pyx_v_iz1; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
      __pyx_v_iz = __pyx_t_30;

      /* "discretize/_extensions/tree_ext.pyx":6565
 *             dz = <double *> malloc(nz_overlap*sizeof(double))
 *             for iz in range(iz1, iz2):
 *                 z2m = nodes_z[iz]             # <<<<<<<<<<<<<<
 *                 z2p = nodes_z[iz+1]
 *                 if self._dim==3:
 */
      __Pyx_TraceLine(6565,0,__PYX_ERR(0, 6565, __pyx_L1_error))
      __pyx_t_18 = __pyx_v_iz;
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_z.shape[0];
      __pyx_v_z2m = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_z.data + __pyx_t_18 * __pyx_v_nodes_z.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6566
 *             for iz in range(iz1, iz2):
 *                 z2m = nodes_z[iz]
 *                 z2p = nodes_z[iz+1]             # <<<<<<<<<<<<<<
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:
 */
      __Pyx_TraceLine(6566,0,__PYX_ERR(0, 6566, __pyx_L1_error))
      __pyx_t_18 = (__pyx_v_iz + 1);
      if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_nodes_z.shape[0];
      __pyx_v_z2p = (*((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_nodes_z.data + __pyx_t_18 * __pyx_v_nodes_z.strides[0]) )));

      /* "discretize/_extensions/tree_ext.pyx":6567
 *                 z2m = nodes_z[iz]
 *                 z2p = nodes_z[iz+1]
 *                 if self._dim==3:             # <<<<<<<<<<<<<<
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         dz[iz-iz1] = 1.0
 */
      __Pyx_TraceLine(6567,0,__PYX_ERR(0, 6567, __pyx_L1_error))
      __pyx_t_13 = ((__pyx_v_self->_dim == 3) != 0);
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":6568
 *                 z2p = nodes_z[iz+1]
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                         dz[iz-iz1] = 1.0
 *                     else:
 */
        __Pyx_TraceLine(6568,0,__PYX_ERR(0, 6568, __pyx_L1_error))
        __pyx_t_18 = 2;
        if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_xF.shape[0];
        __pyx_t_15 = ((__pyx_v_z1m == (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_18 * __pyx_v_xF.strides[0]) )))) != 0);
        if (!__pyx_t_15) {
        } else {
          __pyx_t_13 = __pyx_t_15;
          goto __pyx_L40_bool_binop_done;
        }
        __pyx_t_18 = 2;
        if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_origin.shape[0];
        __pyx_t_15 = ((__pyx_v_z1p == (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_18 * __pyx_v_origin.strides[0]) )))) != 0);
        __pyx_t_13 = __pyx_t_15;
        __pyx_L40_bool_binop_done:;
        if (__pyx_t_13) {

          /* "discretize/_extensions/tree_ext.pyx":6569
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         dz[iz-iz1] = 1.0             # <<<<<<<<<<<<<<
 *                     else:
 *                         dz[iz-iz1] = min(z1p, z2p) - max(z1m, z2m)
 */
          __Pyx_TraceLine(6569,0,__PYX_ERR(0, 6569, __pyx_L1_error))
          (__pyx_v_dz[(__pyx_v_iz - __pyx_v_iz1)]) = 1.0;

          /* "discretize/_extensions/tree_ext.pyx":6568
 *                 z2p = nodes_z[iz+1]
 *                 if self._dim==3:
 *                     if z1m == xF[2] or z1p == origin[2]:             # <<<<<<<<<<<<<<
 *                         dz[iz-iz1] = 1.0
 *                     else:
 */
          goto __pyx_L39;
        }

        /* "discretize/_extensions/tree_ext.pyx":6571
 *                         dz[iz-iz1] = 1.0
 *                     else:
 *                         dz[iz-iz1] = min(z1p, z2p) - max(z1m, z2m)             # <<<<<<<<<<<<<<
 *                 else:
 *                     dz[iz-iz1] = 1.0
 */
        __Pyx_TraceLine(6571,0,__PYX_ERR(0, 6571, __pyx_L1_error))
        /*else*/ {
          __pyx_t_25 = __pyx_v_z2p;
          __pyx_t_24 = __pyx_v_z1p;
          if (((__pyx_t_25 < __pyx_t_24) != 0)) {
            __pyx_t_31 = __pyx_t_25;
          } else {
            __pyx_t_31 = __pyx_t_24;
          }
          __pyx_t_25 = __pyx_v_z2m;
          __pyx_t_24 = __pyx_v_z1m;
          if (((__pyx_t_25 > __pyx_t_24) != 0)) {
            __pyx_t_26 = __pyx_t_25;
          } else {
            __pyx_t_26 = __pyx_t_24;
          }
          (__pyx_v_dz[(__pyx_v_iz - __pyx_v_iz1)]) = (__pyx_t_31 - __pyx_t_26);
        }
        __pyx_L39:;

        /* "discretize/_extensions/tree_ext.pyx":6567
 *                 z2m = nodes_z[iz]
 *                 z2p = nodes_z[iz+1]
 *                 if self._dim==3:             # <<<<<<<<<<<<<<
 *                     if z1m == xF[2] or z1p == origin[2]:
 *                         dz[iz-iz1] = 1.0
 */
        goto __pyx_L38;
      }

      /* "discretize/_extensions/tree_ext.pyx":6573
 *                         dz[iz-iz1] = min(z1p, z2p) - max(z1m, z2m)
 *                 else:
 *                     dz[iz-iz1] = 1.0             # <<<<<<<<<<<<<<
 * 
 *             i = 0
 */
      __Pyx_TraceLine(6573,0,__PYX_ERR(0, 6573, __pyx_L1_error))
      /*else*/ {
        (__pyx_v_dz[(__pyx_v_iz - __pyx_v_iz1)]) = 1.0;
      }
      __pyx_L38:;
    }

    /* "discretize/_extensions/tree_ext.pyx":6575
 *                     dz[iz-iz1] = 1.0
 * 
 *             i = 0             # <<<<<<<<<<<<<<
 *             weight_sum = 0.0
 *             nnz_row = 0
 */
    __Pyx_TraceLine(6575,0,__PYX_ERR(0, 6575, __pyx_L1_error))
    __pyx_v_i = 0;

    /* "discretize/_extensions/tree_ext.pyx":6576
 * 
 *             i = 0
 *             weight_sum = 0.0             # <<<<<<<<<<<<<<
 *             nnz_row = 0
 *             for iz in range(iz1, iz2):
 */
    __Pyx_TraceLine(6576,0,__PYX_ERR(0, 6576, __pyx_L1_error))
    __pyx_v_weight_sum = 0.0;

    /* "discretize/_extensions/tree_ext.pyx":6577
 *             i = 0
 *             weight_sum = 0.0
 *             nnz_row = 0             # <<<<<<<<<<<<<<
 *             for iz in range(iz1, iz2):
 *                 for iy in range(iy1, iy2):
 */
    __Pyx_TraceLine(6577,0,__PYX_ERR(0, 6577, __pyx_L1_error))
    __pyx_v_nnz_row = 0;

    /* "discretize/_extensions/tree_ext.pyx":6578
 *             weight_sum = 0.0
 *             nnz_row = 0
 *             for iz in range(iz1, iz2):             # <<<<<<<<<<<<<<
 *                 for iy in range(iy1, iy2):
 *                     for ix in range(ix1, ix2):
 */
    __Pyx_TraceLine(6578,0,__PYX_ERR(0, 6578, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_iz2;
    __pyx_t_14 = __pyx_t_6;
    for (__pyx_t_30 = __pyx_v_iz1; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
      __pyx_v_iz = __pyx_t_30;

      /* "discretize/_extensions/tree_ext.pyx":6579
 *             nnz_row = 0
 *             for iz in range(iz1, iz2):
 *                 for iy in range(iy1, iy2):             # <<<<<<<<<<<<<<
 *                     for ix in range(ix1, ix2):
 *                         in_cell_ind = ix + (iy + iz*ny)*nx
 */
      __Pyx_TraceLine(6579,0,__PYX_ERR(0, 6579, __pyx_L1_error))
      __pyx_t_32 = __pyx_v_iy2;
      __pyx_t_33 = __pyx_t_32;
      for (__pyx_t_34 = __pyx_v_iy1; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) {
        __pyx_v_iy = __pyx_t_34;

        /* "discretize/_extensions/tree_ext.pyx":6580
 *             for iz in range(iz1, iz2):
 *                 for iy in range(iy1, iy2):
 *                     for ix in range(ix1, ix2):             # <<<<<<<<<<<<<<
 *                         in_cell_ind = ix + (iy + iz*ny)*nx
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]
 */
        __Pyx_TraceLine(6580,0,__PYX_ERR(0, 6580, __pyx_L1_error))
        __pyx_t_35 = __pyx_v_ix2;
        __pyx_t_36 = __pyx_t_35;
        for (__pyx_t_37 = __pyx_v_ix1; __pyx_t_37 < __pyx_t_36; __pyx_t_37+=1) {
          __pyx_v_ix = __pyx_t_37;

          /* "discretize/_extensions/tree_ext.pyx":6581
 *                 for iy in range(iy1, iy2):
 *                     for ix in range(ix1, ix2):
 *                         in_cell_ind = ix + (iy + iz*ny)*nx             # <<<<<<<<<<<<<<
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]
 *                         if build_mat and weights[i] != 0.0:
 */
          __Pyx_TraceLine(6581,0,__PYX_ERR(0, 6581, __pyx_L1_error))
          __pyx_v_in_cell_ind = (__pyx_v_ix + ((__pyx_v_iy + (__pyx_v_iz * __pyx_v_ny)) * __pyx_v_nx));

          /* "discretize/_extensions/tree_ext.pyx":6582
 *                     for ix in range(ix1, ix2):
 *                         in_cell_ind = ix + (iy + iz*ny)*nx
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]             # <<<<<<<<<<<<<<
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1
 */
          __Pyx_TraceLine(6582,0,__PYX_ERR(0, 6582, __pyx_L1_error))
          (__pyx_v_weights[__pyx_v_i]) = (((__pyx_v_dx[(__pyx_v_ix - __pyx_v_ix1)]) * (__pyx_v_dy[(__pyx_v_iy - __pyx_v_iy1)])) * (__pyx_v_dz[(__pyx_v_iz - __pyx_v_iz1)]));

          /* "discretize/_extensions/tree_ext.pyx":6583
 *                         in_cell_ind = ix + (iy + iz*ny)*nx
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)
 */
          __Pyx_TraceLine(6583,0,__PYX_ERR(0, 6583, __pyx_L1_error))
          __pyx_t_15 = (__pyx_v_build_mat != 0);
          if (__pyx_t_15) {
          } else {
            __pyx_t_13 = __pyx_t_15;
            goto __pyx_L49_bool_binop_done;
          }
          __pyx_t_15 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
          __pyx_t_13 = __pyx_t_15;
          __pyx_L49_bool_binop_done:;
          if (__pyx_t_13) {

            /* "discretize/_extensions/tree_ext.pyx":6584
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1             # <<<<<<<<<<<<<<
 *                             row_inds.push_back(in_cell_ind)
 * 
 */
            __Pyx_TraceLine(6584,0,__PYX_ERR(0, 6584, __pyx_L1_error))
            __pyx_v_nnz_row = (__pyx_v_nnz_row + 1);

            /* "discretize/_extensions/tree_ext.pyx":6585
 *                         if build_mat and weights[i] != 0.0:
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)             # <<<<<<<<<<<<<<
 * 
 *                         weight_sum += weights[i]
 */
            __Pyx_TraceLine(6585,0,__PYX_ERR(0, 6585, __pyx_L1_error))
            try {
              __pyx_v_row_inds.push_back(__pyx_v_in_cell_ind);
            } catch(...) {
              __Pyx_CppExn2PyErr();
              __PYX_ERR(0, 6585, __pyx_L1_error)
            }

            /* "discretize/_extensions/tree_ext.pyx":6583
 *                         in_cell_ind = ix + (iy + iz*ny)*nx
 *                         weights[i] = dx[ix-ix1]*dy[iy-iy1]*dz[iz-iz1]
 *                         if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                             nnz_row += 1
 *                             row_inds.push_back(in_cell_ind)
 */
          }

          /* "discretize/_extensions/tree_ext.pyx":6587
 *                             row_inds.push_back(in_cell_ind)
 * 
 *                         weight_sum += weights[i]             # <<<<<<<<<<<<<<
 *                         i += 1
 * 
 */
          __Pyx_TraceLine(6587,0,__PYX_ERR(0, 6587, __pyx_L1_error))
          __pyx_v_weight_sum = (__pyx_v_weight_sum + (__pyx_v_weights[__pyx_v_i]));

          /* "discretize/_extensions/tree_ext.pyx":6588
 * 
 *                         weight_sum += weights[i]
 *                         i += 1             # <<<<<<<<<<<<<<
 * 
 *             for i in range(n_overlap):
 */
          __Pyx_TraceLine(6588,0,__PYX_ERR(0, 6588, __pyx_L1_error))
          __pyx_v_i = (__pyx_v_i + 1);
        }
      }
    }

    /* "discretize/_extensions/tree_ext.pyx":6590
 *                         i += 1
 * 
 *             for i in range(n_overlap):             # <<<<<<<<<<<<<<
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:
 */
    __Pyx_TraceLine(6590,0,__PYX_ERR(0, 6590, __pyx_L1_error))
    __pyx_t_6 = __pyx_v_n_overlap;
    __pyx_t_14 = __pyx_t_6;
    for (__pyx_t_30 = 0; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
      __pyx_v_i = __pyx_t_30;

      /* "discretize/_extensions/tree_ext.pyx":6591
 * 
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum             # <<<<<<<<<<<<<<
 *                 if build_mat and weights[i] != 0.0:
 *                     all_weights.push_back(weights[i])
 */
      __Pyx_TraceLine(6591,0,__PYX_ERR(0, 6591, __pyx_L1_error))
      __pyx_t_32 = __pyx_v_i;
      (__pyx_v_weights[__pyx_t_32]) = ((__pyx_v_weights[__pyx_t_32]) / __pyx_v_weight_sum);

      /* "discretize/_extensions/tree_ext.pyx":6592
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     all_weights.push_back(weights[i])
 * 
 */
      __Pyx_TraceLine(6592,0,__PYX_ERR(0, 6592, __pyx_L1_error))
      __pyx_t_15 = (__pyx_v_build_mat != 0);
      if (__pyx_t_15) {
      } else {
        __pyx_t_13 = __pyx_t_15;
        goto __pyx_L54_bool_binop_done;
      }
      __pyx_t_15 = (((__pyx_v_weights[__pyx_v_i]) != 0.0) != 0);
      __pyx_t_13 = __pyx_t_15;
      __pyx_L54_bool_binop_done:;
      if (__pyx_t_13) {

        /* "discretize/_extensions/tree_ext.pyx":6593
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:
 *                     all_weights.push_back(weights[i])             # <<<<<<<<<<<<<<
 * 
 *             if not build_mat:
 */
        __Pyx_TraceLine(6593,0,__PYX_ERR(0, 6593, __pyx_L1_error))
        try {
          __pyx_v_all_weights.push_back((__pyx_v_weights[__pyx_v_i]));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 6593, __pyx_L1_error)
        }

        /* "discretize/_extensions/tree_ext.pyx":6592
 *             for i in range(n_overlap):
 *                 weights[i] /= weight_sum
 *                 if build_mat and weights[i] != 0.0:             # <<<<<<<<<<<<<<
 *                     all_weights.push_back(weights[i])
 * 
 */
      }
    }

    /* "discretize/_extensions/tree_ext.pyx":6595
 *                     all_weights.push_back(weights[i])
 * 
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 i = 0
 *                 for iz in range(iz1, iz2):
 */
    __Pyx_TraceLine(6595,0,__PYX_ERR(0, 6595, __pyx_L1_error))
    __pyx_t_13 = ((!(__pyx_v_build_mat != 0)) != 0);
    if (__pyx_t_13) {

      /* "discretize/_extensions/tree_ext.pyx":6596
 * 
 *             if not build_mat:
 *                 i = 0             # <<<<<<<<<<<<<<
 *                 for iz in range(iz1, iz2):
 *                     for iy in range(iy1, iy2):
 */
      __Pyx_TraceLine(6596,0,__PYX_ERR(0, 6596, __pyx_L1_error))
      __pyx_v_i = 0;

      /* "discretize/_extensions/tree_ext.pyx":6597
 *             if not build_mat:
 *                 i = 0
 *                 for iz in range(iz1, iz2):             # <<<<<<<<<<<<<<
 *                     for iy in range(iy1, iy2):
 *                         for ix in range(ix1, ix2):
 */
      __Pyx_TraceLine(6597,0,__PYX_ERR(0, 6597, __pyx_L1_error))
      __pyx_t_6 = __pyx_v_iz2;
      __pyx_t_14 = __pyx_t_6;
      for (__pyx_t_30 = __pyx_v_iz1; __pyx_t_30 < __pyx_t_14; __pyx_t_30+=1) {
        __pyx_v_iz = __pyx_t_30;

        /* "discretize/_extensions/tree_ext.pyx":6598
 *                 i = 0
 *                 for iz in range(iz1, iz2):
 *                     for iy in range(iy1, iy2):             # <<<<<<<<<<<<<<
 *                         for ix in range(ix1, ix2):
 *                             outs[cell.index] += vals[ix, iy, iz]*weights[i]
 */
        __Pyx_TraceLine(6598,0,__PYX_ERR(0, 6598, __pyx_L1_error))
        __pyx_t_32 = __pyx_v_iy2;
        __pyx_t_33 = __pyx_t_32;
        for (__pyx_t_34 = __pyx_v_iy1; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) {
          __pyx_v_iy = __pyx_t_34;

          /* "discretize/_extensions/tree_ext.pyx":6599
 *                 for iz in range(iz1, iz2):
 *                     for iy in range(iy1, iy2):
 *                         for ix in range(ix1, ix2):             # <<<<<<<<<<<<<<
 *                             outs[cell.index] += vals[ix, iy, iz]*weights[i]
 *                             i += 1
 */
          __Pyx_TraceLine(6599,0,__PYX_ERR(0, 6599, __pyx_L1_error))
          __pyx_t_35 = __pyx_v_ix2;
          __pyx_t_36 = __pyx_t_35;
          for (__pyx_t_37 = __pyx_v_ix1; __pyx_t_37 < __pyx_t_36; __pyx_t_37+=1) {
            __pyx_v_ix = __pyx_t_37;

            /* "discretize/_extensions/tree_ext.pyx":6600
 *                     for iy in range(iy1, iy2):
 *                         for ix in range(ix1, ix2):
 *                             outs[cell.index] += vals[ix, iy, iz]*weights[i]             # <<<<<<<<<<<<<<
 *                             i += 1
 *             else:
 */
            __Pyx_TraceLine(6600,0,__PYX_ERR(0, 6600, __pyx_L1_error))
            __pyx_t_18 = __pyx_v_ix;
            __pyx_t_38 = __pyx_v_iy;
            __pyx_t_39 = __pyx_v_iz;
            if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_v_vals.shape[0];
            if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_v_vals.shape[1];
            if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_v_vals.shape[2];
            __pyx_t_40 = __pyx_v_cell->index;
            if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_v_outs.shape[0];
            *((__pyx_t_5numpy_float64_t *) ( /* dim=0 */ (__pyx_v_outs.data + __pyx_t_40 * __pyx_v_outs.strides[0]) )) += ((*((__pyx_t_5numpy_float64_t *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ ((char *) (((__pyx_t_5numpy_float64_t *) __pyx_v_vals.data) + __pyx_t_18)) ) + __pyx_t_38 * __pyx_v_vals.strides[1]) ) + __pyx_t_39 * __pyx_v_vals.strides[2]) ))) * (__pyx_v_weights[__pyx_v_i]));

            /* "discretize/_extensions/tree_ext.pyx":6601
 *                         for ix in range(ix1, ix2):
 *                             outs[cell.index] += vals[ix, iy, iz]*weights[i]
 *                             i += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 nnz_counter += nnz_row
 */
            __Pyx_TraceLine(6601,0,__PYX_ERR(0, 6601, __pyx_L1_error))
            __pyx_v_i = (__pyx_v_i + 1);
          }
        }
      }

      /* "discretize/_extensions/tree_ext.pyx":6595
 *                     all_weights.push_back(weights[i])
 * 
 *             if not build_mat:             # <<<<<<<<<<<<<<
 *                 i = 0
 *                 for iz in range(iz1, iz2):
 */
      goto __pyx_L56;
    }

    /* "discretize/_extensions/tree_ext.pyx":6603
 *                             i += 1
 *             else:
 *                 nnz_counter += nnz_row             # <<<<<<<<<<<<<<
 *                 indptr[cell.index+1] = nnz_counter
 * 
 */
    __Pyx_TraceLine(6603,0,__PYX_ERR(0, 6603, __pyx_L1_error))
    /*else*/ {
      __pyx_v_nnz_counter = (__pyx_v_nnz_counter + __pyx_v_nnz_row);

      /* "discretize/_extensions/tree_ext.pyx":6604
 *             else:
 *                 nnz_counter += nnz_row
 *                 indptr[cell.index+1] = nnz_counter             # <<<<<<<<<<<<<<
 * 
 *             free(weights)
 */
      __Pyx_TraceLine(6604,0,__PYX_ERR(0, 6604, __pyx_L1_error))
      __pyx_t_40 = (__pyx_v_cell->index + 1);
      if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_v_indptr.shape[0];
      *((__pyx_t_5numpy_int64_t *) ( /* dim=0 */ (__pyx_v_indptr.data + __pyx_t_40 * __pyx_v_indptr.strides[0]) )) = __pyx_v_nnz_counter;
    }
    __pyx_L56:;

    /* "discretize/_extensions/tree_ext.pyx":6606
 *                 indptr[cell.index+1] = nnz_counter
 * 
 *             free(weights)             # <<<<<<<<<<<<<<
 *             free(dx)
 *             free(dy)
 */
    __Pyx_TraceLine(6606,0,__PYX_ERR(0, 6606, __pyx_L1_error))
    free(__pyx_v_weights);

    /* "discretize/_extensions/tree_ext.pyx":6607
 * 
 *             free(weights)
 *             free(dx)             # <<<<<<<<<<<<<<
 *             free(dy)
 *             free(dz)
 */
    __Pyx_TraceLine(6607,0,__PYX_ERR(0, 6607, __pyx_L1_error))
    free(__pyx_v_dx);

    /* "discretize/_extensions/tree_ext.pyx":6608
 *             free(weights)
 *             free(dx)
 *             free(dy)             # <<<<<<<<<<<<<<
 *             free(dz)
 * 
 */
    __Pyx_TraceLine(6608,0,__PYX_ERR(0, 6608, __pyx_L1_error))
    free(__pyx_v_dy);

    /* "discretize/_extensions/tree_ext.pyx":6609
 *             free(dx)
 *             free(dy)
 *             free(dz)             # <<<<<<<<<<<<<<
 * 
 *         if not build_mat:
 */
    __Pyx_TraceLine(6609,0,__PYX_ERR(0, 6609, __pyx_L1_error))
    free(__pyx_v_dz);

    /* "discretize/_extensions/tree_ext.pyx":6519
 *         cdef double weight_sum
 * 
 *         for cell in self.tree.cells:             # <<<<<<<<<<<<<<
 *             x1m = min(cell.points[0].location[0], xF[0])
 *             y1m = min(cell.points[0].location[1], xF[1])
 */
    __Pyx_TraceLine(6519,0,__PYX_ERR(0, 6519, __pyx_L1_error))
  }

  /* "discretize/_extensions/tree_ext.pyx":6611
 *             free(dz)
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))
 */
  __Pyx_TraceLine(6611,0,__PYX_ERR(0, 6611, __pyx_L1_error))
  __pyx_t_13 = ((!(__pyx_v_build_mat != 0)) != 0);
  if (__pyx_t_13) {

    /* "discretize/_extensions/tree_ext.pyx":6612
 * 
 *         if not build_mat:
 *             return output             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))
 * 
 */
    __Pyx_TraceLine(6612,0,__PYX_ERR(0, 6612, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_output);
    __pyx_r = __pyx_v_output;
    goto __pyx_L0;

    /* "discretize/_extensions/tree_ext.pyx":6611
 *             free(dz)
 * 
 *         if not build_mat:             # <<<<<<<<<<<<<<
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))
 */
  }

  /* "discretize/_extensions/tree_ext.pyx":6613
 *         if not build_mat:
 *             return output
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))             # <<<<<<<<<<<<<<
 * 
 *     def get_overlapping_cells(self, rectangle):
 */
  __Pyx_TraceLine(6613,0,__PYX_ERR(0, 6613, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_sp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __pyx_convert_vector_to_py_double(__pyx_v_all_weights); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __pyx_convert_vector_to_py_int_t(__pyx_v_row_inds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_indptr, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_5numpy_int64_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_5numpy_int64_t, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8);
  __pyx_t_9 = 0;
  __pyx_t_1 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n_cells); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_in_tens_mesh, __pyx_n_s_n_cells); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
  __pyx_t_1 = 0;
  __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_shape, __pyx_t_10) < 0) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_10;
  __pyx_t_10 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6443
 *     @cython.boundscheck(False)
 *     @cython.cdivision(True)
 *     def _vol_avg_from_tens(self, in_tens_mesh, values=None, output=None):             # <<<<<<<<<<<<<<
 *         cdef double *weights
 *         cdef double over_lap_vol
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_12);
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh._vol_avg_from_tens", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_origin, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_xF, 1);
  __Pyx_XDECREF(__pyx_v_out_cell_inds);
  __Pyx_XDECREF(__pyx_v_ws);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_x, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_y, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_nodes_z, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_vals, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_outs, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_indptr, 1);
  __Pyx_XDECREF(__pyx_v_output);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6615
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))
 * 
 *     def get_overlapping_cells(self, rectangle):             # <<<<<<<<<<<<<<
 *         """Find the indicis of cells that overlap the given rectangle
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_103get_overlapping_cells(PyObject *__pyx_v_self, PyObject *__pyx_v_rectangle); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_102get_overlapping_cells[] = "_TreeMesh.get_overlapping_cells(self, rectangle)\nFind the indicis of cells that overlap the given rectangle\n\n        Parameters\n        ----------\n        rectangle: (dim * 2) array_like\n            array ordered ``[x_min, x_max, y_min, y_max, (z_min, z_max)]`` describing\n            the axis aligned rectangle of interest.\n\n        Returns\n        -------\n        list of int\n            The indices of cells which overlap the axis aligned rectangle.\n        ";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_103get_overlapping_cells(PyObject *__pyx_v_self, PyObject *__pyx_v_rectangle) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_overlapping_cells (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_102get_overlapping_cells(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v_rectangle));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_102get_overlapping_cells(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, PyObject *__pyx_v_rectangle) {
  double __pyx_v_xm;
  double __pyx_v_ym;
  double __pyx_v_zm;
  double __pyx_v_xp;
  double __pyx_v_yp;
  double __pyx_v_zp;
  __Pyx_memviewslice __pyx_v_origin = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_xF = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1 = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  double __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_overlapping_cells", 0);
  __Pyx_TraceCall("get_overlapping_cells", __pyx_f[0], 6615, 0, __PYX_ERR(0, 6615, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6630
 *         """
 *         cdef double xm, ym, zm, xp, yp, zp
 *         cdef double[:] origin = self._origin             # <<<<<<<<<<<<<<
 *         cdef double[:] xF
 *         if self.dim == 2:
 */
  __Pyx_TraceLine(6630,0,__PYX_ERR(0, 6630, __pyx_L1_error))
  if (unlikely(!__pyx_v_self->_origin.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6630, __pyx_L1_error)}
  __pyx_t_1 = __pyx_v_self->_origin;
  __PYX_INC_MEMVIEW(&__pyx_t_1, 1);
  __pyx_v_origin = __pyx_t_1;
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;

  /* "discretize/_extensions/tree_ext.pyx":6632
 *         cdef double[:] origin = self._origin
 *         cdef double[:] xF
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([self._xs[-1], self._ys[-1]])
 *         else:
 */
  __Pyx_TraceLine(6632,0,__PYX_ERR(0, 6632, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6632, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "discretize/_extensions/tree_ext.pyx":6633
 *         cdef double[:] xF
 *         if self.dim == 2:
 *             xF = np.array([self._xs[-1], self._ys[-1]])             # <<<<<<<<<<<<<<
 *         else:
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])
 */
    __Pyx_TraceLine(6633,0,__PYX_ERR(0, 6633, __pyx_L1_error))
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6633, __pyx_L1_error)}
    __pyx_t_6 = -1L;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_self->_xs.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_self->_xs.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6633, __pyx_L1_error)
    }
    __pyx_t_2 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_6 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6633, __pyx_L1_error)}
    __pyx_t_6 = -1L;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_self->_ys.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_self->_ys.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6633, __pyx_L1_error)
    }
    __pyx_t_8 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_6 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyList_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
    __pyx_t_2 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 6633, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_xF = __pyx_t_1;
    __pyx_t_1.memview = NULL;
    __pyx_t_1.data = NULL;

    /* "discretize/_extensions/tree_ext.pyx":6632
 *         cdef double[:] origin = self._origin
 *         cdef double[:] xF
 *         if self.dim == 2:             # <<<<<<<<<<<<<<
 *             xF = np.array([self._xs[-1], self._ys[-1]])
 *         else:
 */
    goto __pyx_L3;
  }

  /* "discretize/_extensions/tree_ext.pyx":6635
 *             xF = np.array([self._xs[-1], self._ys[-1]])
 *         else:
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])             # <<<<<<<<<<<<<<
 *         xm = min(rectangle[0], xF[0])
 *         xp = max(rectangle[1], origin[0])
 */
  __Pyx_TraceLine(6635,0,__PYX_ERR(0, 6635, __pyx_L1_error))
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_v_self->_xs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6635, __pyx_L1_error)}
    __pyx_t_6 = -1L;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_self->_xs.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_self->_xs.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6635, __pyx_L1_error)
    }
    __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_xs.data + __pyx_t_6 * __pyx_v_self->_xs.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(!__pyx_v_self->_ys.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6635, __pyx_L1_error)}
    __pyx_t_6 = -1L;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_self->_ys.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_self->_ys.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6635, __pyx_L1_error)
    }
    __pyx_t_8 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_ys.data + __pyx_t_6 * __pyx_v_self->_ys.strides[0]) )))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (unlikely(!__pyx_v_self->_zs.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 6635, __pyx_L1_error)}
    __pyx_t_6 = -1L;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_self->_zs.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_self->_zs.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6635, __pyx_L1_error)
    }
    __pyx_t_2 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_self->_zs.data + __pyx_t_6 * __pyx_v_self->_zs.strides[0]) )))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = PyList_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_10, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_8);
    PyList_SET_ITEM(__pyx_t_10, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_10, 2, __pyx_t_2);
    __pyx_t_5 = 0;
    __pyx_t_8 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_2, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 6635, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_xF = __pyx_t_1;
    __pyx_t_1.memview = NULL;
    __pyx_t_1.data = NULL;
  }
  __pyx_L3:;

  /* "discretize/_extensions/tree_ext.pyx":6636
 *         else:
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])
 *         xm = min(rectangle[0], xF[0])             # <<<<<<<<<<<<<<
 *         xp = max(rectangle[1], origin[0])
 *         ym = min(rectangle[2], xF[1])
 */
  __Pyx_TraceLine(6636,0,__PYX_ERR(0, 6636, __pyx_L1_error))
  __pyx_t_6 = 0;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_xF.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_xF.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 6636, __pyx_L1_error)
  }
  __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_6 * __pyx_v_xF.strides[0]) )));
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_rectangle, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_10, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6636, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6636, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {
    __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6636, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_9 = __pyx_t_3;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_9); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6636, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_xm = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":6637
 *             xF = np.array([self._xs[-1], self._ys[-1], self._zs[-1]])
 *         xm = min(rectangle[0], xF[0])
 *         xp = max(rectangle[1], origin[0])             # <<<<<<<<<<<<<<
 *         ym = min(rectangle[2], xF[1])
 *         yp = max(rectangle[3], origin[1])
 */
  __Pyx_TraceLine(6637,0,__PYX_ERR(0, 6637, __pyx_L1_error))
  __pyx_t_6 = 0;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_origin.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_origin.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 6637, __pyx_L1_error)
  }
  __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_6 * __pyx_v_origin.strides[0]) )));
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_rectangle, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = PyObject_RichCompare(__pyx_t_2, __pyx_t_9, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6637, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6637, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (__pyx_t_4) {
    __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6637, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_3 = __pyx_t_10;
    __pyx_t_10 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_9);
    __pyx_t_3 = __pyx_t_9;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6637, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_xp = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":6638
 *         xm = min(rectangle[0], xF[0])
 *         xp = max(rectangle[1], origin[0])
 *         ym = min(rectangle[2], xF[1])             # <<<<<<<<<<<<<<
 *         yp = max(rectangle[3], origin[1])
 *         if self.dim==3:
 */
  __Pyx_TraceLine(6638,0,__PYX_ERR(0, 6638, __pyx_L1_error))
  __pyx_t_6 = 1;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_xF.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_xF.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 6638, __pyx_L1_error)
  }
  __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_6 * __pyx_v_xF.strides[0]) )));
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_rectangle, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_10, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6638, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6638, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {
    __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6638, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_9 = __pyx_t_3;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_9); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6638, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_ym = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":6639
 *         xp = max(rectangle[1], origin[0])
 *         ym = min(rectangle[2], xF[1])
 *         yp = max(rectangle[3], origin[1])             # <<<<<<<<<<<<<<
 *         if self.dim==3:
 *             zm = min(rectangle[4], xF[2])
 */
  __Pyx_TraceLine(6639,0,__PYX_ERR(0, 6639, __pyx_L1_error))
  __pyx_t_6 = 1;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_origin.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_origin.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 6639, __pyx_L1_error)
  }
  __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_6 * __pyx_v_origin.strides[0]) )));
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_rectangle, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = PyObject_RichCompare(__pyx_t_2, __pyx_t_9, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6639, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6639, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (__pyx_t_4) {
    __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_3 = __pyx_t_10;
    __pyx_t_10 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_9);
    __pyx_t_3 = __pyx_t_9;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6639, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_yp = __pyx_t_11;

  /* "discretize/_extensions/tree_ext.pyx":6640
 *         ym = min(rectangle[2], xF[1])
 *         yp = max(rectangle[3], origin[1])
 *         if self.dim==3:             # <<<<<<<<<<<<<<
 *             zm = min(rectangle[4], xF[2])
 *             zp = max(rectangle[5], origin[2])
 */
  __Pyx_TraceLine(6640,0,__PYX_ERR(0, 6640, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6640, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_9 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6640, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6640, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_4) {

    /* "discretize/_extensions/tree_ext.pyx":6641
 *         yp = max(rectangle[3], origin[1])
 *         if self.dim==3:
 *             zm = min(rectangle[4], xF[2])             # <<<<<<<<<<<<<<
 *             zp = max(rectangle[5], origin[2])
 *         else:
 */
    __Pyx_TraceLine(6641,0,__PYX_ERR(0, 6641, __pyx_L1_error))
    __pyx_t_6 = 2;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_xF.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_xF.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6641, __pyx_L1_error)
    }
    __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_xF.data + __pyx_t_6 * __pyx_v_xF.strides[0]) )));
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_rectangle, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6641, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6641, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6641, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
      __pyx_t_2 = 0;
    } else {
      __Pyx_INCREF(__pyx_t_9);
      __pyx_t_3 = __pyx_t_9;
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6641, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_zm = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6642
 *         if self.dim==3:
 *             zm = min(rectangle[4], xF[2])
 *             zp = max(rectangle[5], origin[2])             # <<<<<<<<<<<<<<
 *         else:
 *             zm = 0.0
 */
    __Pyx_TraceLine(6642,0,__PYX_ERR(0, 6642, __pyx_L1_error))
    __pyx_t_6 = 2;
    __pyx_t_7 = -1;
    if (__pyx_t_6 < 0) {
      __pyx_t_6 += __pyx_v_origin.shape[0];
      if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_6 >= __pyx_v_origin.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 6642, __pyx_L1_error)
    }
    __pyx_t_11 = (*((double *) ( /* dim=0 */ (__pyx_v_origin.data + __pyx_t_6 * __pyx_v_origin.strides[0]) )));
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_rectangle, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 6642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (__pyx_t_4) {
      __pyx_t_10 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 6642, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_9 = __pyx_t_10;
      __pyx_t_10 = 0;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_9 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_9); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 6642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_zp = __pyx_t_11;

    /* "discretize/_extensions/tree_ext.pyx":6640
 *         ym = min(rectangle[2], xF[1])
 *         yp = max(rectangle[3], origin[1])
 *         if self.dim==3:             # <<<<<<<<<<<<<<
 *             zm = min(rectangle[4], xF[2])
 *             zp = max(rectangle[5], origin[2])
 */
    goto __pyx_L4;
  }

  /* "discretize/_extensions/tree_ext.pyx":6644
 *             zp = max(rectangle[5], origin[2])
 *         else:
 *             zm = 0.0             # <<<<<<<<<<<<<<
 *             zp = 0.0
 *         return self.tree.find_overlapping_cells(xm, xp, ym, yp, zm, zp)
 */
  __Pyx_TraceLine(6644,0,__PYX_ERR(0, 6644, __pyx_L1_error))
  /*else*/ {
    __pyx_v_zm = 0.0;

    /* "discretize/_extensions/tree_ext.pyx":6645
 *         else:
 *             zm = 0.0
 *             zp = 0.0             # <<<<<<<<<<<<<<
 *         return self.tree.find_overlapping_cells(xm, xp, ym, yp, zm, zp)
 * 
 */
    __Pyx_TraceLine(6645,0,__PYX_ERR(0, 6645, __pyx_L1_error))
    __pyx_v_zp = 0.0;
  }
  __pyx_L4:;

  /* "discretize/_extensions/tree_ext.pyx":6646
 *             zm = 0.0
 *             zp = 0.0
 *         return self.tree.find_overlapping_cells(xm, xp, ym, yp, zm, zp)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(6646,0,__PYX_ERR(0, 6646, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_9 = __pyx_convert_vector_to_py_int_t(__pyx_v_self->tree->find_overlapping_cells(__pyx_v_xm, __pyx_v_xp, __pyx_v_ym, __pyx_v_yp, __pyx_v_zm, __pyx_v_zp)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 6646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6615
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(self.n_cells, in_tens_mesh.n_cells))
 * 
 *     def get_overlapping_cells(self, rectangle):             # <<<<<<<<<<<<<<
 *         """Find the indicis of cells that overlap the given rectangle
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.get_overlapping_cells", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_origin, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_xF, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_105__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_104__reduce_cython__[] = "_TreeMesh.__reduce_cython__(self)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_105__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_104__reduce_cython__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_104__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __Pyx_TraceLine(2,0,__PYX_ERR(1, 2, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_107__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_106__setstate_cython__[] = "_TreeMesh.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_107__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_106__setstate_cython__(((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_10discretize_11_extensions_8tree_ext_9_TreeMesh_106__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discretize._extensions.tree_ext._TreeMesh.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discretize/_extensions/tree_ext.pyx":6649
 * 
 * 
 * cdef inline double _clip01(double x) nogil:             # <<<<<<<<<<<<<<
 *     return min(1, max(x, 0))
 */

static CYTHON_INLINE double __pyx_f_10discretize_11_extensions_8tree_ext__clip01(double __pyx_v_x) {
  double __pyx_r;
  __Pyx_TraceDeclarations
  long __pyx_t_1;
  double __pyx_t_2;
  double __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("_clip01", __pyx_f[0], 6649, 1, __PYX_ERR(0, 6649, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":6650
 * 
 * cdef inline double _clip01(double x) nogil:
 *     return min(1, max(x, 0))             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(6650,1,__PYX_ERR(0, 6650, __pyx_L1_error))
  __pyx_t_1 = 0;
  __pyx_t_2 = __pyx_v_x;
  if (((__pyx_t_1 > __pyx_t_2) != 0)) {
    __pyx_t_3 = __pyx_t_1;
  } else {
    __pyx_t_3 = __pyx_t_2;
  }
  __pyx_t_2 = __pyx_t_3;
  __pyx_t_1 = 1;
  if (((__pyx_t_2 < __pyx_t_1) != 0)) {
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  __pyx_r = __pyx_t_3;
  goto __pyx_L0;

  /* "discretize/_extensions/tree_ext.pyx":6649
 * 
 * 
 * cdef inline double _clip01(double x) nogil:             # <<<<<<<<<<<<<<
 *     return min(1, max(x, 0))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("discretize._extensions.tree_ext._clip01", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":734
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew1", __pyx_f[2], 734, 0, __PYX_ERR(2, 734, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":735
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_TraceLine(735,0,__PYX_ERR(2, 735, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 735, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":734
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":737
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew2", __pyx_f[2], 737, 0, __PYX_ERR(2, 737, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":738
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_TraceLine(738,0,__PYX_ERR(2, 738, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 738, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":737
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":740
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew3", __pyx_f[2], 740, 0, __PYX_ERR(2, 740, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":741
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_TraceLine(741,0,__PYX_ERR(2, 741, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 741, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":740
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":743
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew4", __pyx_f[2], 743, 0, __PYX_ERR(2, 743, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":744
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_TraceLine(744,0,__PYX_ERR(2, 744, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 744, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":743
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":746
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew5", __pyx_f[2], 746, 0, __PYX_ERR(2, 746, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":747
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 */
  __Pyx_TraceLine(747,0,__PYX_ERR(2, 747, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":746
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":749
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyDataType_SHAPE", 0);
  __Pyx_TraceCall("PyDataType_SHAPE", __pyx_f[2], 749, 0, __PYX_ERR(2, 749, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":750
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  __Pyx_TraceLine(750,0,__PYX_ERR(2, 750, __pyx_L1_error))
  __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0);
  if (__pyx_t_1) {

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":751
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape             # <<<<<<<<<<<<<<
 *     else:
 *         return ()
 */
    __Pyx_TraceLine(751,0,__PYX_ERR(2, 751, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
    __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape);
    goto __pyx_L0;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":750
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":753
 *         return <tuple>d.subarray.shape
 *     else:
 *         return ()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(753,0,__PYX_ERR(2, 753, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_empty_tuple);
    __pyx_r = __pyx_empty_tuple;
    goto __pyx_L0;
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":749
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("numpy.PyDataType_SHAPE", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":928
 *     int _import_umath() except -1
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_array_base", 0);
  __Pyx_TraceCall("set_array_base", __pyx_f[2], 928, 0, __PYX_ERR(2, 928, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":929
 * 
 * cdef inline void set_array_base(ndarray arr, object base):
 *     Py_INCREF(base) # important to do this before stealing the reference below!             # <<<<<<<<<<<<<<
 *     PyArray_SetBaseObject(arr, base)
 * 
 */
  __Pyx_TraceLine(929,0,__PYX_ERR(2, 929, __pyx_L1_error))
  Py_INCREF(__pyx_v_base);

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":930
 * cdef inline void set_array_base(ndarray arr, object base):
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __Pyx_TraceLine(930,0,__PYX_ERR(2, 930, __pyx_L1_error))
  (void)(PyArray_SetBaseObject(__pyx_v_arr, __pyx_v_base));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":928
 *     int _import_umath() except -1
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.set_array_base", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":932
 *     PyArray_SetBaseObject(arr, base)
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_v_base;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_array_base", 0);
  __Pyx_TraceCall("get_array_base", __pyx_f[2], 932, 0, __PYX_ERR(2, 932, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":933
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)             # <<<<<<<<<<<<<<
 *     if base is NULL:
 *         return None
 */
  __Pyx_TraceLine(933,0,__PYX_ERR(2, 933, __pyx_L1_error))
  __pyx_v_base = PyArray_BASE(__pyx_v_arr);

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":934
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)
 *     if base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     return <object>base
 */
  __Pyx_TraceLine(934,0,__PYX_ERR(2, 934, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":935
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     return <object>base
 * 
 */
    __Pyx_TraceLine(935,0,__PYX_ERR(2, 935, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":934
 * cdef inline object get_array_base(ndarray arr):
 *     base = PyArray_BASE(arr)
 *     if base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     return <object>base
 */
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":936
 *     if base is NULL:
 *         return None
 *     return <object>base             # <<<<<<<<<<<<<<
 * 
 * # Versions of the import_* functions which are more suitable for
 */
  __Pyx_TraceLine(936,0,__PYX_ERR(2, 936, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_base));
  __pyx_r = ((PyObject *)__pyx_v_base);
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":932
 *     PyArray_SetBaseObject(arr, base)
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("numpy.get_array_base", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":940
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         __pyx_import_array()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_array", 0);
  __Pyx_TraceCall("import_array", __pyx_f[2], 940, 0, __PYX_ERR(2, 940, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":941
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
  __Pyx_TraceLine(941,0,__PYX_ERR(2, 941, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":942
 * cdef inline int import_array() except -1:
 *     try:
 *         __pyx_import_array()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")
 */
      __Pyx_TraceLine(942,0,__PYX_ERR(2, 942, __pyx_L3_error))
      __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 942, __pyx_L3_error)

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":941
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":943
 *     try:
 *         __pyx_import_array()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 */
    __Pyx_TraceLine(943,0,__PYX_ERR(2, 943, __pyx_L5_except_error))
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 943, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":944
 *         __pyx_import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
      __Pyx_TraceLine(944,0,__PYX_ERR(2, 944, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 944, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 944, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":941
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         __pyx_import_array()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":940
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         __pyx_import_array()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":946
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_umath", 0);
  __Pyx_TraceCall("import_umath", __pyx_f[2], 946, 0, __PYX_ERR(2, 946, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":947
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  __Pyx_TraceLine(947,0,__PYX_ERR(2, 947, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":948
 * cdef inline int import_umath() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __Pyx_TraceLine(948,0,__PYX_ERR(2, 948, __pyx_L3_error))
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 948, __pyx_L3_error)

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":947
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":949
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __Pyx_TraceLine(949,0,__PYX_ERR(2, 949, __pyx_L5_except_error))
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 949, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":950
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
      __Pyx_TraceLine(950,0,__PYX_ERR(2, 950, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 950, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 950, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":947
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":946
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":952
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("import_ufunc", 0);
  __Pyx_TraceCall("import_ufunc", __pyx_f[2], 952, 0, __PYX_ERR(2, 952, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":953
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  __Pyx_TraceLine(953,0,__PYX_ERR(2, 953, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":954
 * cdef inline int import_ufunc() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __Pyx_TraceLine(954,0,__PYX_ERR(2, 954, __pyx_L3_error))
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 954, __pyx_L3_error)

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":953
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":955
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __Pyx_TraceLine(955,0,__PYX_ERR(2, 955, __pyx_L5_except_error))
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 955, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":956
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef extern from *:
 */
      __Pyx_TraceLine(956,0,__PYX_ERR(2, 956, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 956, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 956, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":953
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":952
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline bint is_timedelta64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.timedelta64)`
 */

static CYTHON_INLINE int __pyx_f_5numpy_is_timedelta64_object(PyObject *__pyx_v_obj) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_timedelta64_object", 0);
  __Pyx_TraceCall("is_timedelta64_object", __pyx_f[2], 966, 0, __PYX_ERR(2, 966, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":978
 *     bool
 *     """
 *     return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(978,0,__PYX_ERR(2, 978, __pyx_L1_error))
  __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyTimedeltaArrType_Type));
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline bint is_timedelta64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.timedelta64)`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.is_timedelta64_object", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":981
 * 
 * 
 * cdef inline bint is_datetime64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.datetime64)`
 */

static CYTHON_INLINE int __pyx_f_5numpy_is_datetime64_object(PyObject *__pyx_v_obj) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_datetime64_object", 0);
  __Pyx_TraceCall("is_datetime64_object", __pyx_f[2], 981, 0, __PYX_ERR(2, 981, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":993
 *     bool
 *     """
 *     return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(993,0,__PYX_ERR(2, 993, __pyx_L1_error))
  __pyx_r = PyObject_TypeCheck(__pyx_v_obj, (&PyDatetimeArrType_Type));
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":981
 * 
 * 
 * cdef inline bint is_datetime64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.datetime64)`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.is_datetime64_object", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":996
 * 
 * 
 * cdef inline npy_datetime get_datetime64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy datetime64 object
 */

static CYTHON_INLINE npy_datetime __pyx_f_5numpy_get_datetime64_value(PyObject *__pyx_v_obj) {
  npy_datetime __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("get_datetime64_value", __pyx_f[2], 996, 1, __PYX_ERR(2, 996, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1003
 *     also needed.  That can be found using `get_datetime64_unit`.
 *     """
 *     return (<PyDatetimeScalarObject*>obj).obval             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1003,1,__PYX_ERR(2, 1003, __pyx_L1_error))
  __pyx_r = ((PyDatetimeScalarObject *)__pyx_v_obj)->obval;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":996
 * 
 * 
 * cdef inline npy_datetime get_datetime64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy datetime64 object
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.get_datetime64_value", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1006
 * 
 * 
 * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy timedelta64 object
 */

static CYTHON_INLINE npy_timedelta __pyx_f_5numpy_get_timedelta64_value(PyObject *__pyx_v_obj) {
  npy_timedelta __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("get_timedelta64_value", __pyx_f[2], 1006, 1, __PYX_ERR(2, 1006, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1010
 *     returns the int64 value underlying scalar numpy timedelta64 object
 *     """
 *     return (<PyTimedeltaScalarObject*>obj).obval             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1010,1,__PYX_ERR(2, 1010, __pyx_L1_error))
  __pyx_r = ((PyTimedeltaScalarObject *)__pyx_v_obj)->obval;
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1006
 * 
 * 
 * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy timedelta64 object
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.get_timedelta64_value", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1013
 * 
 * 
 * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the unit part of the dtype for a numpy datetime64 object.
 */

static CYTHON_INLINE NPY_DATETIMEUNIT __pyx_f_5numpy_get_datetime64_unit(PyObject *__pyx_v_obj) {
  NPY_DATETIMEUNIT __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("get_datetime64_unit", __pyx_f[2], 1013, 1, __PYX_ERR(2, 1013, __pyx_L1_error));

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1017
 *     returns the unit part of the dtype for a numpy datetime64 object.
 *     """
 *     return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(1017,1,__PYX_ERR(2, 1017, __pyx_L1_error))
  __pyx_r = ((NPY_DATETIMEUNIT)((PyDatetimeScalarObject *)__pyx_v_obj)->obmeta.base);
  goto __pyx_L0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1013
 * 
 * 
 * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the unit part of the dtype for a numpy datetime64 object.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.get_datetime64_unit", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = (NPY_DATETIMEUNIT) 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_PY_LONG_LONG")
 * cdef object __pyx_convert_vector_to_py_PY_LONG_LONG(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

static PyObject *__pyx_convert_vector_to_py_PY_LONG_LONG(const std::vector<PY_LONG_LONG>  &__pyx_v_v) {
  size_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  size_t __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_vector_to_py_PY_LONG_LONG", 0);
  __Pyx_TraceCall("__pyx_convert_vector_to_py_PY_LONG_LONG", __pyx_f[1], 60, 0, __PYX_ERR(1, 60, __pyx_L1_error));

  /* "vector.to_py":61
 * @cname("__pyx_convert_vector_to_py_PY_LONG_LONG")
 * cdef object __pyx_convert_vector_to_py_PY_LONG_LONG(vector[X]& v):
 *     return [v[i] for i in range(v.size())]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(61,0,__PYX_ERR(1, 61, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 61, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_v.size();
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;
    __pyx_t_5 = __Pyx_PyInt_From_PY_LONG_LONG((__pyx_v_v[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_PY_LONG_LONG")
 * cdef object __pyx_convert_vector_to_py_PY_LONG_LONG(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("vector.to_py.__pyx_convert_vector_to_py_PY_LONG_LONG", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_convert_vector_to_py_int_t(const std::vector<int_t>  &__pyx_v_v) {
  size_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  size_t __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_vector_to_py_int_t", 0);
  __Pyx_TraceCall("__pyx_convert_vector_to_py_int_t", __pyx_f[1], 60, 0, __PYX_ERR(1, 60, __pyx_L1_error));

  /* "vector.to_py":61
 * @cname("__pyx_convert_vector_to_py_int_t")
 * cdef object __pyx_convert_vector_to_py_int_t(vector[X]& v):
 *     return [v[i] for i in range(v.size())]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(61,0,__PYX_ERR(1, 61, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 61, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_v.size();
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;
    __pyx_t_5 = __Pyx_PyInt_From_int_t((__pyx_v_v[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_int_t")
 * cdef object __pyx_convert_vector_to_py_int_t(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("vector.to_py.__pyx_convert_vector_to_py_int_t", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_convert_vector_to_py_double(const std::vector<double>  &__pyx_v_v) {
  size_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  size_t __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_vector_to_py_double", 0);
  __Pyx_TraceCall("__pyx_convert_vector_to_py_double", __pyx_f[1], 60, 0, __PYX_ERR(1, 60, __pyx_L1_error));

  /* "vector.to_py":61
 * @cname("__pyx_convert_vector_to_py_double")
 * cdef object __pyx_convert_vector_to_py_double(vector[X]& v):
 *     return [v[i] for i in range(v.size())]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(61,0,__PYX_ERR(1, 61, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 61, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_v.size();
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;
    __pyx_t_5 = PyFloat_FromDouble((__pyx_v_v[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_double")
 * cdef object __pyx_convert_vector_to_py_double(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("vector.to_py.__pyx_convert_vector_to_py_double", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":123
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

/* Python wrapper */
static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_shape = 0;
  Py_ssize_t __pyx_v_itemsize;
  PyObject *__pyx_v_format = 0;
  PyObject *__pyx_v_mode = 0;
  int __pyx_v_allocate_buffer;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)__pyx_n_s_c);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 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_itemsize)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(1, 123, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(1, 123, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 123, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_shape = ((PyObject*)values[0]);
    __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 123, __pyx_L3_error)
    __pyx_v_format = values[2];
    __pyx_v_mode = values[3];
    if (values[4]) {
      __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 124, __pyx_L3_error)
    } else {

      /* "View.MemoryView":124
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,
 *                   mode="c", bint allocate_buffer=True):             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
      __pyx_v_allocate_buffer = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 123, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(1, 123, __pyx_L1_error)
  if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) {
    PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(1, 123, __pyx_L1_error)
  }
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer);

  /* "View.MemoryView":123
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) {
  int __pyx_v_idx;
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_dim;
  PyObject **__pyx_v_p;
  char __pyx_v_order;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  char *__pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[1], 123, 0, __PYX_ERR(1, 123, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_format);

  /* "View.MemoryView":130
 *         cdef PyObject **p
 * 
 *         self.ndim = <int> len(shape)             # <<<<<<<<<<<<<<
 *         self.itemsize = itemsize
 * 
 */
  __Pyx_TraceLine(130,0,__PYX_ERR(1, 130, __pyx_L1_error))
  if (unlikely(__pyx_v_shape == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 130, __pyx_L1_error)
  }
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 130, __pyx_L1_error)
  __pyx_v_self->ndim = ((int)__pyx_t_1);

  /* "View.MemoryView":131
 * 
 *         self.ndim = <int> len(shape)
 *         self.itemsize = itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not self.ndim:
 */
  __Pyx_TraceLine(131,0,__PYX_ERR(1, 131, __pyx_L1_error))
  __pyx_v_self->itemsize = __pyx_v_itemsize;

  /* "View.MemoryView":133
 *         self.itemsize = itemsize
 * 
 *         if not self.ndim:             # <<<<<<<<<<<<<<
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 */
  __Pyx_TraceLine(133,0,__PYX_ERR(1, 133, __pyx_L1_error))
  __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":134
 * 
 *         if not self.ndim:
 *             raise ValueError("Empty shape tuple for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if itemsize <= 0:
 */
    __Pyx_TraceLine(134,0,__PYX_ERR(1, 134, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 134, __pyx_L1_error)

    /* "View.MemoryView":133
 *         self.itemsize = itemsize
 * 
 *         if not self.ndim:             # <<<<<<<<<<<<<<
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 */
  }

  /* "View.MemoryView":136
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 *         if itemsize <= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 */
  __Pyx_TraceLine(136,0,__PYX_ERR(1, 136, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":137
 * 
 *         if itemsize <= 0:
 *             raise ValueError("itemsize <= 0 for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if not isinstance(format, bytes):
 */
    __Pyx_TraceLine(137,0,__PYX_ERR(1, 137, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 137, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 137, __pyx_L1_error)

    /* "View.MemoryView":136
 *             raise ValueError("Empty shape tuple for cython.array")
 * 
 *         if itemsize <= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 */
  }

  /* "View.MemoryView":139
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 *         if not isinstance(format, bytes):             # <<<<<<<<<<<<<<
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 */
  __Pyx_TraceLine(139,0,__PYX_ERR(1, 139, __pyx_L1_error))
  __pyx_t_2 = PyBytes_Check(__pyx_v_format); 
  __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_4) {

    /* "View.MemoryView":140
 * 
 *         if not isinstance(format, bytes):
 *             format = format.encode('ASCII')             # <<<<<<<<<<<<<<
 *         self._format = format  # keep a reference to the byte string
 *         self.format = self._format
 */
    __Pyx_TraceLine(140,0,__PYX_ERR(1, 140, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":139
 *             raise ValueError("itemsize <= 0 for cython.array")
 * 
 *         if not isinstance(format, bytes):             # <<<<<<<<<<<<<<
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 */
  }

  /* "View.MemoryView":141
 *         if not isinstance(format, bytes):
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string             # <<<<<<<<<<<<<<
 *         self.format = self._format
 * 
 */
  __Pyx_TraceLine(141,0,__PYX_ERR(1, 141, __pyx_L1_error))
  if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(1, 141, __pyx_L1_error)
  __pyx_t_3 = __pyx_v_format;
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->_format);
  __Pyx_DECREF(__pyx_v_self->_format);
  __pyx_v_self->_format = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "View.MemoryView":142
 *             format = format.encode('ASCII')
 *         self._format = format  # keep a reference to the byte string
 *         self.format = self._format             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(142,0,__PYX_ERR(1, 142, __pyx_L1_error))
  if (unlikely(__pyx_v_self->_format == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(1, 142, __pyx_L1_error)
  }
  __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(1, 142, __pyx_L1_error)
  __pyx_v_self->format = __pyx_t_7;

  /* "View.MemoryView":145
 * 
 * 
 *         self._shape = <Py_ssize_t *> PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)             # <<<<<<<<<<<<<<
 *         self._strides = self._shape + self.ndim
 * 
 */
  __Pyx_TraceLine(145,0,__PYX_ERR(1, 145, __pyx_L1_error))
  __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2)));

  /* "View.MemoryView":146
 * 
 *         self._shape = <Py_ssize_t *> PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)
 *         self._strides = self._shape + self.ndim             # <<<<<<<<<<<<<<
 * 
 *         if not self._shape:
 */
  __Pyx_TraceLine(146,0,__PYX_ERR(1, 146, __pyx_L1_error))
  __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim);

  /* "View.MemoryView":148
 *         self._strides = self._shape + self.ndim
 * 
 *         if not self._shape:             # <<<<<<<<<<<<<<
 *             raise MemoryError("unable to allocate shape and strides.")
 * 
 */
  __Pyx_TraceLine(148,0,__PYX_ERR(1, 148, __pyx_L1_error))
  __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0);
  if (unlikely(__pyx_t_4)) {

    /* "View.MemoryView":149
 * 
 *         if not self._shape:
 *             raise MemoryError("unable to allocate shape and strides.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(149,0,__PYX_ERR(1, 149, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 149, __pyx_L1_error)

    /* "View.MemoryView":148
 *         self._strides = self._shape + self.ndim
 * 
 *         if not self._shape:             # <<<<<<<<<<<<<<
 *             raise MemoryError("unable to allocate shape and strides.")
 * 
 */
  }

  /* "View.MemoryView":152
 * 
 * 
 *         for idx, dim in enumerate(shape):             # <<<<<<<<<<<<<<
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 */
  __Pyx_TraceLine(152,0,__PYX_ERR(1, 152, __pyx_L1_error))
  __pyx_t_8 = 0;
  __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(1, 152, __pyx_L1_error)
    #else
    __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 152, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_dim = __pyx_t_9;
    __pyx_v_idx = __pyx_t_8;
    __pyx_t_8 = (__pyx_t_8 + 1);

    /* "View.MemoryView":153
 * 
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim
 */
    __Pyx_TraceLine(153,0,__PYX_ERR(1, 153, __pyx_L1_error))
    __pyx_t_4 = ((__pyx_v_dim <= 0) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":154
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))             # <<<<<<<<<<<<<<
 *             self._shape[idx] = dim
 * 
 */
      __Pyx_TraceLine(154,0,__PYX_ERR(1, 154, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 154, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 154, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 154, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 154, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 154, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(1, 154, __pyx_L1_error)

      /* "View.MemoryView":153
 * 
 *         for idx, dim in enumerate(shape):
 *             if dim <= 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim
 */
    }

    /* "View.MemoryView":155
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 *             self._shape[idx] = dim             # <<<<<<<<<<<<<<
 * 
 *         cdef char order
 */
    __Pyx_TraceLine(155,0,__PYX_ERR(1, 155, __pyx_L1_error))
    (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim;

    /* "View.MemoryView":152
 * 
 * 
 *         for idx, dim in enumerate(shape):             # <<<<<<<<<<<<<<
 *             if dim <= 0:
 *                 raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
 */
    __Pyx_TraceLine(152,0,__PYX_ERR(1, 152, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":158
 * 
 *         cdef char order
 *         if mode == 'fortran':             # <<<<<<<<<<<<<<
 *             order = b'F'
 *             self.mode = u'fortran'
 */
  __Pyx_TraceLine(158,0,__PYX_ERR(1, 158, __pyx_L1_error))
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 158, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "View.MemoryView":159
 *         cdef char order
 *         if mode == 'fortran':
 *             order = b'F'             # <<<<<<<<<<<<<<
 *             self.mode = u'fortran'
 *         elif mode == 'c':
 */
    __Pyx_TraceLine(159,0,__PYX_ERR(1, 159, __pyx_L1_error))
    __pyx_v_order = 'F';

    /* "View.MemoryView":160
 *         if mode == 'fortran':
 *             order = b'F'
 *             self.mode = u'fortran'             # <<<<<<<<<<<<<<
 *         elif mode == 'c':
 *             order = b'C'
 */
    __Pyx_TraceLine(160,0,__PYX_ERR(1, 160, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_fortran);
    __Pyx_GIVEREF(__pyx_n_u_fortran);
    __Pyx_GOTREF(__pyx_v_self->mode);
    __Pyx_DECREF(__pyx_v_self->mode);
    __pyx_v_self->mode = __pyx_n_u_fortran;

    /* "View.MemoryView":158
 * 
 *         cdef char order
 *         if mode == 'fortran':             # <<<<<<<<<<<<<<
 *             order = b'F'
 *             self.mode = u'fortran'
 */
    goto __pyx_L10;
  }

  /* "View.MemoryView":161
 *             order = b'F'
 *             self.mode = u'fortran'
 *         elif mode == 'c':             # <<<<<<<<<<<<<<
 *             order = b'C'
 *             self.mode = u'c'
 */
  __Pyx_TraceLine(161,0,__PYX_ERR(1, 161, __pyx_L1_error))
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 161, __pyx_L1_error)
  if (likely(__pyx_t_4)) {

    /* "View.MemoryView":162
 *             self.mode = u'fortran'
 *         elif mode == 'c':
 *             order = b'C'             # <<<<<<<<<<<<<<
 *             self.mode = u'c'
 *         else:
 */
    __Pyx_TraceLine(162,0,__PYX_ERR(1, 162, __pyx_L1_error))
    __pyx_v_order = 'C';

    /* "View.MemoryView":163
 *         elif mode == 'c':
 *             order = b'C'
 *             self.mode = u'c'             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
 */
    __Pyx_TraceLine(163,0,__PYX_ERR(1, 163, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_c);
    __Pyx_GIVEREF(__pyx_n_u_c);
    __Pyx_GOTREF(__pyx_v_self->mode);
    __Pyx_DECREF(__pyx_v_self->mode);
    __pyx_v_self->mode = __pyx_n_u_c;

    /* "View.MemoryView":161
 *             order = b'F'
 *             self.mode = u'fortran'
 *         elif mode == 'c':             # <<<<<<<<<<<<<<
 *             order = b'C'
 *             self.mode = u'c'
 */
    goto __pyx_L10;
  }

  /* "View.MemoryView":165
 *             self.mode = u'c'
 *         else:
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)             # <<<<<<<<<<<<<<
 * 
 *         self.len = fill_contig_strides_array(self._shape, self._strides,
 */
  __Pyx_TraceLine(165,0,__PYX_ERR(1, 165, __pyx_L1_error))
  /*else*/ {
    __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 165, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_10, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __PYX_ERR(1, 165, __pyx_L1_error)
  }
  __pyx_L10:;

  /* "View.MemoryView":167
 *             raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
 * 
 *         self.len = fill_contig_strides_array(self._shape, self._strides,             # <<<<<<<<<<<<<<
 *                                              itemsize, self.ndim, order)
 * 
 */
  __Pyx_TraceLine(167,0,__PYX_ERR(1, 167, __pyx_L1_error))
  __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order);

  /* "View.MemoryView":170
 *                                              itemsize, self.ndim, order)
 * 
 *         self.free_data = allocate_buffer             # <<<<<<<<<<<<<<
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:
 */
  __Pyx_TraceLine(170,0,__PYX_ERR(1, 170, __pyx_L1_error))
  __pyx_v_self->free_data = __pyx_v_allocate_buffer;

  /* "View.MemoryView":171
 * 
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'             # <<<<<<<<<<<<<<
 *         if allocate_buffer:
 * 
 */
  __Pyx_TraceLine(171,0,__PYX_ERR(1, 171, __pyx_L1_error))
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 171, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 171, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_v_self->dtype_is_object = __pyx_t_4;

  /* "View.MemoryView":172
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(172,0,__PYX_ERR(1, 172, __pyx_L1_error))
  __pyx_t_4 = (__pyx_v_allocate_buffer != 0);
  if (__pyx_t_4) {

    /* "View.MemoryView":175
 * 
 * 
 *             self.data = <char *>malloc(self.len)             # <<<<<<<<<<<<<<
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")
 */
    __Pyx_TraceLine(175,0,__PYX_ERR(1, 175, __pyx_L1_error))
    __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len));

    /* "View.MemoryView":176
 * 
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("unable to allocate array data.")
 * 
 */
    __Pyx_TraceLine(176,0,__PYX_ERR(1, 176, __pyx_L1_error))
    __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":177
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")             # <<<<<<<<<<<<<<
 * 
 *             if self.dtype_is_object:
 */
      __Pyx_TraceLine(177,0,__PYX_ERR(1, 177, __pyx_L1_error))
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(1, 177, __pyx_L1_error)

      /* "View.MemoryView":176
 * 
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("unable to allocate array data.")
 * 
 */
    }

    /* "View.MemoryView":179
 *                 raise MemoryError("unable to allocate array data.")
 * 
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 */
    __Pyx_TraceLine(179,0,__PYX_ERR(1, 179, __pyx_L1_error))
    __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_4) {

      /* "View.MemoryView":180
 * 
 *             if self.dtype_is_object:
 *                 p = <PyObject **> self.data             # <<<<<<<<<<<<<<
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None
 */
      __Pyx_TraceLine(180,0,__PYX_ERR(1, 180, __pyx_L1_error))
      __pyx_v_p = ((PyObject **)__pyx_v_self->data);

      /* "View.MemoryView":181
 *             if self.dtype_is_object:
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):             # <<<<<<<<<<<<<<
 *                     p[i] = Py_None
 *                     Py_INCREF(Py_None)
 */
      __Pyx_TraceLine(181,0,__PYX_ERR(1, 181, __pyx_L1_error))
      if (unlikely(__pyx_v_itemsize == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
        __PYX_ERR(1, 181, __pyx_L1_error)
      }
      else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) {
        PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
        __PYX_ERR(1, 181, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize);
      __pyx_t_9 = __pyx_t_1;
      for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) {
        __pyx_v_i = __pyx_t_11;

        /* "View.MemoryView":182
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None             # <<<<<<<<<<<<<<
 *                     Py_INCREF(Py_None)
 * 
 */
        __Pyx_TraceLine(182,0,__PYX_ERR(1, 182, __pyx_L1_error))
        (__pyx_v_p[__pyx_v_i]) = Py_None;

        /* "View.MemoryView":183
 *                 for i in range(self.len / itemsize):
 *                     p[i] = Py_None
 *                     Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
        __Pyx_TraceLine(183,0,__PYX_ERR(1, 183, __pyx_L1_error))
        Py_INCREF(Py_None);
      }

      /* "View.MemoryView":179
 *                 raise MemoryError("unable to allocate array data.")
 * 
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 p = <PyObject **> self.data
 *                 for i in range(self.len / itemsize):
 */
    }

    /* "View.MemoryView":172
 *         self.free_data = allocate_buffer
 *         self.dtype_is_object = format == b'O'
 *         if allocate_buffer:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":123
 *         cdef bint dtype_is_object
 * 
 *     def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,             # <<<<<<<<<<<<<<
 *                   mode="c", bint allocate_buffer=True):
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_format);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":186
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_bufmode;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);
  __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 186, 0, __PYX_ERR(1, 186, __pyx_L1_error));

  /* "View.MemoryView":187
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1             # <<<<<<<<<<<<<<
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 */
  __Pyx_TraceLine(187,0,__PYX_ERR(1, 187, __pyx_L1_error))
  __pyx_v_bufmode = -1;

  /* "View.MemoryView":188
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1
 *         if self.mode == u"c":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 */
  __Pyx_TraceLine(188,0,__PYX_ERR(1, 188, __pyx_L1_error))
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 188, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":189
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS             # <<<<<<<<<<<<<<
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 */
    __Pyx_TraceLine(189,0,__PYX_ERR(1, 189, __pyx_L1_error))
    __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);

    /* "View.MemoryView":188
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         cdef int bufmode = -1
 *         if self.mode == u"c":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":190
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 */
  __Pyx_TraceLine(190,0,__PYX_ERR(1, 190, __pyx_L1_error))
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 190, __pyx_L1_error)
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":191
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS             # <<<<<<<<<<<<<<
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 */
    __Pyx_TraceLine(191,0,__PYX_ERR(1, 191, __pyx_L1_error))
    __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);

    /* "View.MemoryView":190
 *         if self.mode == u"c":
 *             bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         elif self.mode == u"fortran":             # <<<<<<<<<<<<<<
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":192
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):             # <<<<<<<<<<<<<<
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 */
  __Pyx_TraceLine(192,0,__PYX_ERR(1, 192, __pyx_L1_error))
  __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":193
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")             # <<<<<<<<<<<<<<
 *         info.buf = self.data
 *         info.len = self.len
 */
    __Pyx_TraceLine(193,0,__PYX_ERR(1, 193, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 193, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 193, __pyx_L1_error)

    /* "View.MemoryView":192
 *         elif self.mode == u"fortran":
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):             # <<<<<<<<<<<<<<
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 */
  }

  /* "View.MemoryView":194
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data             # <<<<<<<<<<<<<<
 *         info.len = self.len
 *         info.ndim = self.ndim
 */
  __Pyx_TraceLine(194,0,__PYX_ERR(1, 194, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_self->data;
  __pyx_v_info->buf = __pyx_t_4;

  /* "View.MemoryView":195
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")
 *         info.buf = self.data
 *         info.len = self.len             # <<<<<<<<<<<<<<
 *         info.ndim = self.ndim
 *         info.shape = self._shape
 */
  __Pyx_TraceLine(195,0,__PYX_ERR(1, 195, __pyx_L1_error))
  __pyx_t_5 = __pyx_v_self->len;
  __pyx_v_info->len = __pyx_t_5;

  /* "View.MemoryView":196
 *         info.buf = self.data
 *         info.len = self.len
 *         info.ndim = self.ndim             # <<<<<<<<<<<<<<
 *         info.shape = self._shape
 *         info.strides = self._strides
 */
  __Pyx_TraceLine(196,0,__PYX_ERR(1, 196, __pyx_L1_error))
  __pyx_t_6 = __pyx_v_self->ndim;
  __pyx_v_info->ndim = __pyx_t_6;

  /* "View.MemoryView":197
 *         info.len = self.len
 *         info.ndim = self.ndim
 *         info.shape = self._shape             # <<<<<<<<<<<<<<
 *         info.strides = self._strides
 *         info.suboffsets = NULL
 */
  __Pyx_TraceLine(197,0,__PYX_ERR(1, 197, __pyx_L1_error))
  __pyx_t_7 = __pyx_v_self->_shape;
  __pyx_v_info->shape = __pyx_t_7;

  /* "View.MemoryView":198
 *         info.ndim = self.ndim
 *         info.shape = self._shape
 *         info.strides = self._strides             # <<<<<<<<<<<<<<
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize
 */
  __Pyx_TraceLine(198,0,__PYX_ERR(1, 198, __pyx_L1_error))
  __pyx_t_7 = __pyx_v_self->_strides;
  __pyx_v_info->strides = __pyx_t_7;

  /* "View.MemoryView":199
 *         info.shape = self._shape
 *         info.strides = self._strides
 *         info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *         info.itemsize = self.itemsize
 *         info.readonly = 0
 */
  __Pyx_TraceLine(199,0,__PYX_ERR(1, 199, __pyx_L1_error))
  __pyx_v_info->suboffsets = NULL;

  /* "View.MemoryView":200
 *         info.strides = self._strides
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize             # <<<<<<<<<<<<<<
 *         info.readonly = 0
 * 
 */
  __Pyx_TraceLine(200,0,__PYX_ERR(1, 200, __pyx_L1_error))
  __pyx_t_5 = __pyx_v_self->itemsize;
  __pyx_v_info->itemsize = __pyx_t_5;

  /* "View.MemoryView":201
 *         info.suboffsets = NULL
 *         info.itemsize = self.itemsize
 *         info.readonly = 0             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
  __Pyx_TraceLine(201,0,__PYX_ERR(1, 201, __pyx_L1_error))
  __pyx_v_info->readonly = 0;

  /* "View.MemoryView":203
 *         info.readonly = 0
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.format
 *         else:
 */
  __Pyx_TraceLine(203,0,__PYX_ERR(1, 203, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":204
 * 
 *         if flags & PyBUF_FORMAT:
 *             info.format = self.format             # <<<<<<<<<<<<<<
 *         else:
 *             info.format = NULL
 */
    __Pyx_TraceLine(204,0,__PYX_ERR(1, 204, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->format;
    __pyx_v_info->format = __pyx_t_4;

    /* "View.MemoryView":203
 *         info.readonly = 0
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.format
 *         else:
 */
    goto __pyx_L5;
  }

  /* "View.MemoryView":206
 *             info.format = self.format
 *         else:
 *             info.format = NULL             # <<<<<<<<<<<<<<
 * 
 *         info.obj = self
 */
  __Pyx_TraceLine(206,0,__PYX_ERR(1, 206, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->format = NULL;
  }
  __pyx_L5:;

  /* "View.MemoryView":208
 *             info.format = NULL
 * 
 *         info.obj = self             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_TraceLine(208,0,__PYX_ERR(1, 208, __pyx_L1_error))
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "View.MemoryView":186
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         cdef int bufmode = -1
 *         if self.mode == u"c":
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":212
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 * 
 *     def __dealloc__(array self):             # <<<<<<<<<<<<<<
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 */

/* Python wrapper */
static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_array___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self));

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

static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[1], 212, 0, __PYX_ERR(1, 212, __pyx_L1_error));

  /* "View.MemoryView":213
 * 
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:             # <<<<<<<<<<<<<<
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 */
  __Pyx_TraceLine(213,0,__PYX_ERR(1, 213, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":214
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)             # <<<<<<<<<<<<<<
 *         elif self.free_data:
 *             if self.dtype_is_object:
 */
    __Pyx_TraceLine(214,0,__PYX_ERR(1, 214, __pyx_L1_error))
    __pyx_v_self->callback_free_data(__pyx_v_self->data);

    /* "View.MemoryView":213
 * 
 *     def __dealloc__(array self):
 *         if self.callback_free_data != NULL:             # <<<<<<<<<<<<<<
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":215
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 *         elif self.free_data:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,
 */
  __Pyx_TraceLine(215,0,__PYX_ERR(1, 215, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->free_data != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":216
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 */
    __Pyx_TraceLine(216,0,__PYX_ERR(1, 216, __pyx_L1_error))
    __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":217
 *         elif self.free_data:
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,             # <<<<<<<<<<<<<<
 *                                           self._strides, self.ndim, False)
 *             free(self.data)
 */
      __Pyx_TraceLine(217,0,__PYX_ERR(1, 217, __pyx_L1_error))
      __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0);

      /* "View.MemoryView":216
 *             self.callback_free_data(self.data)
 *         elif self.free_data:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 */
    }

    /* "View.MemoryView":219
 *                 refcount_objects_in_slice(self.data, self._shape,
 *                                           self._strides, self.ndim, False)
 *             free(self.data)             # <<<<<<<<<<<<<<
 *         PyObject_Free(self._shape)
 * 
 */
    __Pyx_TraceLine(219,0,__PYX_ERR(1, 219, __pyx_L1_error))
    free(__pyx_v_self->data);

    /* "View.MemoryView":215
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 *         elif self.free_data:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 refcount_objects_in_slice(self.data, self._shape,
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":220
 *                                           self._strides, self.ndim, False)
 *             free(self.data)
 *         PyObject_Free(self._shape)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(220,0,__PYX_ERR(1, 220, __pyx_L1_error))
  PyObject_Free(__pyx_v_self->_shape);

  /* "View.MemoryView":212
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
 * 
 *     def __dealloc__(array self):             # <<<<<<<<<<<<<<
 *         if self.callback_free_data != NULL:
 *             self.callback_free_data(self.data)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.array.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "View.MemoryView":223
 * 
 *     @property
 *     def memview(self):             # <<<<<<<<<<<<<<
 *         return self.get_memview()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 223, 0, __PYX_ERR(1, 223, __pyx_L1_error));

  /* "View.MemoryView":224
 *     @property
 *     def memview(self):
 *         return self.get_memview()             # <<<<<<<<<<<<<<
 * 
 *     @cname('get_memview')
 */
  __Pyx_TraceLine(224,0,__PYX_ERR(1, 224, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":223
 * 
 *     @property
 *     def memview(self):             # <<<<<<<<<<<<<<
 *         return self.get_memview()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":227
 * 
 *     @cname('get_memview')
 *     cdef get_memview(self):             # <<<<<<<<<<<<<<
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)
 */

static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) {
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_memview", 0);
  __Pyx_TraceCall("get_memview", __pyx_f[1], 227, 0, __PYX_ERR(1, 227, __pyx_L1_error));

  /* "View.MemoryView":228
 *     @cname('get_memview')
 *     cdef get_memview(self):
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE             # <<<<<<<<<<<<<<
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 */
  __Pyx_TraceLine(228,0,__PYX_ERR(1, 228, __pyx_L1_error))
  __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE);

  /* "View.MemoryView":229
 *     cdef get_memview(self):
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_TraceLine(229,0,__PYX_ERR(1, 229, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":227
 * 
 *     @cname('get_memview')
 *     cdef get_memview(self):             # <<<<<<<<<<<<<<
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":231
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self._shape[0]
 * 
 */

/* Python wrapper */
static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self));

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

static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__len__", 0);
  __Pyx_TraceCall("__len__", __pyx_f[1], 231, 0, __PYX_ERR(1, 231, __pyx_L1_error));

  /* "View.MemoryView":232
 * 
 *     def __len__(self):
 *         return self._shape[0]             # <<<<<<<<<<<<<<
 * 
 *     def __getattr__(self, attr):
 */
  __Pyx_TraceLine(232,0,__PYX_ERR(1, 232, __pyx_L1_error))
  __pyx_r = (__pyx_v_self->_shape[0]);
  goto __pyx_L0;

  /* "View.MemoryView":231
 *         return  memoryview(self, flags, self.dtype_is_object)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self._shape[0]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.array.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":234
 *         return self._shape[0]
 * 
 *     def __getattr__(self, attr):             # <<<<<<<<<<<<<<
 *         return getattr(self.memview, attr)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/
static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr));

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

static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getattr__", 0);
  __Pyx_TraceCall("__getattr__", __pyx_f[1], 234, 0, __PYX_ERR(1, 234, __pyx_L1_error));

  /* "View.MemoryView":235
 * 
 *     def __getattr__(self, attr):
 *         return getattr(self.memview, attr)             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, item):
 */
  __Pyx_TraceLine(235,0,__PYX_ERR(1, 235, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":234
 *         return self._shape[0]
 * 
 *     def __getattr__(self, attr):             # <<<<<<<<<<<<<<
 *         return getattr(self.memview, attr)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":237
 *         return getattr(self.memview, attr)
 * 
 *     def __getitem__(self, item):             # <<<<<<<<<<<<<<
 *         return self.memview[item]
 * 
 */

/* Python wrapper */
static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item));

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

static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);
  __Pyx_TraceCall("__getitem__", __pyx_f[1], 237, 0, __PYX_ERR(1, 237, __pyx_L1_error));

  /* "View.MemoryView":238
 * 
 *     def __getitem__(self, item):
 *         return self.memview[item]             # <<<<<<<<<<<<<<
 * 
 *     def __setitem__(self, item, value):
 */
  __Pyx_TraceLine(238,0,__PYX_ERR(1, 238, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":237
 *         return getattr(self.memview, attr)
 * 
 *     def __getitem__(self, item):             # <<<<<<<<<<<<<<
 *         return self.memview[item]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":240
 *         return self.memview[item]
 * 
 *     def __setitem__(self, item, value):             # <<<<<<<<<<<<<<
 *         self.memview[item] = value
 * 
 */

/* Python wrapper */
static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/
static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value));

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

static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 0);
  __Pyx_TraceCall("__setitem__", __pyx_f[1], 240, 0, __PYX_ERR(1, 240, __pyx_L1_error));

  /* "View.MemoryView":241
 * 
 *     def __setitem__(self, item, value):
 *         self.memview[item] = value             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(241,0,__PYX_ERR(1, 241, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 241, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(1, 241, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "View.MemoryView":240
 *         return self.memview[item]
 * 
 *     def __setitem__(self, item, value):             # <<<<<<<<<<<<<<
 *         self.memview[item] = value
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __Pyx_TraceLine(2,0,__PYX_ERR(1, 2, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":245
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,             # <<<<<<<<<<<<<<
 *                           char *mode, char *buf):
 *     cdef array result
 */

static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) {
  struct __pyx_array_obj *__pyx_v_result = 0;
  struct __pyx_array_obj *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("array_cwrapper", 0);
  __Pyx_TraceCall("array_cwrapper", __pyx_f[1], 245, 0, __PYX_ERR(1, 245, __pyx_L1_error));

  /* "View.MemoryView":249
 *     cdef array result
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 */
  __Pyx_TraceLine(249,0,__PYX_ERR(1, 249, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":250
 * 
 *     if buf == NULL:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))             # <<<<<<<<<<<<<<
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 */
    __Pyx_TraceLine(250,0,__PYX_ERR(1, 250, __pyx_L1_error))
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_shape);
    __Pyx_GIVEREF(__pyx_v_shape);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "View.MemoryView":249
 *     cdef array result
 * 
 *     if buf == NULL:             # <<<<<<<<<<<<<<
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":252
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),             # <<<<<<<<<<<<<<
 *                        allocate_buffer=False)
 *         result.data = buf
 */
  __Pyx_TraceLine(252,0,__PYX_ERR(1, 252, __pyx_L1_error))
  /*else*/ {
    __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_shape);
    __Pyx_GIVEREF(__pyx_v_shape);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;

    /* "View.MemoryView":253
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 *                        allocate_buffer=False)             # <<<<<<<<<<<<<<
 *         result.data = buf
 * 
 */
    __Pyx_TraceLine(253,0,__PYX_ERR(1, 253, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(1, 253, __pyx_L1_error)

    /* "View.MemoryView":252
 *         result = array(shape, itemsize, format, mode.decode('ASCII'))
 *     else:
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),             # <<<<<<<<<<<<<<
 *                        allocate_buffer=False)
 *         result.data = buf
 */
    __Pyx_TraceLine(252,0,__PYX_ERR(1, 252, __pyx_L1_error))
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "View.MemoryView":254
 *         result = array(shape, itemsize, format, mode.decode('ASCII'),
 *                        allocate_buffer=False)
 *         result.data = buf             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
    __Pyx_TraceLine(254,0,__PYX_ERR(1, 254, __pyx_L1_error))
    __pyx_v_result->data = __pyx_v_buf;
  }
  __pyx_L3:;

  /* "View.MemoryView":256
 *         result.data = buf
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(256,0,__PYX_ERR(1, 256, __pyx_L1_error))
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "View.MemoryView":245
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,             # <<<<<<<<<<<<<<
 *                           char *mode, char *buf):
 *     cdef array result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":282
 * cdef class Enum(object):
 *     cdef object name
 *     def __init__(self, name):             # <<<<<<<<<<<<<<
 *         self.name = name
 *     def __repr__(self):
 */

/* Python wrapper */
static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_name = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0};
    PyObject* values[1] = {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  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_name)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 282, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_name = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 282, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name);

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

static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[1], 282, 0, __PYX_ERR(1, 282, __pyx_L1_error));

  /* "View.MemoryView":283
 *     cdef object name
 *     def __init__(self, name):
 *         self.name = name             # <<<<<<<<<<<<<<
 *     def __repr__(self):
 *         return self.name
 */
  __Pyx_TraceLine(283,0,__PYX_ERR(1, 283, __pyx_L1_error))
  __Pyx_INCREF(__pyx_v_name);
  __Pyx_GIVEREF(__pyx_v_name);
  __Pyx_GOTREF(__pyx_v_self->name);
  __Pyx_DECREF(__pyx_v_self->name);
  __pyx_v_self->name = __pyx_v_name;

  /* "View.MemoryView":282
 * cdef class Enum(object):
 *     cdef object name
 *     def __init__(self, name):             # <<<<<<<<<<<<<<
 *         self.name = name
 *     def __repr__(self):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":284
 *     def __init__(self, name):
 *         self.name = name
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return self.name
 * 
 */

/* Python wrapper */
static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));

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

static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);
  __Pyx_TraceCall("__repr__", __pyx_f[1], 284, 0, __PYX_ERR(1, 284, __pyx_L1_error));

  /* "View.MemoryView":285
 *         self.name = name
 *     def __repr__(self):
 *         return self.name             # <<<<<<<<<<<<<<
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 */
  __Pyx_TraceLine(285,0,__PYX_ERR(1, 285, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->name);
  __pyx_r = __pyx_v_self->name;
  goto __pyx_L0;

  /* "View.MemoryView":284
 *     def __init__(self, name):
 *         self.name = name
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return self.name
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.Enum.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self.name,)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __Pyx_TraceLine(5,0,__PYX_ERR(1, 5, __pyx_L1_error))
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_self->name);
  __Pyx_GIVEREF(__pyx_v_self->name);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name);
  __pyx_v_state = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __Pyx_TraceLine(6,0,__PYX_ERR(1, 6, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v__dict = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "(tree fragment)":7
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __Pyx_TraceLine(7,0,__PYX_ERR(1, 7, __pyx_L1_error))
  __pyx_t_2 = (__pyx_v__dict != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __Pyx_TraceLine(8,0,__PYX_ERR(1, 8, __pyx_L1_error))
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = self.name is not None
 */
    __Pyx_TraceLine(9,0,__PYX_ERR(1, 9, __pyx_L1_error))
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self.name,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = self.name is not None             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 */
  __Pyx_TraceLine(11,0,__PYX_ERR(1, 11, __pyx_L1_error))
  /*else*/ {
    __pyx_t_3 = (__pyx_v_self->name != Py_None);
    __pyx_v_use_setstate = __pyx_t_3;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = self.name is not None
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 */
  __Pyx_TraceLine(12,0,__PYX_ERR(1, 12, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_use_setstate != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":13
 *         use_setstate = self.name is not None
 *     if use_setstate:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 */
    __Pyx_TraceLine(13,0,__PYX_ERR(1, 13, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_184977713);
    __Pyx_GIVEREF(__pyx_int_184977713);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = self.name is not None
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */
  __Pyx_TraceLine(15,0,__PYX_ERR(1, 15, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_184977713);
    __Pyx_GIVEREF(__pyx_int_184977713);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 16, 0, __PYX_ERR(1, 16, __pyx_L1_error));

  /* "(tree fragment)":17
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(17,0,__PYX_ERR(1, 17, __pyx_L1_error))
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Enum__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":299
 * 
 * @cname('__pyx_align_pointer')
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:             # <<<<<<<<<<<<<<
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory
 */

static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) {
  Py_intptr_t __pyx_v_aligned_p;
  size_t __pyx_v_offset;
  void *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("align_pointer", __pyx_f[1], 299, 1, __PYX_ERR(1, 299, __pyx_L1_error));

  /* "View.MemoryView":301
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory             # <<<<<<<<<<<<<<
 *     cdef size_t offset
 * 
 */
  __Pyx_TraceLine(301,1,__PYX_ERR(1, 301, __pyx_L1_error))
  __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory);

  /* "View.MemoryView":305
 * 
 *     with cython.cdivision(True):
 *         offset = aligned_p % alignment             # <<<<<<<<<<<<<<
 * 
 *     if offset > 0:
 */
  __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment);

  /* "View.MemoryView":307
 *         offset = aligned_p % alignment
 * 
 *     if offset > 0:             # <<<<<<<<<<<<<<
 *         aligned_p += alignment - offset
 * 
 */
  __Pyx_TraceLine(307,1,__PYX_ERR(1, 307, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_offset > 0) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":308
 * 
 *     if offset > 0:
 *         aligned_p += alignment - offset             # <<<<<<<<<<<<<<
 * 
 *     return <void *> aligned_p
 */
    __Pyx_TraceLine(308,1,__PYX_ERR(1, 308, __pyx_L1_error))
    __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset));

    /* "View.MemoryView":307
 *         offset = aligned_p % alignment
 * 
 *     if offset > 0:             # <<<<<<<<<<<<<<
 *         aligned_p += alignment - offset
 * 
 */
  }

  /* "View.MemoryView":310
 *         aligned_p += alignment - offset
 * 
 *     return <void *> aligned_p             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(310,1,__PYX_ERR(1, 310, __pyx_L1_error))
  __pyx_r = ((void *)__pyx_v_aligned_p);
  goto __pyx_L0;

  /* "View.MemoryView":299
 * 
 * @cname('__pyx_align_pointer')
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:             # <<<<<<<<<<<<<<
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.align_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":346
 *     cdef __Pyx_TypeInfo *typeinfo
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):             # <<<<<<<<<<<<<<
 *         self.obj = obj
 *         self.flags = flags
 */

/* Python wrapper */
static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  int __pyx_v_flags;
  int __pyx_v_dtype_is_object;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,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_obj)) != 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_flags)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(1, 346, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 346, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_obj = values[0];
    __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 346, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 346, __pyx_L3_error)
    } else {
      __pyx_v_dtype_is_object = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 346, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object);

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[1], 346, 0, __PYX_ERR(1, 346, __pyx_L1_error));

  /* "View.MemoryView":347
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
 *         self.obj = obj             # <<<<<<<<<<<<<<
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:
 */
  __Pyx_TraceLine(347,0,__PYX_ERR(1, 347, __pyx_L1_error))
  __Pyx_INCREF(__pyx_v_obj);
  __Pyx_GIVEREF(__pyx_v_obj);
  __Pyx_GOTREF(__pyx_v_self->obj);
  __Pyx_DECREF(__pyx_v_self->obj);
  __pyx_v_self->obj = __pyx_v_obj;

  /* "View.MemoryView":348
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
 *         self.obj = obj
 *         self.flags = flags             # <<<<<<<<<<<<<<
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 */
  __Pyx_TraceLine(348,0,__PYX_ERR(1, 348, __pyx_L1_error))
  __pyx_v_self->flags = __pyx_v_flags;

  /* "View.MemoryView":349
 *         self.obj = obj
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 */
  __Pyx_TraceLine(349,0,__PYX_ERR(1, 349, __pyx_L1_error))
  __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type));
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__pyx_v_obj != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "View.MemoryView":350
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)             # <<<<<<<<<<<<<<
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 */
    __Pyx_TraceLine(350,0,__PYX_ERR(1, 350, __pyx_L1_error))
    __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 350, __pyx_L1_error)

    /* "View.MemoryView":351
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:             # <<<<<<<<<<<<<<
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)
 */
    __Pyx_TraceLine(351,0,__PYX_ERR(1, 351, __pyx_L1_error))
    __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":352
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None             # <<<<<<<<<<<<<<
 *                 Py_INCREF(Py_None)
 * 
 */
      __Pyx_TraceLine(352,0,__PYX_ERR(1, 352, __pyx_L1_error))
      ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None;

      /* "View.MemoryView":353
 *             if <PyObject *> self.view.obj == NULL:
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *         if not __PYX_CYTHON_ATOMICS_ENABLED():
 */
      __Pyx_TraceLine(353,0,__PYX_ERR(1, 353, __pyx_L1_error))
      Py_INCREF(Py_None);

      /* "View.MemoryView":351
 *         if type(self) is memoryview or obj is not None:
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:             # <<<<<<<<<<<<<<
 *                 (<__pyx_buffer *> &self.view).obj = Py_None
 *                 Py_INCREF(Py_None)
 */
    }

    /* "View.MemoryView":349
 *         self.obj = obj
 *         self.flags = flags
 *         if type(self) is memoryview or obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_GetBuffer(obj, &self.view, flags)
 *             if <PyObject *> self.view.obj == NULL:
 */
  }

  /* "View.MemoryView":355
 *                 Py_INCREF(Py_None)
 * 
 *         if not __PYX_CYTHON_ATOMICS_ENABLED():             # <<<<<<<<<<<<<<
 *             global __pyx_memoryview_thread_locks_used
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 */
  __Pyx_TraceLine(355,0,__PYX_ERR(1, 355, __pyx_L1_error))
  __pyx_t_1 = ((!(__PYX_CYTHON_ATOMICS_ENABLED() != 0)) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":357
 *         if not __PYX_CYTHON_ATOMICS_ENABLED():
 *             global __pyx_memoryview_thread_locks_used
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:             # <<<<<<<<<<<<<<
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *                 __pyx_memoryview_thread_locks_used += 1
 */
    __Pyx_TraceLine(357,0,__PYX_ERR(1, 357, __pyx_L1_error))
    __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":358
 *             global __pyx_memoryview_thread_locks_used
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]             # <<<<<<<<<<<<<<
 *                 __pyx_memoryview_thread_locks_used += 1
 *             if self.lock is NULL:
 */
      __Pyx_TraceLine(358,0,__PYX_ERR(1, 358, __pyx_L1_error))
      __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);

      /* "View.MemoryView":359
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *                 __pyx_memoryview_thread_locks_used += 1             # <<<<<<<<<<<<<<
 *             if self.lock is NULL:
 *                 self.lock = PyThread_allocate_lock()
 */
      __Pyx_TraceLine(359,0,__PYX_ERR(1, 359, __pyx_L1_error))
      __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1);

      /* "View.MemoryView":357
 *         if not __PYX_CYTHON_ATOMICS_ENABLED():
 *             global __pyx_memoryview_thread_locks_used
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:             # <<<<<<<<<<<<<<
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *                 __pyx_memoryview_thread_locks_used += 1
 */
    }

    /* "View.MemoryView":360
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *                 __pyx_memoryview_thread_locks_used += 1
 *             if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                 self.lock = PyThread_allocate_lock()
 *                 if self.lock is NULL:
 */
    __Pyx_TraceLine(360,0,__PYX_ERR(1, 360, __pyx_L1_error))
    __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":361
 *                 __pyx_memoryview_thread_locks_used += 1
 *             if self.lock is NULL:
 *                 self.lock = PyThread_allocate_lock()             # <<<<<<<<<<<<<<
 *                 if self.lock is NULL:
 *                     raise MemoryError
 */
      __Pyx_TraceLine(361,0,__PYX_ERR(1, 361, __pyx_L1_error))
      __pyx_v_self->lock = PyThread_allocate_lock();

      /* "View.MemoryView":362
 *             if self.lock is NULL:
 *                 self.lock = PyThread_allocate_lock()
 *                 if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError
 * 
 */
      __Pyx_TraceLine(362,0,__PYX_ERR(1, 362, __pyx_L1_error))
      __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
      if (unlikely(__pyx_t_1)) {

        /* "View.MemoryView":363
 *                 self.lock = PyThread_allocate_lock()
 *                 if self.lock is NULL:
 *                     raise MemoryError             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
        __Pyx_TraceLine(363,0,__PYX_ERR(1, 363, __pyx_L1_error))
        PyErr_NoMemory(); __PYX_ERR(1, 363, __pyx_L1_error)

        /* "View.MemoryView":362
 *             if self.lock is NULL:
 *                 self.lock = PyThread_allocate_lock()
 *                 if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError
 * 
 */
      }

      /* "View.MemoryView":360
 *                 self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
 *                 __pyx_memoryview_thread_locks_used += 1
 *             if self.lock is NULL:             # <<<<<<<<<<<<<<
 *                 self.lock = PyThread_allocate_lock()
 *                 if self.lock is NULL:
 */
    }

    /* "View.MemoryView":355
 *                 Py_INCREF(Py_None)
 * 
 *         if not __PYX_CYTHON_ATOMICS_ENABLED():             # <<<<<<<<<<<<<<
 *             global __pyx_memoryview_thread_locks_used
 *             if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
 */
  }

  /* "View.MemoryView":365
 *                     raise MemoryError
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 */
  __Pyx_TraceLine(365,0,__PYX_ERR(1, 365, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":366
 * 
 *         if flags & PyBUF_FORMAT:
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')             # <<<<<<<<<<<<<<
 *         else:
 *             self.dtype_is_object = dtype_is_object
 */
    __Pyx_TraceLine(366,0,__PYX_ERR(1, 366, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L12_bool_binop_done:;
    __pyx_v_self->dtype_is_object = __pyx_t_1;

    /* "View.MemoryView":365
 *                     raise MemoryError
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 */
    goto __pyx_L11;
  }

  /* "View.MemoryView":368
 *             self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
 *         else:
 *             self.dtype_is_object = dtype_is_object             # <<<<<<<<<<<<<<
 * 
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
 */
  __Pyx_TraceLine(368,0,__PYX_ERR(1, 368, __pyx_L1_error))
  /*else*/ {
    __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object;
  }
  __pyx_L11:;

  /* "View.MemoryView":370
 *             self.dtype_is_object = dtype_is_object
 * 
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(             # <<<<<<<<<<<<<<
 *                   <void *> &self.acquisition_count[0], sizeof(__pyx_atomic_int))
 *         self.typeinfo = NULL
 */
  __Pyx_TraceLine(370,0,__PYX_ERR(1, 370, __pyx_L1_error))
  __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int))));

  /* "View.MemoryView":372
 *         self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
 *                   <void *> &self.acquisition_count[0], sizeof(__pyx_atomic_int))
 *         self.typeinfo = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(memoryview self):
 */
  __Pyx_TraceLine(372,0,__PYX_ERR(1, 372, __pyx_L1_error))
  __pyx_v_self->typeinfo = NULL;

  /* "View.MemoryView":346
 *     cdef __Pyx_TypeInfo *typeinfo
 * 
 *     def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):             # <<<<<<<<<<<<<<
 *         self.obj = obj
 *         self.flags = flags
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":374
 *         self.typeinfo = NULL
 * 
 *     def __dealloc__(memoryview self):             # <<<<<<<<<<<<<<
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 */

/* Python wrapper */
static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) {
  int __pyx_v_i;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyThread_type_lock __pyx_t_6;
  PyThread_type_lock __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[1], 374, 0, __PYX_ERR(1, 374, __pyx_L1_error));

  /* "View.MemoryView":375
 * 
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 */
  __Pyx_TraceLine(375,0,__PYX_ERR(1, 375, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->obj != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":376
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)             # <<<<<<<<<<<<<<
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 * 
 */
    __Pyx_TraceLine(376,0,__PYX_ERR(1, 376, __pyx_L1_error))
    __Pyx_ReleaseBuffer((&__pyx_v_self->view));

    /* "View.MemoryView":375
 * 
 *     def __dealloc__(memoryview self):
 *         if self.obj is not None:             # <<<<<<<<<<<<<<
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":377
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:             # <<<<<<<<<<<<<<
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 */
  __Pyx_TraceLine(377,0,__PYX_ERR(1, 377, __pyx_L1_error))
  __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":379
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL             # <<<<<<<<<<<<<<
 *             Py_DECREF(Py_None)
 * 
 */
    __Pyx_TraceLine(379,0,__PYX_ERR(1, 379, __pyx_L1_error))
    ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL;

    /* "View.MemoryView":380
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 *             Py_DECREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *         cdef int i
 */
    __Pyx_TraceLine(380,0,__PYX_ERR(1, 380, __pyx_L1_error))
    Py_DECREF(Py_None);

    /* "View.MemoryView":377
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 *         elif (<__pyx_buffer *> &self.view).obj == Py_None:             # <<<<<<<<<<<<<<
 * 
 *             (<__pyx_buffer *> &self.view).obj = NULL
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":384
 *         cdef int i
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:             # <<<<<<<<<<<<<<
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 */
  __Pyx_TraceLine(384,0,__PYX_ERR(1, 384, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":385
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):             # <<<<<<<<<<<<<<
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 */
    __Pyx_TraceLine(385,0,__PYX_ERR(1, 385, __pyx_L1_error))
    __pyx_t_3 = __pyx_memoryview_thread_locks_used;
    __pyx_t_4 = __pyx_t_3;
    for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
      __pyx_v_i = __pyx_t_5;

      /* "View.MemoryView":386
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:             # <<<<<<<<<<<<<<
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 */
      __Pyx_TraceLine(386,0,__PYX_ERR(1, 386, __pyx_L1_error))
      __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":387
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1             # <<<<<<<<<<<<<<
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 */
        __Pyx_TraceLine(387,0,__PYX_ERR(1, 387, __pyx_L1_error))
        __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1);

        /* "View.MemoryView":388
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:             # <<<<<<<<<<<<<<
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 */
        __Pyx_TraceLine(388,0,__PYX_ERR(1, 388, __pyx_L1_error))
        __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":390
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])             # <<<<<<<<<<<<<<
 *                     break
 *             else:
 */
          __Pyx_TraceLine(390,0,__PYX_ERR(1, 390, __pyx_L1_error))
          __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
          __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]);

          /* "View.MemoryView":389
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (             # <<<<<<<<<<<<<<
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 *                     break
 */
          __Pyx_TraceLine(389,0,__PYX_ERR(1, 389, __pyx_L1_error))
          (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6;
          (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7;

          /* "View.MemoryView":388
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:             # <<<<<<<<<<<<<<
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 */
        }

        /* "View.MemoryView":391
 *                         __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
 *                             __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
 *                     break             # <<<<<<<<<<<<<<
 *             else:
 *                 PyThread_free_lock(self.lock)
 */
        __Pyx_TraceLine(391,0,__PYX_ERR(1, 391, __pyx_L1_error))
        goto __pyx_L6_break;

        /* "View.MemoryView":386
 *         if self.lock != NULL:
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:             # <<<<<<<<<<<<<<
 *                     __pyx_memoryview_thread_locks_used -= 1
 *                     if i != __pyx_memoryview_thread_locks_used:
 */
      }
    }
    /*else*/ {

      /* "View.MemoryView":393
 *                     break
 *             else:
 *                 PyThread_free_lock(self.lock)             # <<<<<<<<<<<<<<
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:
 */
      __Pyx_TraceLine(393,0,__PYX_ERR(1, 393, __pyx_L1_error))
      PyThread_free_lock(__pyx_v_self->lock);
    }
    __pyx_L6_break:;

    /* "View.MemoryView":384
 *         cdef int i
 *         global __pyx_memoryview_thread_locks_used
 *         if self.lock != NULL:             # <<<<<<<<<<<<<<
 *             for i in range(__pyx_memoryview_thread_locks_used):
 *                 if __pyx_memoryview_thread_locks[i] is self.lock:
 */
  }

  /* "View.MemoryView":374
 *         self.typeinfo = NULL
 * 
 *     def __dealloc__(memoryview self):             # <<<<<<<<<<<<<<
 *         if self.obj is not None:
 *             __Pyx_ReleaseBuffer(&self.view)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.memoryview.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "View.MemoryView":395
 *                 PyThread_free_lock(self.lock)
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf
 */

static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
  Py_ssize_t __pyx_v_dim;
  char *__pyx_v_itemp;
  PyObject *__pyx_v_idx = NULL;
  char *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  char *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_item_pointer", 0);
  __Pyx_TraceCall("get_item_pointer", __pyx_f[1], 395, 0, __PYX_ERR(1, 395, __pyx_L1_error));

  /* "View.MemoryView":397
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf             # <<<<<<<<<<<<<<
 * 
 *         for dim, idx in enumerate(index):
 */
  __Pyx_TraceLine(397,0,__PYX_ERR(1, 397, __pyx_L1_error))
  __pyx_v_itemp = ((char *)__pyx_v_self->view.buf);

  /* "View.MemoryView":399
 *         cdef char *itemp = <char *> self.view.buf
 * 
 *         for dim, idx in enumerate(index):             # <<<<<<<<<<<<<<
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 */
  __Pyx_TraceLine(399,0,__PYX_ERR(1, 399, __pyx_L1_error))
  __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) {
    __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 399, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 399, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 399, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 399, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 399, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 399, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(1, 399, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_v_dim = __pyx_t_1;
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "View.MemoryView":400
 * 
 *         for dim, idx in enumerate(index):
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)             # <<<<<<<<<<<<<<
 * 
 *         return itemp
 */
    __Pyx_TraceLine(400,0,__PYX_ERR(1, 400, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 400, __pyx_L1_error)
    __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(1, 400, __pyx_L1_error)
    __pyx_v_itemp = __pyx_t_7;

    /* "View.MemoryView":399
 *         cdef char *itemp = <char *> self.view.buf
 * 
 *         for dim, idx in enumerate(index):             # <<<<<<<<<<<<<<
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 */
    __Pyx_TraceLine(399,0,__PYX_ERR(1, 399, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":402
 *             itemp = pybuffer_index(&self.view, itemp, idx, dim)
 * 
 *         return itemp             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(402,0,__PYX_ERR(1, 402, __pyx_L1_error))
  __pyx_r = __pyx_v_itemp;
  goto __pyx_L0;

  /* "View.MemoryView":395
 *                 PyThread_free_lock(self.lock)
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":405
 * 
 * 
 *     def __getitem__(memoryview self, object index):             # <<<<<<<<<<<<<<
 *         if index is Ellipsis:
 *             return self
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/
static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
  PyObject *__pyx_v_have_slices = NULL;
  PyObject *__pyx_v_indices = NULL;
  char *__pyx_v_itemp;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  char *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);
  __Pyx_TraceCall("__getitem__", __pyx_f[1], 405, 0, __PYX_ERR(1, 405, __pyx_L1_error));

  /* "View.MemoryView":406
 * 
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:             # <<<<<<<<<<<<<<
 *             return self
 * 
 */
  __Pyx_TraceLine(406,0,__PYX_ERR(1, 406, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":407
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:
 *             return self             # <<<<<<<<<<<<<<
 * 
 *         have_slices, indices = _unellipsify(index, self.view.ndim)
 */
    __Pyx_TraceLine(407,0,__PYX_ERR(1, 407, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = ((PyObject *)__pyx_v_self);
    goto __pyx_L0;

    /* "View.MemoryView":406
 * 
 *     def __getitem__(memoryview self, object index):
 *         if index is Ellipsis:             # <<<<<<<<<<<<<<
 *             return self
 * 
 */
  }

  /* "View.MemoryView":409
 *             return self
 * 
 *         have_slices, indices = _unellipsify(index, self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *         cdef char *itemp
 */
  __Pyx_TraceLine(409,0,__PYX_ERR(1, 409, __pyx_L1_error))
  __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 409, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(__pyx_t_3 != Py_None)) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(1, 409, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 409, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 409, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 409, __pyx_L1_error)
  }
  __pyx_v_have_slices = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_indices = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "View.MemoryView":412
 * 
 *         cdef char *itemp
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             return memview_slice(self, indices)
 *         else:
 */
  __Pyx_TraceLine(412,0,__PYX_ERR(1, 412, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 412, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "View.MemoryView":413
 *         cdef char *itemp
 *         if have_slices:
 *             return memview_slice(self, indices)             # <<<<<<<<<<<<<<
 *         else:
 *             itemp = self.get_item_pointer(indices)
 */
    __Pyx_TraceLine(413,0,__PYX_ERR(1, 413, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 413, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":412
 * 
 *         cdef char *itemp
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             return memview_slice(self, indices)
 *         else:
 */
  }

  /* "View.MemoryView":415
 *             return memview_slice(self, indices)
 *         else:
 *             itemp = self.get_item_pointer(indices)             # <<<<<<<<<<<<<<
 *             return self.convert_item_to_object(itemp)
 * 
 */
  __Pyx_TraceLine(415,0,__PYX_ERR(1, 415, __pyx_L1_error))
  /*else*/ {
    __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(1, 415, __pyx_L1_error)
    __pyx_v_itemp = __pyx_t_6;

    /* "View.MemoryView":416
 *         else:
 *             itemp = self.get_item_pointer(indices)
 *             return self.convert_item_to_object(itemp)             # <<<<<<<<<<<<<<
 * 
 *     def __setitem__(memoryview self, object index, object value):
 */
    __Pyx_TraceLine(416,0,__PYX_ERR(1, 416, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 416, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":405
 * 
 * 
 *     def __getitem__(memoryview self, object index):             # <<<<<<<<<<<<<<
 *         if index is Ellipsis:
 *             return self
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_have_slices);
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":418
 *             return self.convert_item_to_object(itemp)
 * 
 *     def __setitem__(memoryview self, object index, object value):             # <<<<<<<<<<<<<<
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")
 */

/* Python wrapper */
static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/
static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value));

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_have_slices = NULL;
  PyObject *__pyx_v_obj = NULL;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 0);
  __Pyx_TraceCall("__setitem__", __pyx_f[1], 418, 0, __PYX_ERR(1, 418, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_index);

  /* "View.MemoryView":419
 * 
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 */
  __Pyx_TraceLine(419,0,__PYX_ERR(1, 419, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->view.readonly != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":420
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 */
    __Pyx_TraceLine(420,0,__PYX_ERR(1, 420, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 420, __pyx_L1_error)

    /* "View.MemoryView":419
 * 
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 */
  }

  /* "View.MemoryView":422
 *             raise TypeError("Cannot assign to read-only memoryview")
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *         if have_slices:
 */
  __Pyx_TraceLine(422,0,__PYX_ERR(1, 422, __pyx_L1_error))
  __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(__pyx_t_2 != Py_None)) {
    PyObject* sequence = __pyx_t_2;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(1, 422, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 422, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 422, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 422, __pyx_L1_error)
  }
  __pyx_v_have_slices = __pyx_t_3;
  __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "View.MemoryView":424
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 * 
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             obj = self.is_slice(value)
 *             if obj:
 */
  __Pyx_TraceLine(424,0,__PYX_ERR(1, 424, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 424, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "View.MemoryView":425
 * 
 *         if have_slices:
 *             obj = self.is_slice(value)             # <<<<<<<<<<<<<<
 *             if obj:
 *                 self.setitem_slice_assignment(self[index], obj)
 */
    __Pyx_TraceLine(425,0,__PYX_ERR(1, 425, __pyx_L1_error))
    __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 425, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_obj = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "View.MemoryView":426
 *         if have_slices:
 *             obj = self.is_slice(value)
 *             if obj:             # <<<<<<<<<<<<<<
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 */
    __Pyx_TraceLine(426,0,__PYX_ERR(1, 426, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 426, __pyx_L1_error)
    if (__pyx_t_1) {

      /* "View.MemoryView":427
 *             obj = self.is_slice(value)
 *             if obj:
 *                 self.setitem_slice_assignment(self[index], obj)             # <<<<<<<<<<<<<<
 *             else:
 *                 self.setitem_slice_assign_scalar(self[index], value)
 */
      __Pyx_TraceLine(427,0,__PYX_ERR(1, 427, __pyx_L1_error))
      __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 427, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 427, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "View.MemoryView":426
 *         if have_slices:
 *             obj = self.is_slice(value)
 *             if obj:             # <<<<<<<<<<<<<<
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 */
      goto __pyx_L5;
    }

    /* "View.MemoryView":429
 *                 self.setitem_slice_assignment(self[index], obj)
 *             else:
 *                 self.setitem_slice_assign_scalar(self[index], value)             # <<<<<<<<<<<<<<
 *         else:
 *             self.setitem_indexed(index, value)
 */
    __Pyx_TraceLine(429,0,__PYX_ERR(1, 429, __pyx_L1_error))
    /*else*/ {
      __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 429, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(1, 429, __pyx_L1_error)
      __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 429, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_L5:;

    /* "View.MemoryView":424
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 * 
 *         if have_slices:             # <<<<<<<<<<<<<<
 *             obj = self.is_slice(value)
 *             if obj:
 */
    goto __pyx_L4;
  }

  /* "View.MemoryView":431
 *                 self.setitem_slice_assign_scalar(self[index], value)
 *         else:
 *             self.setitem_indexed(index, value)             # <<<<<<<<<<<<<<
 * 
 *     cdef is_slice(self, obj):
 */
  __Pyx_TraceLine(431,0,__PYX_ERR(1, 431, __pyx_L1_error))
  /*else*/ {
    __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L4:;

  /* "View.MemoryView":418
 *             return self.convert_item_to_object(itemp)
 * 
 *     def __setitem__(memoryview self, object index, object value):             # <<<<<<<<<<<<<<
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_have_slices);
  __Pyx_XDECREF(__pyx_v_obj);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":433
 *             self.setitem_indexed(index, value)
 * 
 *     cdef is_slice(self, obj):             # <<<<<<<<<<<<<<
 *         if not isinstance(obj, memoryview):
 *             try:
 */

static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_slice", 0);
  __Pyx_TraceCall("is_slice", __pyx_f[1], 433, 0, __PYX_ERR(1, 433, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_obj);

  /* "View.MemoryView":434
 * 
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):             # <<<<<<<<<<<<<<
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 */
  __Pyx_TraceLine(434,0,__PYX_ERR(1, 434, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); 
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":435
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
    __Pyx_TraceLine(435,0,__PYX_ERR(1, 435, __pyx_L1_error))
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "View.MemoryView":436
 *         if not isinstance(obj, memoryview):
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,             # <<<<<<<<<<<<<<
 *                                  self.dtype_is_object)
 *             except TypeError:
 */
        __Pyx_TraceLine(436,0,__PYX_ERR(1, 436, __pyx_L4_error))
        __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 436, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "View.MemoryView":437
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)             # <<<<<<<<<<<<<<
 *             except TypeError:
 *                 return None
 */
        __Pyx_TraceLine(437,0,__PYX_ERR(1, 437, __pyx_L4_error))
        __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 437, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);

        /* "View.MemoryView":436
 *         if not isinstance(obj, memoryview):
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,             # <<<<<<<<<<<<<<
 *                                  self.dtype_is_object)
 *             except TypeError:
 */
        __Pyx_TraceLine(436,0,__PYX_ERR(1, 436, __pyx_L4_error))
        __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 436, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
        __pyx_t_6 = 0;
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 436, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "View.MemoryView":435
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "View.MemoryView":438
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 *             except TypeError:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
      __Pyx_TraceLine(438,0,__PYX_ERR(1, 438, __pyx_L6_except_error))
      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
      if (__pyx_t_9) {
        __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(1, 438, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_6);

        /* "View.MemoryView":439
 *                                  self.dtype_is_object)
 *             except TypeError:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *         return obj
 */
        __Pyx_TraceLine(439,0,__PYX_ERR(1, 439, __pyx_L6_except_error))
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_except_return;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "View.MemoryView":435
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):
 *             try:             # <<<<<<<<<<<<<<
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 *                                  self.dtype_is_object)
 */
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L7_except_return:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L0;
      __pyx_L9_try_end:;
    }

    /* "View.MemoryView":434
 * 
 *     cdef is_slice(self, obj):
 *         if not isinstance(obj, memoryview):             # <<<<<<<<<<<<<<
 *             try:
 *                 obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
 */
  }

  /* "View.MemoryView":441
 *                 return None
 * 
 *         return obj             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_slice_assignment(self, dst, src):
 */
  __Pyx_TraceLine(441,0,__PYX_ERR(1, 441, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_obj);
  __pyx_r = __pyx_v_obj;
  goto __pyx_L0;

  /* "View.MemoryView":433
 *             self.setitem_indexed(index, value)
 * 
 *     cdef is_slice(self, obj):             # <<<<<<<<<<<<<<
 *         if not isinstance(obj, memoryview):
 *             try:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_obj);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":443
 *         return obj
 * 
 *     cdef setitem_slice_assignment(self, dst, src):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice dst_slice
 *         cdef __Pyx_memviewslice src_slice
 */

static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) {
  __Pyx_memviewslice __pyx_v_dst_slice;
  __Pyx_memviewslice __pyx_v_src_slice;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  __Pyx_memviewslice *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_slice_assignment", 0);
  __Pyx_TraceCall("setitem_slice_assignment", __pyx_f[1], 443, 0, __PYX_ERR(1, 443, __pyx_L1_error));

  /* "View.MemoryView":447
 *         cdef __Pyx_memviewslice src_slice
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],             # <<<<<<<<<<<<<<
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 */
  __Pyx_TraceLine(447,0,__PYX_ERR(1, 447, __pyx_L1_error))
  if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(1, 447, __pyx_L1_error)
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 447, __pyx_L1_error)

  /* "View.MemoryView":448
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
 *                                  get_slice_from_memview(dst, &dst_slice)[0],             # <<<<<<<<<<<<<<
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 */
  __Pyx_TraceLine(448,0,__PYX_ERR(1, 448, __pyx_L1_error))
  if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(1, 448, __pyx_L1_error)
  __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 448, __pyx_L1_error)

  /* "View.MemoryView":449
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):
 */
  __Pyx_TraceLine(449,0,__PYX_ERR(1, 449, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 449, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 449, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":447
 *         cdef __Pyx_memviewslice src_slice
 * 
 *         memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],             # <<<<<<<<<<<<<<
 *                                  get_slice_from_memview(dst, &dst_slice)[0],
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 */
  __Pyx_TraceLine(447,0,__PYX_ERR(1, 447, __pyx_L1_error))
  __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 447, __pyx_L1_error)

  /* "View.MemoryView":443
 *         return obj
 * 
 *     cdef setitem_slice_assignment(self, dst, src):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice dst_slice
 *         cdef __Pyx_memviewslice src_slice
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":451
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):             # <<<<<<<<<<<<<<
 *         cdef int array[128]
 *         cdef void *tmp = NULL
 */

static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) {
  int __pyx_v_array[0x80];
  void *__pyx_v_tmp;
  void *__pyx_v_item;
  __Pyx_memviewslice *__pyx_v_dst_slice;
  __Pyx_memviewslice __pyx_v_tmp_slice;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  char const *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0);
  __Pyx_TraceCall("setitem_slice_assign_scalar", __pyx_f[1], 451, 0, __PYX_ERR(1, 451, __pyx_L1_error));

  /* "View.MemoryView":453
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):
 *         cdef int array[128]
 *         cdef void *tmp = NULL             # <<<<<<<<<<<<<<
 *         cdef void *item
 * 
 */
  __Pyx_TraceLine(453,0,__PYX_ERR(1, 453, __pyx_L1_error))
  __pyx_v_tmp = NULL;

  /* "View.MemoryView":458
 *         cdef __Pyx_memviewslice *dst_slice
 *         cdef __Pyx_memviewslice tmp_slice
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)             # <<<<<<<<<<<<<<
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):
 */
  __Pyx_TraceLine(458,0,__PYX_ERR(1, 458, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 458, __pyx_L1_error)
  __pyx_v_dst_slice = __pyx_t_1;

  /* "View.MemoryView":460
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):             # <<<<<<<<<<<<<<
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 */
  __Pyx_TraceLine(460,0,__PYX_ERR(1, 460, __pyx_L1_error))
  __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":461
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)             # <<<<<<<<<<<<<<
 *             if tmp == NULL:
 *                 raise MemoryError
 */
    __Pyx_TraceLine(461,0,__PYX_ERR(1, 461, __pyx_L1_error))
    __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize);

    /* "View.MemoryView":462
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 *             item = tmp
 */
    __Pyx_TraceLine(462,0,__PYX_ERR(1, 462, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "View.MemoryView":463
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 *                 raise MemoryError             # <<<<<<<<<<<<<<
 *             item = tmp
 *         else:
 */
      __Pyx_TraceLine(463,0,__PYX_ERR(1, 463, __pyx_L1_error))
      PyErr_NoMemory(); __PYX_ERR(1, 463, __pyx_L1_error)

      /* "View.MemoryView":462
 *         if <size_t>self.view.itemsize > sizeof(array):
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError
 *             item = tmp
 */
    }

    /* "View.MemoryView":464
 *             if tmp == NULL:
 *                 raise MemoryError
 *             item = tmp             # <<<<<<<<<<<<<<
 *         else:
 *             item = <void *> array
 */
    __Pyx_TraceLine(464,0,__PYX_ERR(1, 464, __pyx_L1_error))
    __pyx_v_item = __pyx_v_tmp;

    /* "View.MemoryView":460
 *         dst_slice = get_slice_from_memview(dst, &tmp_slice)
 * 
 *         if <size_t>self.view.itemsize > sizeof(array):             # <<<<<<<<<<<<<<
 *             tmp = PyMem_Malloc(self.view.itemsize)
 *             if tmp == NULL:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":466
 *             item = tmp
 *         else:
 *             item = <void *> array             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  __Pyx_TraceLine(466,0,__PYX_ERR(1, 466, __pyx_L1_error))
  /*else*/ {
    __pyx_v_item = ((void *)__pyx_v_array);
  }
  __pyx_L3:;

  /* "View.MemoryView":468
 *             item = <void *> array
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             if self.dtype_is_object:
 *                 (<PyObject **> item)[0] = <PyObject *> value
 */
  __Pyx_TraceLine(468,0,__PYX_ERR(1, 468, __pyx_L1_error))
  /*try:*/ {

    /* "View.MemoryView":469
 * 
 *         try:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 */
    __Pyx_TraceLine(469,0,__PYX_ERR(1, 469, __pyx_L6_error))
    __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":470
 *         try:
 *             if self.dtype_is_object:
 *                 (<PyObject **> item)[0] = <PyObject *> value             # <<<<<<<<<<<<<<
 *             else:
 *                 self.assign_item_from_object(<char *> item, value)
 */
      __Pyx_TraceLine(470,0,__PYX_ERR(1, 470, __pyx_L6_error))
      (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value);

      /* "View.MemoryView":469
 * 
 *         try:
 *             if self.dtype_is_object:             # <<<<<<<<<<<<<<
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 */
      goto __pyx_L8;
    }

    /* "View.MemoryView":472
 *                 (<PyObject **> item)[0] = <PyObject *> value
 *             else:
 *                 self.assign_item_from_object(<char *> item, value)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(472,0,__PYX_ERR(1, 472, __pyx_L6_error))
    /*else*/ {
      __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 472, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_L8:;

    /* "View.MemoryView":476
 * 
 * 
 *             if self.view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 */
    __Pyx_TraceLine(476,0,__PYX_ERR(1, 476, __pyx_L6_error))
    __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":477
 * 
 *             if self.view.suboffsets != NULL:
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)             # <<<<<<<<<<<<<<
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 *                                 item, self.dtype_is_object)
 */
      __Pyx_TraceLine(477,0,__PYX_ERR(1, 477, __pyx_L6_error))
      __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 477, __pyx_L6_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "View.MemoryView":476
 * 
 * 
 *             if self.view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
 */
    }

    /* "View.MemoryView":478
 *             if self.view.suboffsets != NULL:
 *                 assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
 *             slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,             # <<<<<<<<<<<<<<
 *                                 item, self.dtype_is_object)
 *         finally:
 */
    __Pyx_TraceLine(478,0,__PYX_ERR(1, 478, __pyx_L6_error))
    __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object);
  }

  /* "View.MemoryView":481
 *                                 item, self.dtype_is_object)
 *         finally:
 *             PyMem_Free(tmp)             # <<<<<<<<<<<<<<
 * 
 *     cdef setitem_indexed(self, index, value):
 */
  __Pyx_TraceLine(481,0,__PYX_ERR(1, 481, __pyx_L6_error))
  /*finally:*/ {
    /*normal exit:*/{
      PyMem_Free(__pyx_v_tmp);
      goto __pyx_L7;
    }
    __pyx_L6_error:;
    /*exception exit:*/{
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
      {
        PyMem_Free(__pyx_v_tmp);
      }
      if (PY_MAJOR_VERSION >= 3) {
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
      __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
      goto __pyx_L1_error;
    }
    __pyx_L7:;
  }

  /* "View.MemoryView":451
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):             # <<<<<<<<<<<<<<
 *         cdef int array[128]
 *         cdef void *tmp = NULL
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":483
 *             PyMem_Free(tmp)
 * 
 *     cdef setitem_indexed(self, index, value):             # <<<<<<<<<<<<<<
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)
 */

static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
  char *__pyx_v_itemp;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  char *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setitem_indexed", 0);
  __Pyx_TraceCall("setitem_indexed", __pyx_f[1], 483, 0, __PYX_ERR(1, 483, __pyx_L1_error));

  /* "View.MemoryView":484
 * 
 *     cdef setitem_indexed(self, index, value):
 *         cdef char *itemp = self.get_item_pointer(index)             # <<<<<<<<<<<<<<
 *         self.assign_item_from_object(itemp, value)
 * 
 */
  __Pyx_TraceLine(484,0,__PYX_ERR(1, 484, __pyx_L1_error))
  __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(1, 484, __pyx_L1_error)
  __pyx_v_itemp = __pyx_t_1;

  /* "View.MemoryView":485
 *     cdef setitem_indexed(self, index, value):
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)             # <<<<<<<<<<<<<<
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 */
  __Pyx_TraceLine(485,0,__PYX_ERR(1, 485, __pyx_L1_error))
  __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":483
 *             PyMem_Free(tmp)
 * 
 *     cdef setitem_indexed(self, index, value):             # <<<<<<<<<<<<<<
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":487
 *         self.assign_item_from_object(itemp, value)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) {
  PyObject *__pyx_v_struct = NULL;
  PyObject *__pyx_v_bytesitem = 0;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  size_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_item_to_object", 0);
  __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 487, 0, __PYX_ERR(1, 487, __pyx_L1_error));

  /* "View.MemoryView":490
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 *         import struct             # <<<<<<<<<<<<<<
 *         cdef bytes bytesitem
 * 
 */
  __Pyx_TraceLine(490,0,__PYX_ERR(1, 490, __pyx_L1_error))
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_struct = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "View.MemoryView":493
 *         cdef bytes bytesitem
 * 
 *         bytesitem = itemp[:self.view.itemsize]             # <<<<<<<<<<<<<<
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)
 */
  __Pyx_TraceLine(493,0,__PYX_ERR(1, 493, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_bytesitem = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "View.MemoryView":494
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
  __Pyx_TraceLine(494,0,__PYX_ERR(1, 494, __pyx_L1_error))
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "View.MemoryView":495
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)             # <<<<<<<<<<<<<<
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")
 */
      __Pyx_TraceLine(495,0,__PYX_ERR(1, 495, __pyx_L3_error))
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 495, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 495, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 495, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 495, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 495, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
        __Pyx_INCREF(__pyx_v_bytesitem);
        __Pyx_GIVEREF(__pyx_v_bytesitem);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem);
        __pyx_t_6 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 495, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_result = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "View.MemoryView":494
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
    }

    /* "View.MemoryView":499
 *             raise ValueError("Unable to convert item to object")
 *         else:
 *             if len(self.view.format) == 1:             # <<<<<<<<<<<<<<
 *                 return result[0]
 *             return result
 */
    __Pyx_TraceLine(499,0,__PYX_ERR(1, 499, __pyx_L5_except_error))
    /*else:*/ {
      __pyx_t_10 = strlen(__pyx_v_self->view.format); 
      __pyx_t_11 = ((__pyx_t_10 == 1) != 0);
      if (__pyx_t_11) {

        /* "View.MemoryView":500
 *         else:
 *             if len(self.view.format) == 1:
 *                 return result[0]             # <<<<<<<<<<<<<<
 *             return result
 * 
 */
        __Pyx_TraceLine(500,0,__PYX_ERR(1, 500, __pyx_L5_except_error))
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 500, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L6_except_return;

        /* "View.MemoryView":499
 *             raise ValueError("Unable to convert item to object")
 *         else:
 *             if len(self.view.format) == 1:             # <<<<<<<<<<<<<<
 *                 return result[0]
 *             return result
 */
      }

      /* "View.MemoryView":501
 *             if len(self.view.format) == 1:
 *                 return result[0]
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 */
      __Pyx_TraceLine(501,0,__PYX_ERR(1, 501, __pyx_L5_except_error))
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_result);
      __pyx_r = __pyx_v_result;
      goto __pyx_L6_except_return;
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "View.MemoryView":496
 *         try:
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:             # <<<<<<<<<<<<<<
 *             raise ValueError("Unable to convert item to object")
 *         else:
 */
    __Pyx_TraceLine(496,0,__PYX_ERR(1, 496, __pyx_L5_except_error))
    __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 496, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9);
    __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0;
    if (__pyx_t_8) {
      __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(1, 496, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_1);

      /* "View.MemoryView":497
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")             # <<<<<<<<<<<<<<
 *         else:
 *             if len(self.view.format) == 1:
 */
      __Pyx_TraceLine(497,0,__PYX_ERR(1, 497, __pyx_L5_except_error))
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 497, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(1, 497, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "View.MemoryView":494
 * 
 *         bytesitem = itemp[:self.view.itemsize]
 *         try:             # <<<<<<<<<<<<<<
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 */
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L0;
  }

  /* "View.MemoryView":487
 *         self.assign_item_from_object(itemp, value)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_struct);
  __Pyx_XDECREF(__pyx_v_bytesitem);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":503
 *             return result
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
  PyObject *__pyx_v_struct = NULL;
  char __pyx_v_c;
  PyObject *__pyx_v_bytesvalue = 0;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  char *__pyx_t_11;
  char *__pyx_t_12;
  char *__pyx_t_13;
  char *__pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assign_item_from_object", 0);
  __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 503, 0, __PYX_ERR(1, 503, __pyx_L1_error));

  /* "View.MemoryView":506
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 *         import struct             # <<<<<<<<<<<<<<
 *         cdef char c
 *         cdef bytes bytesvalue
 */
  __Pyx_TraceLine(506,0,__PYX_ERR(1, 506, __pyx_L1_error))
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_struct = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "View.MemoryView":511
 *         cdef Py_ssize_t i
 * 
 *         if isinstance(value, tuple):             # <<<<<<<<<<<<<<
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 */
  __Pyx_TraceLine(511,0,__PYX_ERR(1, 511, __pyx_L1_error))
  __pyx_t_2 = PyTuple_Check(__pyx_v_value); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "View.MemoryView":512
 * 
 *         if isinstance(value, tuple):
 *             bytesvalue = struct.pack(self.view.format, *value)             # <<<<<<<<<<<<<<
 *         else:
 *             bytesvalue = struct.pack(self.view.format, value)
 */
    __Pyx_TraceLine(512,0,__PYX_ERR(1, 512, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 512, __pyx_L1_error)
    __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "View.MemoryView":511
 *         cdef Py_ssize_t i
 * 
 *         if isinstance(value, tuple):             # <<<<<<<<<<<<<<
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":514
 *             bytesvalue = struct.pack(self.view.format, *value)
 *         else:
 *             bytesvalue = struct.pack(self.view.format, value)             # <<<<<<<<<<<<<<
 * 
 *         for i, c in enumerate(bytesvalue):
 */
  __Pyx_TraceLine(514,0,__PYX_ERR(1, 514, __pyx_L1_error))
  /*else*/ {
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 514, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 514, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 514, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 514, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value);
      __pyx_t_1 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 514, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 514, __pyx_L1_error)
    __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
  }
  __pyx_L3:;

  /* "View.MemoryView":516
 *             bytesvalue = struct.pack(self.view.format, value)
 * 
 *         for i, c in enumerate(bytesvalue):             # <<<<<<<<<<<<<<
 *             itemp[i] = c
 * 
 */
  __Pyx_TraceLine(516,0,__PYX_ERR(1, 516, __pyx_L1_error))
  __pyx_t_9 = 0;
  if (unlikely(__pyx_v_bytesvalue == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
    __PYX_ERR(1, 516, __pyx_L1_error)
  }
  __Pyx_INCREF(__pyx_v_bytesvalue);
  __pyx_t_10 = __pyx_v_bytesvalue;
  __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10);
  __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10));
  for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) {
    __pyx_t_11 = __pyx_t_14;
    __pyx_v_c = (__pyx_t_11[0]);

    /* "View.MemoryView":517
 * 
 *         for i, c in enumerate(bytesvalue):
 *             itemp[i] = c             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
    __Pyx_TraceLine(517,0,__PYX_ERR(1, 517, __pyx_L1_error))
    __pyx_v_i = __pyx_t_9;

    /* "View.MemoryView":516
 *             bytesvalue = struct.pack(self.view.format, value)
 * 
 *         for i, c in enumerate(bytesvalue):             # <<<<<<<<<<<<<<
 *             itemp[i] = c
 * 
 */
    __Pyx_TraceLine(516,0,__PYX_ERR(1, 516, __pyx_L1_error))
    __pyx_t_9 = (__pyx_t_9 + 1);

    /* "View.MemoryView":517
 * 
 *         for i, c in enumerate(bytesvalue):
 *             itemp[i] = c             # <<<<<<<<<<<<<<
 * 
 *     @cname('getbuffer')
 */
    __Pyx_TraceLine(517,0,__PYX_ERR(1, 517, __pyx_L1_error))
    (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c;
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "View.MemoryView":503
 *             return result
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_struct);
  __Pyx_XDECREF(__pyx_v_bytesvalue);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":520
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t *__pyx_t_4;
  char *__pyx_t_5;
  void *__pyx_t_6;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);
  __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 520, 0, __PYX_ERR(1, 520, __pyx_L1_error));

  /* "View.MemoryView":521
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 */
  __Pyx_TraceLine(521,0,__PYX_ERR(1, 521, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->view.readonly != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":522
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_ND:
 */
    __Pyx_TraceLine(522,0,__PYX_ERR(1, 522, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 522, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 522, __pyx_L1_error)

    /* "View.MemoryView":521
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 */
  }

  /* "View.MemoryView":524
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 *         if flags & PyBUF_ND:             # <<<<<<<<<<<<<<
 *             info.shape = self.view.shape
 *         else:
 */
  __Pyx_TraceLine(524,0,__PYX_ERR(1, 524, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":525
 * 
 *         if flags & PyBUF_ND:
 *             info.shape = self.view.shape             # <<<<<<<<<<<<<<
 *         else:
 *             info.shape = NULL
 */
    __Pyx_TraceLine(525,0,__PYX_ERR(1, 525, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->view.shape;
    __pyx_v_info->shape = __pyx_t_4;

    /* "View.MemoryView":524
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 * 
 *         if flags & PyBUF_ND:             # <<<<<<<<<<<<<<
 *             info.shape = self.view.shape
 *         else:
 */
    goto __pyx_L6;
  }

  /* "View.MemoryView":527
 *             info.shape = self.view.shape
 *         else:
 *             info.shape = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_STRIDES:
 */
  __Pyx_TraceLine(527,0,__PYX_ERR(1, 527, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->shape = NULL;
  }
  __pyx_L6:;

  /* "View.MemoryView":529
 *             info.shape = NULL
 * 
 *         if flags & PyBUF_STRIDES:             # <<<<<<<<<<<<<<
 *             info.strides = self.view.strides
 *         else:
 */
  __Pyx_TraceLine(529,0,__PYX_ERR(1, 529, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":530
 * 
 *         if flags & PyBUF_STRIDES:
 *             info.strides = self.view.strides             # <<<<<<<<<<<<<<
 *         else:
 *             info.strides = NULL
 */
    __Pyx_TraceLine(530,0,__PYX_ERR(1, 530, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->view.strides;
    __pyx_v_info->strides = __pyx_t_4;

    /* "View.MemoryView":529
 *             info.shape = NULL
 * 
 *         if flags & PyBUF_STRIDES:             # <<<<<<<<<<<<<<
 *             info.strides = self.view.strides
 *         else:
 */
    goto __pyx_L7;
  }

  /* "View.MemoryView":532
 *             info.strides = self.view.strides
 *         else:
 *             info.strides = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_INDIRECT:
 */
  __Pyx_TraceLine(532,0,__PYX_ERR(1, 532, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->strides = NULL;
  }
  __pyx_L7:;

  /* "View.MemoryView":534
 *             info.strides = NULL
 * 
 *         if flags & PyBUF_INDIRECT:             # <<<<<<<<<<<<<<
 *             info.suboffsets = self.view.suboffsets
 *         else:
 */
  __Pyx_TraceLine(534,0,__PYX_ERR(1, 534, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":535
 * 
 *         if flags & PyBUF_INDIRECT:
 *             info.suboffsets = self.view.suboffsets             # <<<<<<<<<<<<<<
 *         else:
 *             info.suboffsets = NULL
 */
    __Pyx_TraceLine(535,0,__PYX_ERR(1, 535, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_self->view.suboffsets;
    __pyx_v_info->suboffsets = __pyx_t_4;

    /* "View.MemoryView":534
 *             info.strides = NULL
 * 
 *         if flags & PyBUF_INDIRECT:             # <<<<<<<<<<<<<<
 *             info.suboffsets = self.view.suboffsets
 *         else:
 */
    goto __pyx_L8;
  }

  /* "View.MemoryView":537
 *             info.suboffsets = self.view.suboffsets
 *         else:
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_FORMAT:
 */
  __Pyx_TraceLine(537,0,__PYX_ERR(1, 537, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->suboffsets = NULL;
  }
  __pyx_L8:;

  /* "View.MemoryView":539
 *             info.suboffsets = NULL
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.view.format
 *         else:
 */
  __Pyx_TraceLine(539,0,__PYX_ERR(1, 539, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":540
 * 
 *         if flags & PyBUF_FORMAT:
 *             info.format = self.view.format             # <<<<<<<<<<<<<<
 *         else:
 *             info.format = NULL
 */
    __Pyx_TraceLine(540,0,__PYX_ERR(1, 540, __pyx_L1_error))
    __pyx_t_5 = __pyx_v_self->view.format;
    __pyx_v_info->format = __pyx_t_5;

    /* "View.MemoryView":539
 *             info.suboffsets = NULL
 * 
 *         if flags & PyBUF_FORMAT:             # <<<<<<<<<<<<<<
 *             info.format = self.view.format
 *         else:
 */
    goto __pyx_L9;
  }

  /* "View.MemoryView":542
 *             info.format = self.view.format
 *         else:
 *             info.format = NULL             # <<<<<<<<<<<<<<
 * 
 *         info.buf = self.view.buf
 */
  __Pyx_TraceLine(542,0,__PYX_ERR(1, 542, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->format = NULL;
  }
  __pyx_L9:;

  /* "View.MemoryView":544
 *             info.format = NULL
 * 
 *         info.buf = self.view.buf             # <<<<<<<<<<<<<<
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize
 */
  __Pyx_TraceLine(544,0,__PYX_ERR(1, 544, __pyx_L1_error))
  __pyx_t_6 = __pyx_v_self->view.buf;
  __pyx_v_info->buf = __pyx_t_6;

  /* "View.MemoryView":545
 * 
 *         info.buf = self.view.buf
 *         info.ndim = self.view.ndim             # <<<<<<<<<<<<<<
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len
 */
  __Pyx_TraceLine(545,0,__PYX_ERR(1, 545, __pyx_L1_error))
  __pyx_t_7 = __pyx_v_self->view.ndim;
  __pyx_v_info->ndim = __pyx_t_7;

  /* "View.MemoryView":546
 *         info.buf = self.view.buf
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize             # <<<<<<<<<<<<<<
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly
 */
  __Pyx_TraceLine(546,0,__PYX_ERR(1, 546, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_self->view.itemsize;
  __pyx_v_info->itemsize = __pyx_t_8;

  /* "View.MemoryView":547
 *         info.ndim = self.view.ndim
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len             # <<<<<<<<<<<<<<
 *         info.readonly = self.view.readonly
 *         info.obj = self
 */
  __Pyx_TraceLine(547,0,__PYX_ERR(1, 547, __pyx_L1_error))
  __pyx_t_8 = __pyx_v_self->view.len;
  __pyx_v_info->len = __pyx_t_8;

  /* "View.MemoryView":548
 *         info.itemsize = self.view.itemsize
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly             # <<<<<<<<<<<<<<
 *         info.obj = self
 * 
 */
  __Pyx_TraceLine(548,0,__PYX_ERR(1, 548, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_self->view.readonly;
  __pyx_v_info->readonly = __pyx_t_1;

  /* "View.MemoryView":549
 *         info.len = self.view.len
 *         info.readonly = self.view.readonly
 *         info.obj = self             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_TraceLine(549,0,__PYX_ERR(1, 549, __pyx_L1_error))
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "View.MemoryView":520
 * 
 *     @cname('getbuffer')
 *     def __getbuffer__(self, Py_buffer *info, int flags):             # <<<<<<<<<<<<<<
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":555
 * 
 *     @property
 *     def T(self):             # <<<<<<<<<<<<<<
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 555, 0, __PYX_ERR(1, 555, __pyx_L1_error));

  /* "View.MemoryView":556
 *     @property
 *     def T(self):
 *         cdef _memoryviewslice result = memoryview_copy(self)             # <<<<<<<<<<<<<<
 *         transpose_memslice(&result.from_slice)
 *         return result
 */
  __Pyx_TraceLine(556,0,__PYX_ERR(1, 556, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 556, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(1, 556, __pyx_L1_error)
  __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "View.MemoryView":557
 *     def T(self):
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __Pyx_TraceLine(557,0,__PYX_ERR(1, 557, __pyx_L1_error))
  __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 557, __pyx_L1_error)

  /* "View.MemoryView":558
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(558,0,__PYX_ERR(1, 558, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":555
 * 
 *     @property
 *     def T(self):             # <<<<<<<<<<<<<<
 *         cdef _memoryviewslice result = memoryview_copy(self)
 *         transpose_memslice(&result.from_slice)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":561
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.obj
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 561, 0, __PYX_ERR(1, 561, __pyx_L1_error));

  /* "View.MemoryView":562
 *     @property
 *     def base(self):
 *         return self.obj             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(562,0,__PYX_ERR(1, 562, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->obj);
  __pyx_r = __pyx_v_self->obj;
  goto __pyx_L0;

  /* "View.MemoryView":561
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.obj
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":565
 * 
 *     @property
 *     def shape(self):             # <<<<<<<<<<<<<<
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_length;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 565, 0, __PYX_ERR(1, 565, __pyx_L1_error));

  /* "View.MemoryView":566
 *     @property
 *     def shape(self):
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(566,0,__PYX_ERR(1, 566, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
  for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_2 = __pyx_t_4;
    __pyx_v_length = (__pyx_t_2[0]);
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 566, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 566, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":565
 * 
 *     @property
 *     def shape(self):             # <<<<<<<<<<<<<<
 *         return tuple([length for length in self.view.shape[:self.view.ndim]])
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":569
 * 
 *     @property
 *     def strides(self):             # <<<<<<<<<<<<<<
 *         if self.view.strides == NULL:
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_stride;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 569, 0, __PYX_ERR(1, 569, __pyx_L1_error));

  /* "View.MemoryView":570
 *     @property
 *     def strides(self):
 *         if self.view.strides == NULL:             # <<<<<<<<<<<<<<
 * 
 *             raise ValueError("Buffer view does not expose strides")
 */
  __Pyx_TraceLine(570,0,__PYX_ERR(1, 570, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":572
 *         if self.view.strides == NULL:
 * 
 *             raise ValueError("Buffer view does not expose strides")             # <<<<<<<<<<<<<<
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])
 */
    __Pyx_TraceLine(572,0,__PYX_ERR(1, 572, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 572, __pyx_L1_error)

    /* "View.MemoryView":570
 *     @property
 *     def strides(self):
 *         if self.view.strides == NULL:             # <<<<<<<<<<<<<<
 * 
 *             raise ValueError("Buffer view does not expose strides")
 */
  }

  /* "View.MemoryView":574
 *             raise ValueError("Buffer view does not expose strides")
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(574,0,__PYX_ERR(1, 574, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim);
  for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
    __pyx_t_3 = __pyx_t_5;
    __pyx_v_stride = (__pyx_t_3[0]);
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 574, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":569
 * 
 *     @property
 *     def strides(self):             # <<<<<<<<<<<<<<
 *         if self.view.strides == NULL:
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":577
 * 
 *     @property
 *     def suboffsets(self):             # <<<<<<<<<<<<<<
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  Py_ssize_t *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 577, 0, __PYX_ERR(1, 577, __pyx_L1_error));

  /* "View.MemoryView":578
 *     @property
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:             # <<<<<<<<<<<<<<
 *             return (-1,) * self.view.ndim
 * 
 */
  __Pyx_TraceLine(578,0,__PYX_ERR(1, 578, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":579
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim             # <<<<<<<<<<<<<<
 * 
 *         return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
 */
    __Pyx_TraceLine(579,0,__PYX_ERR(1, 579, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__44, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":578
 *     @property
 *     def suboffsets(self):
 *         if self.view.suboffsets == NULL:             # <<<<<<<<<<<<<<
 *             return (-1,) * self.view.ndim
 * 
 */
  }

  /* "View.MemoryView":581
 *             return (-1,) * self.view.ndim
 * 
 *         return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(581,0,__PYX_ERR(1, 581, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim);
  for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
    __pyx_t_4 = __pyx_t_6;
    __pyx_v_suboffset = (__pyx_t_4[0]);
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 581, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 581, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":577
 * 
 *     @property
 *     def suboffsets(self):             # <<<<<<<<<<<<<<
 *         if self.view.suboffsets == NULL:
 *             return (-1,) * self.view.ndim
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":584
 * 
 *     @property
 *     def ndim(self):             # <<<<<<<<<<<<<<
 *         return self.view.ndim
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 584, 0, __PYX_ERR(1, 584, __pyx_L1_error));

  /* "View.MemoryView":585
 *     @property
 *     def ndim(self):
 *         return self.view.ndim             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(585,0,__PYX_ERR(1, 585, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":584
 * 
 *     @property
 *     def ndim(self):             # <<<<<<<<<<<<<<
 *         return self.view.ndim
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":588
 * 
 *     @property
 *     def itemsize(self):             # <<<<<<<<<<<<<<
 *         return self.view.itemsize
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 588, 0, __PYX_ERR(1, 588, __pyx_L1_error));

  /* "View.MemoryView":589
 *     @property
 *     def itemsize(self):
 *         return self.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(589,0,__PYX_ERR(1, 589, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":588
 * 
 *     @property
 *     def itemsize(self):             # <<<<<<<<<<<<<<
 *         return self.view.itemsize
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":592
 * 
 *     @property
 *     def nbytes(self):             # <<<<<<<<<<<<<<
 *         return self.size * self.view.itemsize
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 592, 0, __PYX_ERR(1, 592, __pyx_L1_error));

  /* "View.MemoryView":593
 *     @property
 *     def nbytes(self):
 *         return self.size * self.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(593,0,__PYX_ERR(1, 593, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":592
 * 
 *     @property
 *     def nbytes(self):             # <<<<<<<<<<<<<<
 *         return self.size * self.view.itemsize
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":596
 * 
 *     @property
 *     def size(self):             # <<<<<<<<<<<<<<
 *         if self._size is None:
 *             result = 1
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  Py_ssize_t *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 596, 0, __PYX_ERR(1, 596, __pyx_L1_error));

  /* "View.MemoryView":597
 *     @property
 *     def size(self):
 *         if self._size is None:             # <<<<<<<<<<<<<<
 *             result = 1
 * 
 */
  __Pyx_TraceLine(597,0,__PYX_ERR(1, 597, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_self->_size == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":598
 *     def size(self):
 *         if self._size is None:
 *             result = 1             # <<<<<<<<<<<<<<
 * 
 *             for length in self.view.shape[:self.view.ndim]:
 */
    __Pyx_TraceLine(598,0,__PYX_ERR(1, 598, __pyx_L1_error))
    __Pyx_INCREF(__pyx_int_1);
    __pyx_v_result = __pyx_int_1;

    /* "View.MemoryView":600
 *             result = 1
 * 
 *             for length in self.view.shape[:self.view.ndim]:             # <<<<<<<<<<<<<<
 *                 result *= length
 * 
 */
    __Pyx_TraceLine(600,0,__PYX_ERR(1, 600, __pyx_L1_error))
    __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
    for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
      __pyx_t_3 = __pyx_t_5;
      __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 600, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "View.MemoryView":601
 * 
 *             for length in self.view.shape[:self.view.ndim]:
 *                 result *= length             # <<<<<<<<<<<<<<
 * 
 *             self._size = result
 */
      __Pyx_TraceLine(601,0,__PYX_ERR(1, 601, __pyx_L1_error))
      __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 601, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6);
      __pyx_t_6 = 0;
    }

    /* "View.MemoryView":603
 *                 result *= length
 * 
 *             self._size = result             # <<<<<<<<<<<<<<
 * 
 *         return self._size
 */
    __Pyx_TraceLine(603,0,__PYX_ERR(1, 603, __pyx_L1_error))
    __Pyx_INCREF(__pyx_v_result);
    __Pyx_GIVEREF(__pyx_v_result);
    __Pyx_GOTREF(__pyx_v_self->_size);
    __Pyx_DECREF(__pyx_v_self->_size);
    __pyx_v_self->_size = __pyx_v_result;

    /* "View.MemoryView":597
 *     @property
 *     def size(self):
 *         if self._size is None:             # <<<<<<<<<<<<<<
 *             result = 1
 * 
 */
  }

  /* "View.MemoryView":605
 *             self._size = result
 * 
 *         return self._size             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_TraceLine(605,0,__PYX_ERR(1, 605, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_size);
  __pyx_r = __pyx_v_self->_size;
  goto __pyx_L0;

  /* "View.MemoryView":596
 * 
 *     @property
 *     def size(self):             # <<<<<<<<<<<<<<
 *         if self._size is None:
 *             result = 1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":607
 *         return self._size
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]
 */

/* Python wrapper */
static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__len__", 0);
  __Pyx_TraceCall("__len__", __pyx_f[1], 607, 0, __PYX_ERR(1, 607, __pyx_L1_error));

  /* "View.MemoryView":608
 * 
 *     def __len__(self):
 *         if self.view.ndim >= 1:             # <<<<<<<<<<<<<<
 *             return self.view.shape[0]
 * 
 */
  __Pyx_TraceLine(608,0,__PYX_ERR(1, 608, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":609
 *     def __len__(self):
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]             # <<<<<<<<<<<<<<
 * 
 *         return 0
 */
    __Pyx_TraceLine(609,0,__PYX_ERR(1, 609, __pyx_L1_error))
    __pyx_r = (__pyx_v_self->view.shape[0]);
    goto __pyx_L0;

    /* "View.MemoryView":608
 * 
 *     def __len__(self):
 *         if self.view.ndim >= 1:             # <<<<<<<<<<<<<<
 *             return self.view.shape[0]
 * 
 */
  }

  /* "View.MemoryView":611
 *             return self.view.shape[0]
 * 
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_TraceLine(611,0,__PYX_ERR(1, 611, __pyx_L1_error))
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":607
 *         return self._size
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.view.ndim >= 1:
 *             return self.view.shape[0]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView.memoryview.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":613
 *         return 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);
  __Pyx_TraceCall("__repr__", __pyx_f[1], 613, 0, __PYX_ERR(1, 613, __pyx_L1_error));

  /* "View.MemoryView":614
 * 
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,             # <<<<<<<<<<<<<<
 *                                                id(self))
 * 
 */
  __Pyx_TraceLine(614,0,__PYX_ERR(1, 614, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "View.MemoryView":615
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __Pyx_TraceLine(615,0,__PYX_ERR(1, 615, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 615, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "View.MemoryView":614
 * 
 *     def __repr__(self):
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,             # <<<<<<<<<<<<<<
 *                                                id(self))
 * 
 */
  __Pyx_TraceLine(614,0,__PYX_ERR(1, 614, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":613
 *         return 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r at 0x%x>" % (self.base.__class__.__name__,
 *                                                id(self))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":617
 *                                                id(self))
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[1], 617, 0, __PYX_ERR(1, 617, __pyx_L1_error));

  /* "View.MemoryView":618
 * 
 *     def __str__(self):
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(618,0,__PYX_ERR(1, 618, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":617
 *                                                id(self))
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "<MemoryView of %r object>" % (self.base.__class__.__name__,)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":621
 * 
 * 
 *     def is_c_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice *__pyx_v_mslice;
  __Pyx_memviewslice __pyx_v_tmp;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_c_contig", 0);
  __Pyx_TraceCall("is_c_contig", __pyx_f[1], 621, 0, __PYX_ERR(1, 621, __pyx_L1_error));

  /* "View.MemoryView":624
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)             # <<<<<<<<<<<<<<
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 */
  __Pyx_TraceLine(624,0,__PYX_ERR(1, 624, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 624, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":625
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *     def is_f_contig(self):
 */
  __Pyx_TraceLine(625,0,__PYX_ERR(1, 625, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 625, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":621
 * 
 * 
 *     def is_c_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":627
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 *     def is_f_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice *__pyx_v_mslice;
  __Pyx_memviewslice __pyx_v_tmp;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_f_contig", 0);
  __Pyx_TraceCall("is_f_contig", __pyx_f[1], 627, 0, __PYX_ERR(1, 627, __pyx_L1_error));

  /* "View.MemoryView":630
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)             # <<<<<<<<<<<<<<
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 */
  __Pyx_TraceLine(630,0,__PYX_ERR(1, 630, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 630, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":631
 *         cdef __Pyx_memviewslice tmp
 *         mslice = get_slice_from_memview(self, &tmp)
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)             # <<<<<<<<<<<<<<
 * 
 *     def copy(self):
 */
  __Pyx_TraceLine(631,0,__PYX_ERR(1, 631, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 631, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":627
 *         return slice_is_contig(mslice[0], 'C', self.view.ndim)
 * 
 *     def is_f_contig(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice *mslice
 *         cdef __Pyx_memviewslice tmp
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":633
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_mslice;
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 0);
  __Pyx_TraceCall("copy", __pyx_f[1], 633, 0, __PYX_ERR(1, 633, __pyx_L1_error));

  /* "View.MemoryView":635
 *     def copy(self):
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS             # <<<<<<<<<<<<<<
 * 
 *         slice_copy(self, &mslice)
 */
  __Pyx_TraceLine(635,0,__PYX_ERR(1, 635, __pyx_L1_error))
  __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS));

  /* "View.MemoryView":637
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 * 
 *         slice_copy(self, &mslice)             # <<<<<<<<<<<<<<
 *         mslice = slice_copy_contig(&mslice, "c", self.view.ndim,
 *                                    self.view.itemsize,
 */
  __Pyx_TraceLine(637,0,__PYX_ERR(1, 637, __pyx_L1_error))
  __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice));

  /* "View.MemoryView":638
 * 
 *         slice_copy(self, &mslice)
 *         mslice = slice_copy_contig(&mslice, "c", self.view.ndim,             # <<<<<<<<<<<<<<
 *                                    self.view.itemsize,
 *                                    flags|PyBUF_C_CONTIGUOUS,
 */
  __Pyx_TraceLine(638,0,__PYX_ERR(1, 638, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 638, __pyx_L1_error)
  __pyx_v_mslice = __pyx_t_1;

  /* "View.MemoryView":643
 *                                    self.dtype_is_object)
 * 
 *         return memoryview_copy_from_slice(self, &mslice)             # <<<<<<<<<<<<<<
 * 
 *     def copy_fortran(self):
 */
  __Pyx_TraceLine(643,0,__PYX_ERR(1, 643, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":633
 *         return slice_is_contig(mslice[0], 'F', self.view.ndim)
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice mslice
 *         cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":645
 *         return memoryview_copy_from_slice(self, &mslice)
 * 
 *     def copy_fortran(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 */

/* Python wrapper */
static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0);
  __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) {
  __Pyx_memviewslice __pyx_v_src;
  __Pyx_memviewslice __pyx_v_dst;
  int __pyx_v_flags;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_memviewslice __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy_fortran", 0);
  __Pyx_TraceCall("copy_fortran", __pyx_f[1], 645, 0, __PYX_ERR(1, 645, __pyx_L1_error));

  /* "View.MemoryView":647
 *     def copy_fortran(self):
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS             # <<<<<<<<<<<<<<
 * 
 *         slice_copy(self, &src)
 */
  __Pyx_TraceLine(647,0,__PYX_ERR(1, 647, __pyx_L1_error))
  __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS));

  /* "View.MemoryView":649
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 * 
 *         slice_copy(self, &src)             # <<<<<<<<<<<<<<
 *         dst = slice_copy_contig(&src, "fortran", self.view.ndim,
 *                                 self.view.itemsize,
 */
  __Pyx_TraceLine(649,0,__PYX_ERR(1, 649, __pyx_L1_error))
  __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src));

  /* "View.MemoryView":650
 * 
 *         slice_copy(self, &src)
 *         dst = slice_copy_contig(&src, "fortran", self.view.ndim,             # <<<<<<<<<<<<<<
 *                                 self.view.itemsize,
 *                                 flags|PyBUF_F_CONTIGUOUS,
 */
  __Pyx_TraceLine(650,0,__PYX_ERR(1, 650, __pyx_L1_error))
  __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 650, __pyx_L1_error)
  __pyx_v_dst = __pyx_t_1;

  /* "View.MemoryView":655
 *                                 self.dtype_is_object)
 * 
 *         return memoryview_copy_from_slice(self, &dst)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(655,0,__PYX_ERR(1, 655, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":645
 *         return memoryview_copy_from_slice(self, &mslice)
 * 
 *     def copy_fortran(self):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice src, dst
 *         cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __Pyx_TraceLine(2,0,__PYX_ERR(1, 2, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":659
 * 
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):             # <<<<<<<<<<<<<<
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 */

static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) {
  struct __pyx_memoryview_obj *__pyx_v_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_cwrapper", 0);
  __Pyx_TraceCall("memoryview_cwrapper", __pyx_f[1], 659, 0, __PYX_ERR(1, 659, __pyx_L1_error));

  /* "View.MemoryView":660
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)             # <<<<<<<<<<<<<<
 *     result.typeinfo = typeinfo
 *     return result
 */
  __Pyx_TraceLine(660,0,__PYX_ERR(1, 660, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_o);
  __Pyx_GIVEREF(__pyx_v_o);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":661
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
  __Pyx_TraceLine(661,0,__PYX_ERR(1, 661, __pyx_L1_error))
  __pyx_v_result->typeinfo = __pyx_v_typeinfo;

  /* "View.MemoryView":662
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 *     return result             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_check')
 */
  __Pyx_TraceLine(662,0,__PYX_ERR(1, 662, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":659
 * 
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):             # <<<<<<<<<<<<<<
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":665
 * 
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):             # <<<<<<<<<<<<<<
 *     return isinstance(o, memoryview)
 * 
 */

static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_check", 0);
  __Pyx_TraceCall("memoryview_check", __pyx_f[1], 665, 0, __PYX_ERR(1, 665, __pyx_L1_error));

  /* "View.MemoryView":666
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):
 *     return isinstance(o, memoryview)             # <<<<<<<<<<<<<<
 * 
 * cdef tuple _unellipsify(object index, int ndim):
 */
  __Pyx_TraceLine(666,0,__PYX_ERR(1, 666, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); 
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "View.MemoryView":665
 * 
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):             # <<<<<<<<<<<<<<
 *     return isinstance(o, memoryview)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.memoryview_check", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":668
 *     return isinstance(o, memoryview)
 * 
 * cdef tuple _unellipsify(object index, int ndim):             # <<<<<<<<<<<<<<
 *     """
 *     Replace all ellipses with full slices and fill incomplete indices with
 */

static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) {
  PyObject *__pyx_v_tup = NULL;
  PyObject *__pyx_v_result = NULL;
  int __pyx_v_have_slices;
  int __pyx_v_seen_ellipsis;
  CYTHON_UNUSED PyObject *__pyx_v_idx = NULL;
  PyObject *__pyx_v_item = NULL;
  Py_ssize_t __pyx_v_nslices;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_unellipsify", 0);
  __Pyx_TraceCall("_unellipsify", __pyx_f[1], 668, 0, __PYX_ERR(1, 668, __pyx_L1_error));

  /* "View.MemoryView":673
 *     full slices.
 *     """
 *     if not isinstance(index, tuple):             # <<<<<<<<<<<<<<
 *         tup = (index,)
 *     else:
 */
  __Pyx_TraceLine(673,0,__PYX_ERR(1, 673, __pyx_L1_error))
  __pyx_t_1 = PyTuple_Check(__pyx_v_index); 
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":674
 *     """
 *     if not isinstance(index, tuple):
 *         tup = (index,)             # <<<<<<<<<<<<<<
 *     else:
 *         tup = index
 */
    __Pyx_TraceLine(674,0,__PYX_ERR(1, 674, __pyx_L1_error))
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 674, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_index);
    __Pyx_GIVEREF(__pyx_v_index);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index);
    __pyx_v_tup = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "View.MemoryView":673
 *     full slices.
 *     """
 *     if not isinstance(index, tuple):             # <<<<<<<<<<<<<<
 *         tup = (index,)
 *     else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":676
 *         tup = (index,)
 *     else:
 *         tup = index             # <<<<<<<<<<<<<<
 * 
 *     result = []
 */
  __Pyx_TraceLine(676,0,__PYX_ERR(1, 676, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(__pyx_v_index);
    __pyx_v_tup = __pyx_v_index;
  }
  __pyx_L3:;

  /* "View.MemoryView":678
 *         tup = index
 * 
 *     result = []             # <<<<<<<<<<<<<<
 *     have_slices = False
 *     seen_ellipsis = False
 */
  __Pyx_TraceLine(678,0,__PYX_ERR(1, 678, __pyx_L1_error))
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "View.MemoryView":679
 * 
 *     result = []
 *     have_slices = False             # <<<<<<<<<<<<<<
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 */
  __Pyx_TraceLine(679,0,__PYX_ERR(1, 679, __pyx_L1_error))
  __pyx_v_have_slices = 0;

  /* "View.MemoryView":680
 *     result = []
 *     have_slices = False
 *     seen_ellipsis = False             # <<<<<<<<<<<<<<
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 */
  __Pyx_TraceLine(680,0,__PYX_ERR(1, 680, __pyx_L1_error))
  __pyx_v_seen_ellipsis = 0;

  /* "View.MemoryView":681
 *     have_slices = False
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):             # <<<<<<<<<<<<<<
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 */
  __Pyx_TraceLine(681,0,__PYX_ERR(1, 681, __pyx_L1_error))
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_3 = __pyx_int_0;
  if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) {
    __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 681, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 681, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 681, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 681, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 681, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(1, 681, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3);
    __pyx_t_3 = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "View.MemoryView":682
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:             # <<<<<<<<<<<<<<
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 */
    __Pyx_TraceLine(682,0,__PYX_ERR(1, 682, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis);
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":683
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 *             if not seen_ellipsis:             # <<<<<<<<<<<<<<
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True
 */
      __Pyx_TraceLine(683,0,__PYX_ERR(1, 683, __pyx_L1_error))
      __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0);
      if (__pyx_t_1) {

        /* "View.MemoryView":684
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))             # <<<<<<<<<<<<<<
 *                 seen_ellipsis = True
 *             else:
 */
        __Pyx_TraceLine(684,0,__PYX_ERR(1, 684, __pyx_L1_error))
        __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(1, 684, __pyx_L1_error)
        __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 684, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        { Py_ssize_t __pyx_temp;
          for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) {
            __Pyx_INCREF(__pyx_slice__20);
            __Pyx_GIVEREF(__pyx_slice__20);
            PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__20);
          }
        }
        __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 684, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "View.MemoryView":685
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append(slice(None))
 */
        __Pyx_TraceLine(685,0,__PYX_ERR(1, 685, __pyx_L1_error))
        __pyx_v_seen_ellipsis = 1;

        /* "View.MemoryView":683
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:
 *             if not seen_ellipsis:             # <<<<<<<<<<<<<<
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 *                 seen_ellipsis = True
 */
        goto __pyx_L7;
      }

      /* "View.MemoryView":687
 *                 seen_ellipsis = True
 *             else:
 *                 result.append(slice(None))             # <<<<<<<<<<<<<<
 *             have_slices = True
 *         else:
 */
      __Pyx_TraceLine(687,0,__PYX_ERR(1, 687, __pyx_L1_error))
      /*else*/ {
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__20); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 687, __pyx_L1_error)
      }
      __pyx_L7:;

      /* "View.MemoryView":688
 *             else:
 *                 result.append(slice(None))
 *             have_slices = True             # <<<<<<<<<<<<<<
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):
 */
      __Pyx_TraceLine(688,0,__PYX_ERR(1, 688, __pyx_L1_error))
      __pyx_v_have_slices = 1;

      /* "View.MemoryView":682
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):
 *         if item is Ellipsis:             # <<<<<<<<<<<<<<
 *             if not seen_ellipsis:
 *                 result.extend([slice(None)] * (ndim - len(tup) + 1))
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":690
 *             have_slices = True
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):             # <<<<<<<<<<<<<<
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 */
    __Pyx_TraceLine(690,0,__PYX_ERR(1, 690, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = PySlice_Check(__pyx_v_item); 
      __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0);
      if (__pyx_t_10) {
      } else {
        __pyx_t_1 = __pyx_t_10;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0);
      __pyx_t_1 = __pyx_t_10;
      __pyx_L9_bool_binop_done:;
      if (unlikely(__pyx_t_1)) {

        /* "View.MemoryView":691
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):
 *                 raise TypeError("Cannot index with type '%s'" % type(item))             # <<<<<<<<<<<<<<
 * 
 *             have_slices = have_slices or isinstance(item, slice)
 */
        __Pyx_TraceLine(691,0,__PYX_ERR(1, 691, __pyx_L1_error))
        __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 691, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 691, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_11, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __PYX_ERR(1, 691, __pyx_L1_error)

        /* "View.MemoryView":690
 *             have_slices = True
 *         else:
 *             if not isinstance(item, slice) and not PyIndex_Check(item):             # <<<<<<<<<<<<<<
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 */
      }

      /* "View.MemoryView":693
 *                 raise TypeError("Cannot index with type '%s'" % type(item))
 * 
 *             have_slices = have_slices or isinstance(item, slice)             # <<<<<<<<<<<<<<
 *             result.append(item)
 * 
 */
      __Pyx_TraceLine(693,0,__PYX_ERR(1, 693, __pyx_L1_error))
      __pyx_t_10 = (__pyx_v_have_slices != 0);
      if (!__pyx_t_10) {
      } else {
        __pyx_t_1 = __pyx_t_10;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_10 = PySlice_Check(__pyx_v_item); 
      __pyx_t_2 = (__pyx_t_10 != 0);
      __pyx_t_1 = __pyx_t_2;
      __pyx_L11_bool_binop_done:;
      __pyx_v_have_slices = __pyx_t_1;

      /* "View.MemoryView":694
 * 
 *             have_slices = have_slices or isinstance(item, slice)
 *             result.append(item)             # <<<<<<<<<<<<<<
 * 
 *     nslices = ndim - len(result)
 */
      __Pyx_TraceLine(694,0,__PYX_ERR(1, 694, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 694, __pyx_L1_error)
    }
    __pyx_L6:;

    /* "View.MemoryView":681
 *     have_slices = False
 *     seen_ellipsis = False
 *     for idx, item in enumerate(tup):             # <<<<<<<<<<<<<<
 *         if item is Ellipsis:
 *             if not seen_ellipsis:
 */
    __Pyx_TraceLine(681,0,__PYX_ERR(1, 681, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":696
 *             result.append(item)
 * 
 *     nslices = ndim - len(result)             # <<<<<<<<<<<<<<
 *     if nslices:
 *         result.extend([slice(None)] * nslices)
 */
  __Pyx_TraceLine(696,0,__PYX_ERR(1, 696, __pyx_L1_error))
  __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 696, __pyx_L1_error)
  __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5);

  /* "View.MemoryView":697
 * 
 *     nslices = ndim - len(result)
 *     if nslices:             # <<<<<<<<<<<<<<
 *         result.extend([slice(None)] * nslices)
 * 
 */
  __Pyx_TraceLine(697,0,__PYX_ERR(1, 697, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_nslices != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":698
 *     nslices = ndim - len(result)
 *     if nslices:
 *         result.extend([slice(None)] * nslices)             # <<<<<<<<<<<<<<
 * 
 *     return have_slices or nslices, tuple(result)
 */
    __Pyx_TraceLine(698,0,__PYX_ERR(1, 698, __pyx_L1_error))
    __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    { Py_ssize_t __pyx_temp;
      for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) {
        __Pyx_INCREF(__pyx_slice__20);
        __Pyx_GIVEREF(__pyx_slice__20);
        PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__20);
      }
    }
    __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 698, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "View.MemoryView":697
 * 
 *     nslices = ndim - len(result)
 *     if nslices:             # <<<<<<<<<<<<<<
 *         result.extend([slice(None)] * nslices)
 * 
 */
  }

  /* "View.MemoryView":700
 *         result.extend([slice(None)] * nslices)
 * 
 *     return have_slices or nslices, tuple(result)             # <<<<<<<<<<<<<<
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 */
  __Pyx_TraceLine(700,0,__PYX_ERR(1, 700, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  if (!__pyx_v_have_slices) {
  } else {
    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 700, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L14_bool_binop_done;
  }
  __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 700, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_L14_bool_binop_done:;
  __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 700, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 700, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_r = ((PyObject*)__pyx_t_11);
  __pyx_t_11 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":668
 *     return isinstance(o, memoryview)
 * 
 * cdef tuple _unellipsify(object index, int ndim):             # <<<<<<<<<<<<<<
 *     """
 *     Replace all ellipses with full slices and fill incomplete indices with
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tup);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_XDECREF(__pyx_v_item);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":702
 *     return have_slices or nslices, tuple(result)
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):             # <<<<<<<<<<<<<<
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 */

static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) {
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t *__pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assert_direct_dimensions", 0);
  __Pyx_TraceCall("assert_direct_dimensions", __pyx_f[1], 702, 0, __PYX_ERR(1, 702, __pyx_L1_error));

  /* "View.MemoryView":703
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:             # <<<<<<<<<<<<<<
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")
 */
  __Pyx_TraceLine(703,0,__PYX_ERR(1, 703, __pyx_L1_error))
  __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim);
  for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) {
    __pyx_t_1 = __pyx_t_3;
    __pyx_v_suboffset = (__pyx_t_1[0]);

    /* "View.MemoryView":704
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("Indirect dimensions not supported")
 * 
 */
    __Pyx_TraceLine(704,0,__PYX_ERR(1, 704, __pyx_L1_error))
    __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "View.MemoryView":705
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(705,0,__PYX_ERR(1, 705, __pyx_L1_error))
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(1, 705, __pyx_L1_error)

      /* "View.MemoryView":704
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("Indirect dimensions not supported")
 * 
 */
    }
  }

  /* "View.MemoryView":702
 *     return have_slices or nslices, tuple(result)
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):             # <<<<<<<<<<<<<<
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":712
 * 
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):             # <<<<<<<<<<<<<<
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim
 *     cdef bint negative_step
 */

static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) {
  int __pyx_v_new_ndim;
  int __pyx_v_suboffset_dim;
  int __pyx_v_dim;
  __Pyx_memviewslice __pyx_v_src;
  __Pyx_memviewslice __pyx_v_dst;
  __Pyx_memviewslice *__pyx_v_p_src;
  struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0;
  __Pyx_memviewslice *__pyx_v_p_dst;
  int *__pyx_v_p_suboffset_dim;
  Py_ssize_t __pyx_v_start;
  Py_ssize_t __pyx_v_stop;
  Py_ssize_t __pyx_v_step;
  int __pyx_v_have_start;
  int __pyx_v_have_stop;
  int __pyx_v_have_step;
  PyObject *__pyx_v_index = NULL;
  struct __pyx_memoryview_obj *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  struct __pyx_memoryview_obj *__pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memview_slice", 0);
  __Pyx_TraceCall("memview_slice", __pyx_f[1], 712, 0, __PYX_ERR(1, 712, __pyx_L1_error));

  /* "View.MemoryView":713
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim             # <<<<<<<<<<<<<<
 *     cdef bint negative_step
 *     cdef __Pyx_memviewslice src, dst
 */
  __Pyx_TraceLine(713,0,__PYX_ERR(1, 713, __pyx_L1_error))
  __pyx_v_new_ndim = 0;
  __pyx_v_suboffset_dim = -1;

  /* "View.MemoryView":720
 * 
 * 
 *     memset(&dst, 0, sizeof(dst))             # <<<<<<<<<<<<<<
 * 
 *     cdef _memoryviewslice memviewsliceobj
 */
  __Pyx_TraceLine(720,0,__PYX_ERR(1, 720, __pyx_L1_error))
  (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))));

  /* "View.MemoryView":724
 *     cdef _memoryviewslice memviewsliceobj
 * 
 *     assert memview.view.ndim > 0             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(memview, _memoryviewslice):
 */
  __Pyx_TraceLine(724,0,__PYX_ERR(1, 724, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) {
      PyErr_SetNone(PyExc_AssertionError);
      __PYX_ERR(1, 724, __pyx_L1_error)
    }
  }
  #endif

  /* "View.MemoryView":726
 *     assert memview.view.ndim > 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice
 */
  __Pyx_TraceLine(726,0,__PYX_ERR(1, 726, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":727
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         memviewsliceobj = memview             # <<<<<<<<<<<<<<
 *         p_src = &memviewsliceobj.from_slice
 *     else:
 */
    __Pyx_TraceLine(727,0,__PYX_ERR(1, 727, __pyx_L1_error))
    if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 727, __pyx_L1_error)
    __pyx_t_3 = ((PyObject *)__pyx_v_memview);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":728
 *     if isinstance(memview, _memoryviewslice):
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice             # <<<<<<<<<<<<<<
 *     else:
 *         slice_copy(memview, &src)
 */
    __Pyx_TraceLine(728,0,__PYX_ERR(1, 728, __pyx_L1_error))
    __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice);

    /* "View.MemoryView":726
 *     assert memview.view.ndim > 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         memviewsliceobj = memview
 *         p_src = &memviewsliceobj.from_slice
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":730
 *         p_src = &memviewsliceobj.from_slice
 *     else:
 *         slice_copy(memview, &src)             # <<<<<<<<<<<<<<
 *         p_src = &src
 * 
 */
  __Pyx_TraceLine(730,0,__PYX_ERR(1, 730, __pyx_L1_error))
  /*else*/ {
    __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src));

    /* "View.MemoryView":731
 *     else:
 *         slice_copy(memview, &src)
 *         p_src = &src             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(731,0,__PYX_ERR(1, 731, __pyx_L1_error))
    __pyx_v_p_src = (&__pyx_v_src);
  }
  __pyx_L3:;

  /* "View.MemoryView":737
 * 
 * 
 *     dst.memview = p_src.memview             # <<<<<<<<<<<<<<
 *     dst.data = p_src.data
 * 
 */
  __Pyx_TraceLine(737,0,__PYX_ERR(1, 737, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_p_src->memview;
  __pyx_v_dst.memview = __pyx_t_4;

  /* "View.MemoryView":738
 * 
 *     dst.memview = p_src.memview
 *     dst.data = p_src.data             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(738,0,__PYX_ERR(1, 738, __pyx_L1_error))
  __pyx_t_5 = __pyx_v_p_src->data;
  __pyx_v_dst.data = __pyx_t_5;

  /* "View.MemoryView":743
 * 
 * 
 *     cdef __Pyx_memviewslice *p_dst = &dst             # <<<<<<<<<<<<<<
 *     cdef int *p_suboffset_dim = &suboffset_dim
 *     cdef Py_ssize_t start, stop, step
 */
  __Pyx_TraceLine(743,0,__PYX_ERR(1, 743, __pyx_L1_error))
  __pyx_v_p_dst = (&__pyx_v_dst);

  /* "View.MemoryView":744
 * 
 *     cdef __Pyx_memviewslice *p_dst = &dst
 *     cdef int *p_suboffset_dim = &suboffset_dim             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t start, stop, step
 *     cdef bint have_start, have_stop, have_step
 */
  __Pyx_TraceLine(744,0,__PYX_ERR(1, 744, __pyx_L1_error))
  __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim);

  /* "View.MemoryView":748
 *     cdef bint have_start, have_stop, have_step
 * 
 *     for dim, index in enumerate(indices):             # <<<<<<<<<<<<<<
 *         if PyIndex_Check(index):
 *             slice_memviewslice(
 */
  __Pyx_TraceLine(748,0,__PYX_ERR(1, 748, __pyx_L1_error))
  __pyx_t_6 = 0;
  if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
    __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 748, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 748, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 748, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 748, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 748, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      }
    } else {
      __pyx_t_9 = __pyx_t_8(__pyx_t_3);
      if (unlikely(!__pyx_t_9)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(1, 748, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_v_dim = __pyx_t_6;
    __pyx_t_6 = (__pyx_t_6 + 1);

    /* "View.MemoryView":749
 * 
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):             # <<<<<<<<<<<<<<
 *             slice_memviewslice(
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 */
    __Pyx_TraceLine(749,0,__PYX_ERR(1, 749, __pyx_L1_error))
    __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":753
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 *                 index, 0, 0, # start, stop, step             # <<<<<<<<<<<<<<
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 */
      __Pyx_TraceLine(753,0,__PYX_ERR(1, 753, __pyx_L1_error))
      __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 753, __pyx_L1_error)

      /* "View.MemoryView":750
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):
 *             slice_memviewslice(             # <<<<<<<<<<<<<<
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 */
      __Pyx_TraceLine(750,0,__PYX_ERR(1, 750, __pyx_L1_error))
      __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 750, __pyx_L1_error)

      /* "View.MemoryView":749
 * 
 *     for dim, index in enumerate(indices):
 *         if PyIndex_Check(index):             # <<<<<<<<<<<<<<
 *             slice_memviewslice(
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":756
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 *         elif index is None:             # <<<<<<<<<<<<<<
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 */
    __Pyx_TraceLine(756,0,__PYX_ERR(1, 756, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_index == Py_None);
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":757
 *                 False)
 *         elif index is None:
 *             p_dst.shape[new_ndim] = 1             # <<<<<<<<<<<<<<
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1
 */
      __Pyx_TraceLine(757,0,__PYX_ERR(1, 757, __pyx_L1_error))
      (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1;

      /* "View.MemoryView":758
 *         elif index is None:
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0             # <<<<<<<<<<<<<<
 *             p_dst.suboffsets[new_ndim] = -1
 *             new_ndim += 1
 */
      __Pyx_TraceLine(758,0,__PYX_ERR(1, 758, __pyx_L1_error))
      (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0;

      /* "View.MemoryView":759
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1             # <<<<<<<<<<<<<<
 *             new_ndim += 1
 *         else:
 */
      __Pyx_TraceLine(759,0,__PYX_ERR(1, 759, __pyx_L1_error))
      (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L;

      /* "View.MemoryView":760
 *             p_dst.strides[new_ndim] = 0
 *             p_dst.suboffsets[new_ndim] = -1
 *             new_ndim += 1             # <<<<<<<<<<<<<<
 *         else:
 *             start = index.start or 0
 */
      __Pyx_TraceLine(760,0,__PYX_ERR(1, 760, __pyx_L1_error))
      __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);

      /* "View.MemoryView":756
 *                 0, 0, 0, # have_{start,stop,step}
 *                 False)
 *         elif index is None:             # <<<<<<<<<<<<<<
 *             p_dst.shape[new_ndim] = 1
 *             p_dst.strides[new_ndim] = 0
 */
      goto __pyx_L6;
    }

    /* "View.MemoryView":762
 *             new_ndim += 1
 *         else:
 *             start = index.start or 0             # <<<<<<<<<<<<<<
 *             stop = index.stop or 0
 *             step = index.step or 0
 */
    __Pyx_TraceLine(762,0,__PYX_ERR(1, 762, __pyx_L1_error))
    /*else*/ {
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 762, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 762, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 762, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L7_bool_binop_done:;
      __pyx_v_start = __pyx_t_10;

      /* "View.MemoryView":763
 *         else:
 *             start = index.start or 0
 *             stop = index.stop or 0             # <<<<<<<<<<<<<<
 *             step = index.step or 0
 * 
 */
      __Pyx_TraceLine(763,0,__PYX_ERR(1, 763, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 763, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 763, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 763, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_v_stop = __pyx_t_10;

      /* "View.MemoryView":764
 *             start = index.start or 0
 *             stop = index.stop or 0
 *             step = index.step or 0             # <<<<<<<<<<<<<<
 * 
 *             have_start = index.start is not None
 */
      __Pyx_TraceLine(764,0,__PYX_ERR(1, 764, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 764, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 764, __pyx_L1_error)
      if (!__pyx_t_1) {
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 764, __pyx_L1_error)
        __pyx_t_10 = __pyx_t_12;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_10 = 0;
      __pyx_L11_bool_binop_done:;
      __pyx_v_step = __pyx_t_10;

      /* "View.MemoryView":766
 *             step = index.step or 0
 * 
 *             have_start = index.start is not None             # <<<<<<<<<<<<<<
 *             have_stop = index.stop is not None
 *             have_step = index.step is not None
 */
      __Pyx_TraceLine(766,0,__PYX_ERR(1, 766, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 766, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_start = __pyx_t_1;

      /* "View.MemoryView":767
 * 
 *             have_start = index.start is not None
 *             have_stop = index.stop is not None             # <<<<<<<<<<<<<<
 *             have_step = index.step is not None
 * 
 */
      __Pyx_TraceLine(767,0,__PYX_ERR(1, 767, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_stop = __pyx_t_1;

      /* "View.MemoryView":768
 *             have_start = index.start is not None
 *             have_stop = index.stop is not None
 *             have_step = index.step is not None             # <<<<<<<<<<<<<<
 * 
 *             slice_memviewslice(
 */
      __Pyx_TraceLine(768,0,__PYX_ERR(1, 768, __pyx_L1_error))
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 768, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = (__pyx_t_9 != Py_None);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_have_step = __pyx_t_1;

      /* "View.MemoryView":770
 *             have_step = index.step is not None
 * 
 *             slice_memviewslice(             # <<<<<<<<<<<<<<
 *                 p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
 *                 dim, new_ndim, p_suboffset_dim,
 */
      __Pyx_TraceLine(770,0,__PYX_ERR(1, 770, __pyx_L1_error))
      __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 770, __pyx_L1_error)

      /* "View.MemoryView":776
 *                 have_start, have_stop, have_step,
 *                 True)
 *             new_ndim += 1             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(memview, _memoryviewslice):
 */
      __Pyx_TraceLine(776,0,__PYX_ERR(1, 776, __pyx_L1_error))
      __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
    }
    __pyx_L6:;

    /* "View.MemoryView":748
 *     cdef bint have_start, have_stop, have_step
 * 
 *     for dim, index in enumerate(indices):             # <<<<<<<<<<<<<<
 *         if PyIndex_Check(index):
 *             slice_memviewslice(
 */
    __Pyx_TraceLine(748,0,__PYX_ERR(1, 748, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "View.MemoryView":778
 *             new_ndim += 1
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 */
  __Pyx_TraceLine(778,0,__PYX_ERR(1, 778, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":779
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,
 */
    __Pyx_TraceLine(779,0,__PYX_ERR(1, 779, __pyx_L1_error))
    __Pyx_XDECREF(((PyObject *)__pyx_r));

    /* "View.MemoryView":780
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_dtype_func,
 *                                     memview.dtype_is_object)
 */
    __Pyx_TraceLine(780,0,__PYX_ERR(1, 780, __pyx_L1_error))
    if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 780, __pyx_L1_error) }

    /* "View.MemoryView":781
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 *     else:
 */
    __Pyx_TraceLine(781,0,__PYX_ERR(1, 781, __pyx_L1_error))
    if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 781, __pyx_L1_error) }

    /* "View.MemoryView":779
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         return memoryview_fromslice(dst, new_ndim,             # <<<<<<<<<<<<<<
 *                                     memviewsliceobj.to_object_func,
 *                                     memviewsliceobj.to_dtype_func,
 */
    __Pyx_TraceLine(779,0,__PYX_ERR(1, 779, __pyx_L1_error))
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 779, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 779, __pyx_L1_error)
    __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":778
 *             new_ndim += 1
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         return memoryview_fromslice(dst, new_ndim,
 *                                     memviewsliceobj.to_object_func,
 */
  }

  /* "View.MemoryView":784
 *                                     memview.dtype_is_object)
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 * 
 */
  __Pyx_TraceLine(784,0,__PYX_ERR(1, 784, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));

    /* "View.MemoryView":785
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,
 *                                     memview.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(785,0,__PYX_ERR(1, 785, __pyx_L1_error))
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 784, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "View.MemoryView":784
 *                                     memview.dtype_is_object)
 *     else:
 *         return memoryview_fromslice(dst, new_ndim, NULL, NULL,             # <<<<<<<<<<<<<<
 *                                     memview.dtype_is_object)
 * 
 */
    __Pyx_TraceLine(784,0,__PYX_ERR(1, 784, __pyx_L1_error))
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 784, __pyx_L1_error)
    __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":712
 * 
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):             # <<<<<<<<<<<<<<
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim
 *     cdef bint negative_step
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj);
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":809
 * 
 * @cname('__pyx_memoryview_slice_memviewslice')
 * cdef int slice_memviewslice(             # <<<<<<<<<<<<<<
 *         __Pyx_memviewslice *dst,
 *         Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
 */

static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) {
  Py_ssize_t __pyx_v_new_shape;
  int __pyx_v_negative_step;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("slice_memviewslice", __pyx_f[1], 809, 1, __PYX_ERR(1, 809, __pyx_L1_error));

  /* "View.MemoryView":829
 *     cdef bint negative_step
 * 
 *     if not is_slice:             # <<<<<<<<<<<<<<
 * 
 *         if start < 0:
 */
  __Pyx_TraceLine(829,1,__PYX_ERR(1, 829, __pyx_L1_error))
  __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":831
 *     if not is_slice:
 * 
 *         if start < 0:             # <<<<<<<<<<<<<<
 *             start += shape
 *         if not 0 <= start < shape:
 */
    __Pyx_TraceLine(831,1,__PYX_ERR(1, 831, __pyx_L1_error))
    __pyx_t_1 = ((__pyx_v_start < 0) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":832
 * 
 *         if start < 0:
 *             start += shape             # <<<<<<<<<<<<<<
 *         if not 0 <= start < shape:
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 */
      __Pyx_TraceLine(832,1,__PYX_ERR(1, 832, __pyx_L1_error))
      __pyx_v_start = (__pyx_v_start + __pyx_v_shape);

      /* "View.MemoryView":831
 *     if not is_slice:
 * 
 *         if start < 0:             # <<<<<<<<<<<<<<
 *             start += shape
 *         if not 0 <= start < shape:
 */
    }

    /* "View.MemoryView":833
 *         if start < 0:
 *             start += shape
 *         if not 0 <= start < shape:             # <<<<<<<<<<<<<<
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 *     else:
 */
    __Pyx_TraceLine(833,1,__PYX_ERR(1, 833, __pyx_L1_error))
    __pyx_t_1 = (0 <= __pyx_v_start);
    if (__pyx_t_1) {
      __pyx_t_1 = (__pyx_v_start < __pyx_v_shape);
    }
    __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":834
 *             start += shape
 *         if not 0 <= start < shape:
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)             # <<<<<<<<<<<<<<
 *     else:
 * 
 */
      __Pyx_TraceLine(834,1,__PYX_ERR(1, 834, __pyx_L1_error))
      __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 834, __pyx_L1_error)

      /* "View.MemoryView":833
 *         if start < 0:
 *             start += shape
 *         if not 0 <= start < shape:             # <<<<<<<<<<<<<<
 *             _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
 *     else:
 */
    }

    /* "View.MemoryView":829
 *     cdef bint negative_step
 * 
 *     if not is_slice:             # <<<<<<<<<<<<<<
 * 
 *         if start < 0:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":837
 *     else:
 * 
 *         negative_step = have_step != 0 and step < 0             # <<<<<<<<<<<<<<
 * 
 *         if have_step and step == 0:
 */
  __Pyx_TraceLine(837,1,__PYX_ERR(1, 837, __pyx_L1_error))
  /*else*/ {
    __pyx_t_1 = ((__pyx_v_have_step != 0) != 0);
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_1 = ((__pyx_v_step < 0) != 0);
    __pyx_t_2 = __pyx_t_1;
    __pyx_L6_bool_binop_done:;
    __pyx_v_negative_step = __pyx_t_2;

    /* "View.MemoryView":839
 *         negative_step = have_step != 0 and step < 0
 * 
 *         if have_step and step == 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
 * 
 */
    __Pyx_TraceLine(839,1,__PYX_ERR(1, 839, __pyx_L1_error))
    __pyx_t_1 = (__pyx_v_have_step != 0);
    if (__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_1 = ((__pyx_v_step == 0) != 0);
    __pyx_t_2 = __pyx_t_1;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_2) {

      /* "View.MemoryView":840
 * 
 *         if have_step and step == 0:
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(840,1,__PYX_ERR(1, 840, __pyx_L1_error))
      __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 840, __pyx_L1_error)

      /* "View.MemoryView":839
 *         negative_step = have_step != 0 and step < 0
 * 
 *         if have_step and step == 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
 * 
 */
    }

    /* "View.MemoryView":843
 * 
 * 
 *         if have_start:             # <<<<<<<<<<<<<<
 *             if start < 0:
 *                 start += shape
 */
    __Pyx_TraceLine(843,1,__PYX_ERR(1, 843, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_have_start != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":844
 * 
 *         if have_start:
 *             if start < 0:             # <<<<<<<<<<<<<<
 *                 start += shape
 *                 if start < 0:
 */
      __Pyx_TraceLine(844,1,__PYX_ERR(1, 844, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_start < 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":845
 *         if have_start:
 *             if start < 0:
 *                 start += shape             # <<<<<<<<<<<<<<
 *                 if start < 0:
 *                     start = 0
 */
        __Pyx_TraceLine(845,1,__PYX_ERR(1, 845, __pyx_L1_error))
        __pyx_v_start = (__pyx_v_start + __pyx_v_shape);

        /* "View.MemoryView":846
 *             if start < 0:
 *                 start += shape
 *                 if start < 0:             # <<<<<<<<<<<<<<
 *                     start = 0
 *             elif start >= shape:
 */
        __Pyx_TraceLine(846,1,__PYX_ERR(1, 846, __pyx_L1_error))
        __pyx_t_2 = ((__pyx_v_start < 0) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":847
 *                 start += shape
 *                 if start < 0:
 *                     start = 0             # <<<<<<<<<<<<<<
 *             elif start >= shape:
 *                 if negative_step:
 */
          __Pyx_TraceLine(847,1,__PYX_ERR(1, 847, __pyx_L1_error))
          __pyx_v_start = 0;

          /* "View.MemoryView":846
 *             if start < 0:
 *                 start += shape
 *                 if start < 0:             # <<<<<<<<<<<<<<
 *                     start = 0
 *             elif start >= shape:
 */
        }

        /* "View.MemoryView":844
 * 
 *         if have_start:
 *             if start < 0:             # <<<<<<<<<<<<<<
 *                 start += shape
 *                 if start < 0:
 */
        goto __pyx_L12;
      }

      /* "View.MemoryView":848
 *                 if start < 0:
 *                     start = 0
 *             elif start >= shape:             # <<<<<<<<<<<<<<
 *                 if negative_step:
 *                     start = shape - 1
 */
      __Pyx_TraceLine(848,1,__PYX_ERR(1, 848, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":849
 *                     start = 0
 *             elif start >= shape:
 *                 if negative_step:             # <<<<<<<<<<<<<<
 *                     start = shape - 1
 *                 else:
 */
        __Pyx_TraceLine(849,1,__PYX_ERR(1, 849, __pyx_L1_error))
        __pyx_t_2 = (__pyx_v_negative_step != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":850
 *             elif start >= shape:
 *                 if negative_step:
 *                     start = shape - 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     start = shape
 */
          __Pyx_TraceLine(850,1,__PYX_ERR(1, 850, __pyx_L1_error))
          __pyx_v_start = (__pyx_v_shape - 1);

          /* "View.MemoryView":849
 *                     start = 0
 *             elif start >= shape:
 *                 if negative_step:             # <<<<<<<<<<<<<<
 *                     start = shape - 1
 *                 else:
 */
          goto __pyx_L14;
        }

        /* "View.MemoryView":852
 *                     start = shape - 1
 *                 else:
 *                     start = shape             # <<<<<<<<<<<<<<
 *         else:
 *             if negative_step:
 */
        __Pyx_TraceLine(852,1,__PYX_ERR(1, 852, __pyx_L1_error))
        /*else*/ {
          __pyx_v_start = __pyx_v_shape;
        }
        __pyx_L14:;

        /* "View.MemoryView":848
 *                 if start < 0:
 *                     start = 0
 *             elif start >= shape:             # <<<<<<<<<<<<<<
 *                 if negative_step:
 *                     start = shape - 1
 */
      }
      __pyx_L12:;

      /* "View.MemoryView":843
 * 
 * 
 *         if have_start:             # <<<<<<<<<<<<<<
 *             if start < 0:
 *                 start += shape
 */
      goto __pyx_L11;
    }

    /* "View.MemoryView":854
 *                     start = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 start = shape - 1
 *             else:
 */
    __Pyx_TraceLine(854,1,__PYX_ERR(1, 854, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = (__pyx_v_negative_step != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":855
 *         else:
 *             if negative_step:
 *                 start = shape - 1             # <<<<<<<<<<<<<<
 *             else:
 *                 start = 0
 */
        __Pyx_TraceLine(855,1,__PYX_ERR(1, 855, __pyx_L1_error))
        __pyx_v_start = (__pyx_v_shape - 1);

        /* "View.MemoryView":854
 *                     start = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 start = shape - 1
 *             else:
 */
        goto __pyx_L15;
      }

      /* "View.MemoryView":857
 *                 start = shape - 1
 *             else:
 *                 start = 0             # <<<<<<<<<<<<<<
 * 
 *         if have_stop:
 */
      __Pyx_TraceLine(857,1,__PYX_ERR(1, 857, __pyx_L1_error))
      /*else*/ {
        __pyx_v_start = 0;
      }
      __pyx_L15:;
    }
    __pyx_L11:;

    /* "View.MemoryView":859
 *                 start = 0
 * 
 *         if have_stop:             # <<<<<<<<<<<<<<
 *             if stop < 0:
 *                 stop += shape
 */
    __Pyx_TraceLine(859,1,__PYX_ERR(1, 859, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_have_stop != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":860
 * 
 *         if have_stop:
 *             if stop < 0:             # <<<<<<<<<<<<<<
 *                 stop += shape
 *                 if stop < 0:
 */
      __Pyx_TraceLine(860,1,__PYX_ERR(1, 860, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":861
 *         if have_stop:
 *             if stop < 0:
 *                 stop += shape             # <<<<<<<<<<<<<<
 *                 if stop < 0:
 *                     stop = 0
 */
        __Pyx_TraceLine(861,1,__PYX_ERR(1, 861, __pyx_L1_error))
        __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape);

        /* "View.MemoryView":862
 *             if stop < 0:
 *                 stop += shape
 *                 if stop < 0:             # <<<<<<<<<<<<<<
 *                     stop = 0
 *             elif stop > shape:
 */
        __Pyx_TraceLine(862,1,__PYX_ERR(1, 862, __pyx_L1_error))
        __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
        if (__pyx_t_2) {

          /* "View.MemoryView":863
 *                 stop += shape
 *                 if stop < 0:
 *                     stop = 0             # <<<<<<<<<<<<<<
 *             elif stop > shape:
 *                 stop = shape
 */
          __Pyx_TraceLine(863,1,__PYX_ERR(1, 863, __pyx_L1_error))
          __pyx_v_stop = 0;

          /* "View.MemoryView":862
 *             if stop < 0:
 *                 stop += shape
 *                 if stop < 0:             # <<<<<<<<<<<<<<
 *                     stop = 0
 *             elif stop > shape:
 */
        }

        /* "View.MemoryView":860
 * 
 *         if have_stop:
 *             if stop < 0:             # <<<<<<<<<<<<<<
 *                 stop += shape
 *                 if stop < 0:
 */
        goto __pyx_L17;
      }

      /* "View.MemoryView":864
 *                 if stop < 0:
 *                     stop = 0
 *             elif stop > shape:             # <<<<<<<<<<<<<<
 *                 stop = shape
 *         else:
 */
      __Pyx_TraceLine(864,1,__PYX_ERR(1, 864, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":865
 *                     stop = 0
 *             elif stop > shape:
 *                 stop = shape             # <<<<<<<<<<<<<<
 *         else:
 *             if negative_step:
 */
        __Pyx_TraceLine(865,1,__PYX_ERR(1, 865, __pyx_L1_error))
        __pyx_v_stop = __pyx_v_shape;

        /* "View.MemoryView":864
 *                 if stop < 0:
 *                     stop = 0
 *             elif stop > shape:             # <<<<<<<<<<<<<<
 *                 stop = shape
 *         else:
 */
      }
      __pyx_L17:;

      /* "View.MemoryView":859
 *                 start = 0
 * 
 *         if have_stop:             # <<<<<<<<<<<<<<
 *             if stop < 0:
 *                 stop += shape
 */
      goto __pyx_L16;
    }

    /* "View.MemoryView":867
 *                 stop = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 stop = -1
 *             else:
 */
    __Pyx_TraceLine(867,1,__PYX_ERR(1, 867, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = (__pyx_v_negative_step != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":868
 *         else:
 *             if negative_step:
 *                 stop = -1             # <<<<<<<<<<<<<<
 *             else:
 *                 stop = shape
 */
        __Pyx_TraceLine(868,1,__PYX_ERR(1, 868, __pyx_L1_error))
        __pyx_v_stop = -1L;

        /* "View.MemoryView":867
 *                 stop = shape
 *         else:
 *             if negative_step:             # <<<<<<<<<<<<<<
 *                 stop = -1
 *             else:
 */
        goto __pyx_L19;
      }

      /* "View.MemoryView":870
 *                 stop = -1
 *             else:
 *                 stop = shape             # <<<<<<<<<<<<<<
 * 
 *         if not have_step:
 */
      __Pyx_TraceLine(870,1,__PYX_ERR(1, 870, __pyx_L1_error))
      /*else*/ {
        __pyx_v_stop = __pyx_v_shape;
      }
      __pyx_L19:;
    }
    __pyx_L16:;

    /* "View.MemoryView":872
 *                 stop = shape
 * 
 *         if not have_step:             # <<<<<<<<<<<<<<
 *             step = 1
 * 
 */
    __Pyx_TraceLine(872,1,__PYX_ERR(1, 872, __pyx_L1_error))
    __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":873
 * 
 *         if not have_step:
 *             step = 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(873,1,__PYX_ERR(1, 873, __pyx_L1_error))
      __pyx_v_step = 1;

      /* "View.MemoryView":872
 *                 stop = shape
 * 
 *         if not have_step:             # <<<<<<<<<<<<<<
 *             step = 1
 * 
 */
    }

    /* "View.MemoryView":877
 * 
 *         with cython.cdivision(True):
 *             new_shape = (stop - start) // step             # <<<<<<<<<<<<<<
 * 
 *             if (stop - start) - step * new_shape:
 */
    __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step);

    /* "View.MemoryView":879
 *             new_shape = (stop - start) // step
 * 
 *             if (stop - start) - step * new_shape:             # <<<<<<<<<<<<<<
 *                 new_shape += 1
 * 
 */
    __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":880
 * 
 *             if (stop - start) - step * new_shape:
 *                 new_shape += 1             # <<<<<<<<<<<<<<
 * 
 *         if new_shape < 0:
 */
      __pyx_v_new_shape = (__pyx_v_new_shape + 1);

      /* "View.MemoryView":879
 *             new_shape = (stop - start) // step
 * 
 *             if (stop - start) - step * new_shape:             # <<<<<<<<<<<<<<
 *                 new_shape += 1
 * 
 */
    }

    /* "View.MemoryView":882
 *                 new_shape += 1
 * 
 *         if new_shape < 0:             # <<<<<<<<<<<<<<
 *             new_shape = 0
 * 
 */
    __Pyx_TraceLine(882,1,__PYX_ERR(1, 882, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":883
 * 
 *         if new_shape < 0:
 *             new_shape = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(883,1,__PYX_ERR(1, 883, __pyx_L1_error))
      __pyx_v_new_shape = 0;

      /* "View.MemoryView":882
 *                 new_shape += 1
 * 
 *         if new_shape < 0:             # <<<<<<<<<<<<<<
 *             new_shape = 0
 * 
 */
    }

    /* "View.MemoryView":886
 * 
 * 
 *         dst.strides[new_ndim] = stride * step             # <<<<<<<<<<<<<<
 *         dst.shape[new_ndim] = new_shape
 *         dst.suboffsets[new_ndim] = suboffset
 */
    __Pyx_TraceLine(886,1,__PYX_ERR(1, 886, __pyx_L1_error))
    (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step);

    /* "View.MemoryView":887
 * 
 *         dst.strides[new_ndim] = stride * step
 *         dst.shape[new_ndim] = new_shape             # <<<<<<<<<<<<<<
 *         dst.suboffsets[new_ndim] = suboffset
 * 
 */
    __Pyx_TraceLine(887,1,__PYX_ERR(1, 887, __pyx_L1_error))
    (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape;

    /* "View.MemoryView":888
 *         dst.strides[new_ndim] = stride * step
 *         dst.shape[new_ndim] = new_shape
 *         dst.suboffsets[new_ndim] = suboffset             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(888,1,__PYX_ERR(1, 888, __pyx_L1_error))
    (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset;
  }
  __pyx_L3:;

  /* "View.MemoryView":891
 * 
 * 
 *     if suboffset_dim[0] < 0:             # <<<<<<<<<<<<<<
 *         dst.data += start * stride
 *     else:
 */
  __Pyx_TraceLine(891,1,__PYX_ERR(1, 891, __pyx_L1_error))
  __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":892
 * 
 *     if suboffset_dim[0] < 0:
 *         dst.data += start * stride             # <<<<<<<<<<<<<<
 *     else:
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 */
    __Pyx_TraceLine(892,1,__PYX_ERR(1, 892, __pyx_L1_error))
    __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride));

    /* "View.MemoryView":891
 * 
 * 
 *     if suboffset_dim[0] < 0:             # <<<<<<<<<<<<<<
 *         dst.data += start * stride
 *     else:
 */
    goto __pyx_L23;
  }

  /* "View.MemoryView":894
 *         dst.data += start * stride
 *     else:
 *         dst.suboffsets[suboffset_dim[0]] += start * stride             # <<<<<<<<<<<<<<
 * 
 *     if suboffset >= 0:
 */
  __Pyx_TraceLine(894,1,__PYX_ERR(1, 894, __pyx_L1_error))
  /*else*/ {
    __pyx_t_3 = (__pyx_v_suboffset_dim[0]);
    (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride));
  }
  __pyx_L23:;

  /* "View.MemoryView":896
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 * 
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         if not is_slice:
 *             if new_ndim == 0:
 */
  __Pyx_TraceLine(896,1,__PYX_ERR(1, 896, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":897
 * 
 *     if suboffset >= 0:
 *         if not is_slice:             # <<<<<<<<<<<<<<
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 */
    __Pyx_TraceLine(897,1,__PYX_ERR(1, 897, __pyx_L1_error))
    __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":898
 *     if suboffset >= 0:
 *         if not is_slice:
 *             if new_ndim == 0:             # <<<<<<<<<<<<<<
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 */
      __Pyx_TraceLine(898,1,__PYX_ERR(1, 898, __pyx_L1_error))
      __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":899
 *         if not is_slice:
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset             # <<<<<<<<<<<<<<
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "
 */
        __Pyx_TraceLine(899,1,__PYX_ERR(1, 899, __pyx_L1_error))
        __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset);

        /* "View.MemoryView":898
 *     if suboffset >= 0:
 *         if not is_slice:
 *             if new_ndim == 0:             # <<<<<<<<<<<<<<
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 */
        goto __pyx_L26;
      }

      /* "View.MemoryView":901
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "             # <<<<<<<<<<<<<<
 *                                      "must be indexed and not sliced", dim)
 *         else:
 */
      __Pyx_TraceLine(901,1,__PYX_ERR(1, 901, __pyx_L1_error))
      /*else*/ {

        /* "View.MemoryView":902
 *             else:
 *                 _err_dim(IndexError, "All dimensions preceding dimension %d "
 *                                      "must be indexed and not sliced", dim)             # <<<<<<<<<<<<<<
 *         else:
 *             suboffset_dim[0] = new_ndim
 */
        __Pyx_TraceLine(902,1,__PYX_ERR(1, 902, __pyx_L1_error))
        __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 901, __pyx_L1_error)
      }
      __pyx_L26:;

      /* "View.MemoryView":897
 * 
 *     if suboffset >= 0:
 *         if not is_slice:             # <<<<<<<<<<<<<<
 *             if new_ndim == 0:
 *                 dst.data = (<char **> dst.data)[0] + suboffset
 */
      goto __pyx_L25;
    }

    /* "View.MemoryView":904
 *                                      "must be indexed and not sliced", dim)
 *         else:
 *             suboffset_dim[0] = new_ndim             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
    __Pyx_TraceLine(904,1,__PYX_ERR(1, 904, __pyx_L1_error))
    /*else*/ {
      (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim;
    }
    __pyx_L25:;

    /* "View.MemoryView":896
 *         dst.suboffsets[suboffset_dim[0]] += start * stride
 * 
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         if not is_slice:
 *             if new_ndim == 0:
 */
  }

  /* "View.MemoryView":906
 *             suboffset_dim[0] = new_ndim
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(906,1,__PYX_ERR(1, 906, __pyx_L1_error))
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":809
 * 
 * @cname('__pyx_memoryview_slice_memviewslice')
 * cdef int slice_memviewslice(             # <<<<<<<<<<<<<<
 *         __Pyx_memviewslice *dst,
 *         Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":912
 * 
 * @cname('__pyx_pybuffer_index')
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,             # <<<<<<<<<<<<<<
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 */

static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) {
  Py_ssize_t __pyx_v_shape;
  Py_ssize_t __pyx_v_stride;
  Py_ssize_t __pyx_v_suboffset;
  Py_ssize_t __pyx_v_itemsize;
  char *__pyx_v_resultp;
  char *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("pybuffer_index", 0);
  __Pyx_TraceCall("pybuffer_index", __pyx_f[1], 912, 0, __PYX_ERR(1, 912, __pyx_L1_error));

  /* "View.MemoryView":914
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t itemsize = view.itemsize
 *     cdef char *resultp
 */
  __Pyx_TraceLine(914,0,__PYX_ERR(1, 914, __pyx_L1_error))
  __pyx_v_suboffset = -1L;

  /* "View.MemoryView":915
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 *     cdef Py_ssize_t itemsize = view.itemsize             # <<<<<<<<<<<<<<
 *     cdef char *resultp
 * 
 */
  __Pyx_TraceLine(915,0,__PYX_ERR(1, 915, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_view->itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":918
 *     cdef char *resultp
 * 
 *     if view.ndim == 0:             # <<<<<<<<<<<<<<
 *         shape = view.len / itemsize
 *         stride = itemsize
 */
  __Pyx_TraceLine(918,0,__PYX_ERR(1, 918, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":919
 * 
 *     if view.ndim == 0:
 *         shape = view.len / itemsize             # <<<<<<<<<<<<<<
 *         stride = itemsize
 *     else:
 */
    __Pyx_TraceLine(919,0,__PYX_ERR(1, 919, __pyx_L1_error))
    if (unlikely(__pyx_v_itemsize == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
      __PYX_ERR(1, 919, __pyx_L1_error)
    }
    else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) {
      PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
      __PYX_ERR(1, 919, __pyx_L1_error)
    }
    __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize);

    /* "View.MemoryView":920
 *     if view.ndim == 0:
 *         shape = view.len / itemsize
 *         stride = itemsize             # <<<<<<<<<<<<<<
 *     else:
 *         shape = view.shape[dim]
 */
    __Pyx_TraceLine(920,0,__PYX_ERR(1, 920, __pyx_L1_error))
    __pyx_v_stride = __pyx_v_itemsize;

    /* "View.MemoryView":918
 *     cdef char *resultp
 * 
 *     if view.ndim == 0:             # <<<<<<<<<<<<<<
 *         shape = view.len / itemsize
 *         stride = itemsize
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":922
 *         stride = itemsize
 *     else:
 *         shape = view.shape[dim]             # <<<<<<<<<<<<<<
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:
 */
  __Pyx_TraceLine(922,0,__PYX_ERR(1, 922, __pyx_L1_error))
  /*else*/ {
    __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]);

    /* "View.MemoryView":923
 *     else:
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]             # <<<<<<<<<<<<<<
 *         if view.suboffsets != NULL:
 *             suboffset = view.suboffsets[dim]
 */
    __Pyx_TraceLine(923,0,__PYX_ERR(1, 923, __pyx_L1_error))
    __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]);

    /* "View.MemoryView":924
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *             suboffset = view.suboffsets[dim]
 * 
 */
    __Pyx_TraceLine(924,0,__PYX_ERR(1, 924, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":925
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:
 *             suboffset = view.suboffsets[dim]             # <<<<<<<<<<<<<<
 * 
 *     if index < 0:
 */
      __Pyx_TraceLine(925,0,__PYX_ERR(1, 925, __pyx_L1_error))
      __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]);

      /* "View.MemoryView":924
 *         shape = view.shape[dim]
 *         stride = view.strides[dim]
 *         if view.suboffsets != NULL:             # <<<<<<<<<<<<<<
 *             suboffset = view.suboffsets[dim]
 * 
 */
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":927
 *             suboffset = view.suboffsets[dim]
 * 
 *     if index < 0:             # <<<<<<<<<<<<<<
 *         index += view.shape[dim]
 *         if index < 0:
 */
  __Pyx_TraceLine(927,0,__PYX_ERR(1, 927, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_index < 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":928
 * 
 *     if index < 0:
 *         index += view.shape[dim]             # <<<<<<<<<<<<<<
 *         if index < 0:
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 */
    __Pyx_TraceLine(928,0,__PYX_ERR(1, 928, __pyx_L1_error))
    __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim]));

    /* "View.MemoryView":929
 *     if index < 0:
 *         index += view.shape[dim]
 *         if index < 0:             # <<<<<<<<<<<<<<
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
    __Pyx_TraceLine(929,0,__PYX_ERR(1, 929, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_index < 0) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "View.MemoryView":930
 *         index += view.shape[dim]
 *         if index < 0:
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)             # <<<<<<<<<<<<<<
 * 
 *     if index >= shape:
 */
      __Pyx_TraceLine(930,0,__PYX_ERR(1, 930, __pyx_L1_error))
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 930, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 930, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 930, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(1, 930, __pyx_L1_error)

      /* "View.MemoryView":929
 *     if index < 0:
 *         index += view.shape[dim]
 *         if index < 0:             # <<<<<<<<<<<<<<
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
    }

    /* "View.MemoryView":927
 *             suboffset = view.suboffsets[dim]
 * 
 *     if index < 0:             # <<<<<<<<<<<<<<
 *         index += view.shape[dim]
 *         if index < 0:
 */
  }

  /* "View.MemoryView":932
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     if index >= shape:             # <<<<<<<<<<<<<<
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
  __Pyx_TraceLine(932,0,__PYX_ERR(1, 932, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "View.MemoryView":933
 * 
 *     if index >= shape:
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)             # <<<<<<<<<<<<<<
 * 
 *     resultp = bufp + index * stride
 */
    __Pyx_TraceLine(933,0,__PYX_ERR(1, 933, __pyx_L1_error))
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 933, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 933, __pyx_L1_error)

    /* "View.MemoryView":932
 *             raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     if index >= shape:             # <<<<<<<<<<<<<<
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 */
  }

  /* "View.MemoryView":935
 *         raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
 * 
 *     resultp = bufp + index * stride             # <<<<<<<<<<<<<<
 *     if suboffset >= 0:
 *         resultp = (<char **> resultp)[0] + suboffset
 */
  __Pyx_TraceLine(935,0,__PYX_ERR(1, 935, __pyx_L1_error))
  __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride));

  /* "View.MemoryView":936
 * 
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 */
  __Pyx_TraceLine(936,0,__PYX_ERR(1, 936, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":937
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:
 *         resultp = (<char **> resultp)[0] + suboffset             # <<<<<<<<<<<<<<
 * 
 *     return resultp
 */
    __Pyx_TraceLine(937,0,__PYX_ERR(1, 937, __pyx_L1_error))
    __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset);

    /* "View.MemoryView":936
 * 
 *     resultp = bufp + index * stride
 *     if suboffset >= 0:             # <<<<<<<<<<<<<<
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 */
  }

  /* "View.MemoryView":939
 *         resultp = (<char **> resultp)[0] + suboffset
 * 
 *     return resultp             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(939,0,__PYX_ERR(1, 939, __pyx_L1_error))
  __pyx_r = __pyx_v_resultp;
  goto __pyx_L0;

  /* "View.MemoryView":912
 * 
 * @cname('__pyx_pybuffer_index')
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,             # <<<<<<<<<<<<<<
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":945
 * 
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:             # <<<<<<<<<<<<<<
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 */

static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) {
  int __pyx_v_ndim;
  Py_ssize_t *__pyx_v_shape;
  Py_ssize_t *__pyx_v_strides;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  long __pyx_t_3;
  long __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("transpose_memslice", __pyx_f[1], 945, 1, __PYX_ERR(1, 945, __pyx_L1_error));

  /* "View.MemoryView":946
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:
 *     cdef int ndim = memslice.memview.view.ndim             # <<<<<<<<<<<<<<
 * 
 *     cdef Py_ssize_t *shape = memslice.shape
 */
  __Pyx_TraceLine(946,1,__PYX_ERR(1, 946, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_memslice->memview->view.ndim;
  __pyx_v_ndim = __pyx_t_1;

  /* "View.MemoryView":948
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 *     cdef Py_ssize_t *shape = memslice.shape             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t *strides = memslice.strides
 * 
 */
  __Pyx_TraceLine(948,1,__PYX_ERR(1, 948, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_memslice->shape;
  __pyx_v_shape = __pyx_t_2;

  /* "View.MemoryView":949
 * 
 *     cdef Py_ssize_t *shape = memslice.shape
 *     cdef Py_ssize_t *strides = memslice.strides             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(949,1,__PYX_ERR(1, 949, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_memslice->strides;
  __pyx_v_strides = __pyx_t_2;

  /* "View.MemoryView":953
 * 
 *     cdef int i, j
 *     for i in range(ndim / 2):             # <<<<<<<<<<<<<<
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]
 */
  __Pyx_TraceLine(953,1,__PYX_ERR(1, 953, __pyx_L1_error))
  __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2);
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":954
 *     cdef int i, j
 *     for i in range(ndim / 2):
 *         j = ndim - 1 - i             # <<<<<<<<<<<<<<
 *         strides[i], strides[j] = strides[j], strides[i]
 *         shape[i], shape[j] = shape[j], shape[i]
 */
    __Pyx_TraceLine(954,1,__PYX_ERR(1, 954, __pyx_L1_error))
    __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i);

    /* "View.MemoryView":955
 *     for i in range(ndim / 2):
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]             # <<<<<<<<<<<<<<
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 */
    __Pyx_TraceLine(955,1,__PYX_ERR(1, 955, __pyx_L1_error))
    __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]);
    __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]);
    (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5;
    (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6;

    /* "View.MemoryView":956
 *         j = ndim - 1 - i
 *         strides[i], strides[j] = strides[j], strides[i]
 *         shape[i], shape[j] = shape[j], shape[i]             # <<<<<<<<<<<<<<
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
 */
    __Pyx_TraceLine(956,1,__PYX_ERR(1, 956, __pyx_L1_error))
    __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]);
    __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]);
    (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6;
    (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5;

    /* "View.MemoryView":958
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:             # <<<<<<<<<<<<<<
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 */
    __Pyx_TraceLine(958,1,__PYX_ERR(1, 958, __pyx_L1_error))
    __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0);
    if (!__pyx_t_8) {
    } else {
      __pyx_t_7 = __pyx_t_8;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0);
    __pyx_t_7 = __pyx_t_8;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_7) {

      /* "View.MemoryView":959
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")             # <<<<<<<<<<<<<<
 * 
 *     return 1
 */
      __Pyx_TraceLine(959,1,__PYX_ERR(1, 959, __pyx_L1_error))
      __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 959, __pyx_L1_error)

      /* "View.MemoryView":958
 *         shape[i], shape[j] = shape[j], shape[i]
 * 
 *         if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:             # <<<<<<<<<<<<<<
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 */
    }
  }

  /* "View.MemoryView":961
 *             _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
 * 
 *     return 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(961,1,__PYX_ERR(1, 961, __pyx_L1_error))
  __pyx_r = 1;
  goto __pyx_L0;

  /* "View.MemoryView":945
 * 
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:             # <<<<<<<<<<<<<<
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":978
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 */

/* Python wrapper */
static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[1], 978, 0, __PYX_ERR(1, 978, __pyx_L1_error));

  /* "View.MemoryView":979
 * 
 *     def __dealloc__(self):
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)             # <<<<<<<<<<<<<<
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 */
  __Pyx_TraceLine(979,0,__PYX_ERR(1, 979, __pyx_L1_error))
  __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1);

  /* "View.MemoryView":978
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView._memoryviewslice.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "View.MemoryView":981
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)
 */

static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_item_to_object", 0);
  __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 981, 0, __PYX_ERR(1, 981, __pyx_L1_error));

  /* "View.MemoryView":982
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:             # <<<<<<<<<<<<<<
 *             return self.to_object_func(itemp)
 *         else:
 */
  __Pyx_TraceLine(982,0,__PYX_ERR(1, 982, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":983
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)             # <<<<<<<<<<<<<<
 *         else:
 *             return memoryview.convert_item_to_object(self, itemp)
 */
    __Pyx_TraceLine(983,0,__PYX_ERR(1, 983, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 983, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "View.MemoryView":982
 * 
 *     cdef convert_item_to_object(self, char *itemp):
 *         if self.to_object_func != NULL:             # <<<<<<<<<<<<<<
 *             return self.to_object_func(itemp)
 *         else:
 */
  }

  /* "View.MemoryView":985
 *             return self.to_object_func(itemp)
 *         else:
 *             return memoryview.convert_item_to_object(self, itemp)             # <<<<<<<<<<<<<<
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 */
  __Pyx_TraceLine(985,0,__PYX_ERR(1, 985, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 985, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "View.MemoryView":981
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":987
 *             return memoryview.convert_item_to_object(self, itemp)
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)
 */

static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assign_item_from_object", 0);
  __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 987, 0, __PYX_ERR(1, 987, __pyx_L1_error));

  /* "View.MemoryView":988
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:             # <<<<<<<<<<<<<<
 *             self.to_dtype_func(itemp, value)
 *         else:
 */
  __Pyx_TraceLine(988,0,__PYX_ERR(1, 988, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":989
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)             # <<<<<<<<<<<<<<
 *         else:
 *             memoryview.assign_item_from_object(self, itemp, value)
 */
    __Pyx_TraceLine(989,0,__PYX_ERR(1, 989, __pyx_L1_error))
    __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 989, __pyx_L1_error)

    /* "View.MemoryView":988
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):
 *         if self.to_dtype_func != NULL:             # <<<<<<<<<<<<<<
 *             self.to_dtype_func(itemp, value)
 *         else:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":991
 *             self.to_dtype_func(itemp, value)
 *         else:
 *             memoryview.assign_item_from_object(self, itemp, value)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __Pyx_TraceLine(991,0,__PYX_ERR(1, 991, __pyx_L1_error))
  /*else*/ {
    __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 991, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "View.MemoryView":987
 *             return memoryview.convert_item_to_object(self, itemp)
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":994
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.from_object
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 994, 0, __PYX_ERR(1, 994, __pyx_L1_error));

  /* "View.MemoryView":995
 *     @property
 *     def base(self):
 *         return self.from_object             # <<<<<<<<<<<<<<
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
 */
  __Pyx_TraceLine(995,0,__PYX_ERR(1, 995, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->from_object);
  __pyx_r = __pyx_v_self->from_object;
  goto __pyx_L0;

  /* "View.MemoryView":994
 * 
 *     @property
 *     def base(self):             # <<<<<<<<<<<<<<
 *         return self.from_object
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));

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

static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __Pyx_TraceLine(2,0,__PYX_ERR(1, 2, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1001
 * 
 * @cname('__pyx_memoryview_fromslice')
 * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice,             # <<<<<<<<<<<<<<
 *                           int ndim,
 *                           object (*to_object_func)(char *),
 */

static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) {
  struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
  Py_ssize_t __pyx_v_suboffset;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TypeInfo *__pyx_t_4;
  Py_buffer __pyx_t_5;
  Py_ssize_t *__pyx_t_6;
  Py_ssize_t *__pyx_t_7;
  Py_ssize_t *__pyx_t_8;
  Py_ssize_t __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_fromslice", 0);
  __Pyx_TraceCall("memoryview_fromslice", __pyx_f[1], 1001, 0, __PYX_ERR(1, 1001, __pyx_L1_error));

  /* "View.MemoryView":1009
 *     cdef _memoryviewslice result
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __Pyx_TraceLine(1009,0,__PYX_ERR(1, 1009, __pyx_L1_error))
  __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1010
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:
 *         return None             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(1010,0,__PYX_ERR(1, 1010, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "View.MemoryView":1009
 *     cdef _memoryviewslice result
 * 
 *     if <PyObject *> memviewslice.memview == Py_None:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "View.MemoryView":1015
 * 
 * 
 *     result = _memoryviewslice(None, 0, dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 *     result.from_slice = memviewslice
 */
  __Pyx_TraceLine(1015,0,__PYX_ERR(1, 1015, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1015, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1015, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1015, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":1017
 *     result = _memoryviewslice(None, 0, dtype_is_object)
 * 
 *     result.from_slice = memviewslice             # <<<<<<<<<<<<<<
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)
 * 
 */
  __Pyx_TraceLine(1017,0,__PYX_ERR(1, 1017, __pyx_L1_error))
  __pyx_v_result->from_slice = __pyx_v_memviewslice;

  /* "View.MemoryView":1018
 * 
 *     result.from_slice = memviewslice
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)             # <<<<<<<<<<<<<<
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base
 */
  __Pyx_TraceLine(1018,0,__PYX_ERR(1, 1018, __pyx_L1_error))
  __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1);

  /* "View.MemoryView":1020
 *     __PYX_INC_MEMVIEW(&memviewslice, 1)
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base             # <<<<<<<<<<<<<<
 *     result.typeinfo = memviewslice.memview.typeinfo
 * 
 */
  __Pyx_TraceLine(1020,0,__PYX_ERR(1, 1020, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1020, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_result->from_object);
  __Pyx_DECREF(__pyx_v_result->from_object);
  __pyx_v_result->from_object = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "View.MemoryView":1021
 * 
 *     result.from_object = (<memoryview> memviewslice.memview).base
 *     result.typeinfo = memviewslice.memview.typeinfo             # <<<<<<<<<<<<<<
 * 
 *     result.view = memviewslice.memview.view
 */
  __Pyx_TraceLine(1021,0,__PYX_ERR(1, 1021, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo;
  __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4;

  /* "View.MemoryView":1023
 *     result.typeinfo = memviewslice.memview.typeinfo
 * 
 *     result.view = memviewslice.memview.view             # <<<<<<<<<<<<<<
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim
 */
  __Pyx_TraceLine(1023,0,__PYX_ERR(1, 1023, __pyx_L1_error))
  __pyx_t_5 = __pyx_v_memviewslice.memview->view;
  __pyx_v_result->__pyx_base.view = __pyx_t_5;

  /* "View.MemoryView":1024
 * 
 *     result.view = memviewslice.memview.view
 *     result.view.buf = <void *> memviewslice.data             # <<<<<<<<<<<<<<
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 */
  __Pyx_TraceLine(1024,0,__PYX_ERR(1, 1024, __pyx_L1_error))
  __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data);

  /* "View.MemoryView":1025
 *     result.view = memviewslice.memview.view
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim             # <<<<<<<<<<<<<<
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 *     Py_INCREF(Py_None)
 */
  __Pyx_TraceLine(1025,0,__PYX_ERR(1, 1025, __pyx_L1_error))
  __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim;

  /* "View.MemoryView":1026
 *     result.view.buf = <void *> memviewslice.data
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None             # <<<<<<<<<<<<<<
 *     Py_INCREF(Py_None)
 * 
 */
  __Pyx_TraceLine(1026,0,__PYX_ERR(1, 1026, __pyx_L1_error))
  ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None;

  /* "View.MemoryView":1027
 *     result.view.ndim = ndim
 *     (<__pyx_buffer *> &result.view).obj = Py_None
 *     Py_INCREF(Py_None)             # <<<<<<<<<<<<<<
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:
 */
  __Pyx_TraceLine(1027,0,__PYX_ERR(1, 1027, __pyx_L1_error))
  Py_INCREF(Py_None);

  /* "View.MemoryView":1029
 *     Py_INCREF(Py_None)
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:             # <<<<<<<<<<<<<<
 *         result.flags = PyBUF_RECORDS
 *     else:
 */
  __Pyx_TraceLine(1029,0,__PYX_ERR(1, 1029, __pyx_L1_error))
  __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1030
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:
 *         result.flags = PyBUF_RECORDS             # <<<<<<<<<<<<<<
 *     else:
 *         result.flags = PyBUF_RECORDS_RO
 */
    __Pyx_TraceLine(1030,0,__PYX_ERR(1, 1030, __pyx_L1_error))
    __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS;

    /* "View.MemoryView":1029
 *     Py_INCREF(Py_None)
 * 
 *     if (<memoryview>memviewslice.memview).flags & PyBUF_WRITABLE:             # <<<<<<<<<<<<<<
 *         result.flags = PyBUF_RECORDS
 *     else:
 */
    goto __pyx_L4;
  }

  /* "View.MemoryView":1032
 *         result.flags = PyBUF_RECORDS
 *     else:
 *         result.flags = PyBUF_RECORDS_RO             # <<<<<<<<<<<<<<
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape
 */
  __Pyx_TraceLine(1032,0,__PYX_ERR(1, 1032, __pyx_L1_error))
  /*else*/ {
    __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO;
  }
  __pyx_L4:;

  /* "View.MemoryView":1034
 *         result.flags = PyBUF_RECORDS_RO
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape             # <<<<<<<<<<<<<<
 *     result.view.strides = <Py_ssize_t *> result.from_slice.strides
 * 
 */
  __Pyx_TraceLine(1034,0,__PYX_ERR(1, 1034, __pyx_L1_error))
  __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape);

  /* "View.MemoryView":1035
 * 
 *     result.view.shape = <Py_ssize_t *> result.from_slice.shape
 *     result.view.strides = <Py_ssize_t *> result.from_slice.strides             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1035,0,__PYX_ERR(1, 1035, __pyx_L1_error))
  __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides);

  /* "View.MemoryView":1038
 * 
 * 
 *     result.view.suboffsets = NULL             # <<<<<<<<<<<<<<
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:
 */
  __Pyx_TraceLine(1038,0,__PYX_ERR(1, 1038, __pyx_L1_error))
  __pyx_v_result->__pyx_base.view.suboffsets = NULL;

  /* "View.MemoryView":1039
 * 
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:             # <<<<<<<<<<<<<<
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 */
  __Pyx_TraceLine(1039,0,__PYX_ERR(1, 1039, __pyx_L1_error))
  __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim);
  for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) {
    __pyx_t_6 = __pyx_t_8;
    __pyx_v_suboffset = (__pyx_t_6[0]);

    /* "View.MemoryView":1040
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break
 */
    __Pyx_TraceLine(1040,0,__PYX_ERR(1, 1040, __pyx_L1_error))
    __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0);
    if (__pyx_t_1) {

      /* "View.MemoryView":1041
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __Pyx_TraceLine(1041,0,__PYX_ERR(1, 1041, __pyx_L1_error))
      __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets);

      /* "View.MemoryView":1042
 *         if suboffset >= 0:
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break             # <<<<<<<<<<<<<<
 * 
 *     result.view.len = result.view.itemsize
 */
      __Pyx_TraceLine(1042,0,__PYX_ERR(1, 1042, __pyx_L1_error))
      goto __pyx_L6_break;

      /* "View.MemoryView":1040
 *     result.view.suboffsets = NULL
 *     for suboffset in result.from_slice.suboffsets[:ndim]:
 *         if suboffset >= 0:             # <<<<<<<<<<<<<<
 *             result.view.suboffsets = <Py_ssize_t *> result.from_slice.suboffsets
 *             break
 */
    }
  }
  __pyx_L6_break:;

  /* "View.MemoryView":1044
 *             break
 * 
 *     result.view.len = result.view.itemsize             # <<<<<<<<<<<<<<
 *     for length in result.view.shape[:ndim]:
 *         result.view.len *= length
 */
  __Pyx_TraceLine(1044,0,__PYX_ERR(1, 1044, __pyx_L1_error))
  __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize;
  __pyx_v_result->__pyx_base.view.len = __pyx_t_9;

  /* "View.MemoryView":1045
 * 
 *     result.view.len = result.view.itemsize
 *     for length in result.view.shape[:ndim]:             # <<<<<<<<<<<<<<
 *         result.view.len *= length
 * 
 */
  __Pyx_TraceLine(1045,0,__PYX_ERR(1, 1045, __pyx_L1_error))
  __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim);
  for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) {
    __pyx_t_6 = __pyx_t_8;
    __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "View.MemoryView":1046
 *     result.view.len = result.view.itemsize
 *     for length in result.view.shape[:ndim]:
 *         result.view.len *= length             # <<<<<<<<<<<<<<
 * 
 *     result.to_object_func = to_object_func
 */
    __Pyx_TraceLine(1046,0,__PYX_ERR(1, 1046, __pyx_L1_error))
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1046, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_result->__pyx_base.view.len = __pyx_t_9;
  }

  /* "View.MemoryView":1048
 *         result.view.len *= length
 * 
 *     result.to_object_func = to_object_func             # <<<<<<<<<<<<<<
 *     result.to_dtype_func = to_dtype_func
 * 
 */
  __Pyx_TraceLine(1048,0,__PYX_ERR(1, 1048, __pyx_L1_error))
  __pyx_v_result->to_object_func = __pyx_v_to_object_func;

  /* "View.MemoryView":1049
 * 
 *     result.to_object_func = to_object_func
 *     result.to_dtype_func = to_dtype_func             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  __Pyx_TraceLine(1049,0,__PYX_ERR(1, 1049, __pyx_L1_error))
  __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func;

  /* "View.MemoryView":1051
 *     result.to_dtype_func = to_dtype_func
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 */
  __Pyx_TraceLine(1051,0,__PYX_ERR(1, 1051, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "View.MemoryView":1001
 * 
 * @cname('__pyx_memoryview_fromslice')
 * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice,             # <<<<<<<<<<<<<<
 *                           int ndim,
 *                           object (*to_object_func)(char *),
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1054
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview,             # <<<<<<<<<<<<<<
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 */

static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) {
  struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0;
  __Pyx_memviewslice *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_slice_from_memview", 0);
  __Pyx_TraceCall("get_slice_from_memview", __pyx_f[1], 1054, 0, __PYX_ERR(1, 1054, __pyx_L1_error));

  /* "View.MemoryView":1057
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         obj = memview
 *         return &obj.from_slice
 */
  __Pyx_TraceLine(1057,0,__PYX_ERR(1, 1057, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1058
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):
 *         obj = memview             # <<<<<<<<<<<<<<
 *         return &obj.from_slice
 *     else:
 */
    __Pyx_TraceLine(1058,0,__PYX_ERR(1, 1058, __pyx_L1_error))
    if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 1058, __pyx_L1_error)
    __pyx_t_3 = ((PyObject *)__pyx_v_memview);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "View.MemoryView":1059
 *     if isinstance(memview, _memoryviewslice):
 *         obj = memview
 *         return &obj.from_slice             # <<<<<<<<<<<<<<
 *     else:
 *         slice_copy(memview, mslice)
 */
    __Pyx_TraceLine(1059,0,__PYX_ERR(1, 1059, __pyx_L1_error))
    __pyx_r = (&__pyx_v_obj->from_slice);
    goto __pyx_L0;

    /* "View.MemoryView":1057
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         obj = memview
 *         return &obj.from_slice
 */
  }

  /* "View.MemoryView":1061
 *         return &obj.from_slice
 *     else:
 *         slice_copy(memview, mslice)             # <<<<<<<<<<<<<<
 *         return mslice
 * 
 */
  __Pyx_TraceLine(1061,0,__PYX_ERR(1, 1061, __pyx_L1_error))
  /*else*/ {
    __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice);

    /* "View.MemoryView":1062
 *     else:
 *         slice_copy(memview, mslice)
 *         return mslice             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_slice_copy')
 */
    __Pyx_TraceLine(1062,0,__PYX_ERR(1, 1062, __pyx_L1_error))
    __pyx_r = __pyx_v_mslice;
    goto __pyx_L0;
  }

  /* "View.MemoryView":1054
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview,             # <<<<<<<<<<<<<<
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_obj);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1065
 * 
 * @cname('__pyx_memoryview_slice_copy')
 * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst):             # <<<<<<<<<<<<<<
 *     cdef int dim
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 */

static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) {
  int __pyx_v_dim;
  Py_ssize_t *__pyx_v_shape;
  Py_ssize_t *__pyx_v_strides;
  Py_ssize_t *__pyx_v_suboffsets;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("slice_copy", 0);
  __Pyx_TraceCall("slice_copy", __pyx_f[1], 1065, 0, __PYX_ERR(1, 1065, __pyx_L1_error));

  /* "View.MemoryView":1069
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 * 
 *     shape = memview.view.shape             # <<<<<<<<<<<<<<
 *     strides = memview.view.strides
 *     suboffsets = memview.view.suboffsets
 */
  __Pyx_TraceLine(1069,0,__PYX_ERR(1, 1069, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_memview->view.shape;
  __pyx_v_shape = __pyx_t_1;

  /* "View.MemoryView":1070
 * 
 *     shape = memview.view.shape
 *     strides = memview.view.strides             # <<<<<<<<<<<<<<
 *     suboffsets = memview.view.suboffsets
 * 
 */
  __Pyx_TraceLine(1070,0,__PYX_ERR(1, 1070, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_memview->view.strides;
  __pyx_v_strides = __pyx_t_1;

  /* "View.MemoryView":1071
 *     shape = memview.view.shape
 *     strides = memview.view.strides
 *     suboffsets = memview.view.suboffsets             # <<<<<<<<<<<<<<
 * 
 *     dst.memview = <__pyx_memoryview *> memview
 */
  __Pyx_TraceLine(1071,0,__PYX_ERR(1, 1071, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_memview->view.suboffsets;
  __pyx_v_suboffsets = __pyx_t_1;

  /* "View.MemoryView":1073
 *     suboffsets = memview.view.suboffsets
 * 
 *     dst.memview = <__pyx_memoryview *> memview             # <<<<<<<<<<<<<<
 *     dst.data = <char *> memview.view.buf
 * 
 */
  __Pyx_TraceLine(1073,0,__PYX_ERR(1, 1073, __pyx_L1_error))
  __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview);

  /* "View.MemoryView":1074
 * 
 *     dst.memview = <__pyx_memoryview *> memview
 *     dst.data = <char *> memview.view.buf             # <<<<<<<<<<<<<<
 * 
 *     for dim in range(memview.view.ndim):
 */
  __Pyx_TraceLine(1074,0,__PYX_ERR(1, 1074, __pyx_L1_error))
  __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf);

  /* "View.MemoryView":1076
 *     dst.data = <char *> memview.view.buf
 * 
 *     for dim in range(memview.view.ndim):             # <<<<<<<<<<<<<<
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]
 */
  __Pyx_TraceLine(1076,0,__PYX_ERR(1, 1076, __pyx_L1_error))
  __pyx_t_2 = __pyx_v_memview->view.ndim;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_dim = __pyx_t_4;

    /* "View.MemoryView":1077
 * 
 *     for dim in range(memview.view.ndim):
 *         dst.shape[dim] = shape[dim]             # <<<<<<<<<<<<<<
 *         dst.strides[dim] = strides[dim]
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1
 */
    __Pyx_TraceLine(1077,0,__PYX_ERR(1, 1077, __pyx_L1_error))
    (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]);

    /* "View.MemoryView":1078
 *     for dim in range(memview.view.ndim):
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]             # <<<<<<<<<<<<<<
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1
 * 
 */
    __Pyx_TraceLine(1078,0,__PYX_ERR(1, 1078, __pyx_L1_error))
    (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]);

    /* "View.MemoryView":1079
 *         dst.shape[dim] = shape[dim]
 *         dst.strides[dim] = strides[dim]
 *         dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_object')
 */
    __Pyx_TraceLine(1079,0,__PYX_ERR(1, 1079, __pyx_L1_error))
    if ((__pyx_v_suboffsets != 0)) {
      __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]);
    } else {
      __pyx_t_5 = -1L;
    }
    (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5;
  }

  /* "View.MemoryView":1065
 * 
 * @cname('__pyx_memoryview_slice_copy')
 * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst):             # <<<<<<<<<<<<<<
 *     cdef int dim
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.slice_copy", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "View.MemoryView":1082
 * 
 * @cname('__pyx_memoryview_copy_object')
 * cdef memoryview_copy(memoryview memview):             # <<<<<<<<<<<<<<
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 */

static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) {
  __Pyx_memviewslice __pyx_v_memviewslice;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_copy", 0);
  __Pyx_TraceCall("memoryview_copy", __pyx_f[1], 1082, 0, __PYX_ERR(1, 1082, __pyx_L1_error));

  /* "View.MemoryView":1085
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 *     slice_copy(memview, &memviewslice)             # <<<<<<<<<<<<<<
 *     return memoryview_copy_from_slice(memview, &memviewslice)
 * 
 */
  __Pyx_TraceLine(1085,0,__PYX_ERR(1, 1085, __pyx_L1_error))
  __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice));

  /* "View.MemoryView":1086
 *     cdef __Pyx_memviewslice memviewslice
 *     slice_copy(memview, &memviewslice)
 *     return memoryview_copy_from_slice(memview, &memviewslice)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 */
  __Pyx_TraceLine(1086,0,__PYX_ERR(1, 1086, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1082
 * 
 * @cname('__pyx_memoryview_copy_object')
 * cdef memoryview_copy(memoryview memview):             # <<<<<<<<<<<<<<
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1089
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice):             # <<<<<<<<<<<<<<
 *     """
 *     Create a new memoryview object from a given memoryview object and slice.
 */

static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) {
  PyObject *(*__pyx_v_to_object_func)(char *);
  int (*__pyx_v_to_dtype_func)(char *, PyObject *);
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *(*__pyx_t_3)(char *);
  int (*__pyx_t_4)(char *, PyObject *);
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0);
  __Pyx_TraceCall("memoryview_copy_from_slice", __pyx_f[1], 1089, 0, __PYX_ERR(1, 1089, __pyx_L1_error));

  /* "View.MemoryView":1096
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 */
  __Pyx_TraceLine(1096,0,__PYX_ERR(1, 1096, __pyx_L1_error))
  __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1097
 * 
 *     if isinstance(memview, _memoryviewslice):
 *         to_object_func = (<_memoryviewslice> memview).to_object_func             # <<<<<<<<<<<<<<
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 *     else:
 */
    __Pyx_TraceLine(1097,0,__PYX_ERR(1, 1097, __pyx_L1_error))
    __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func;
    __pyx_v_to_object_func = __pyx_t_3;

    /* "View.MemoryView":1098
 *     if isinstance(memview, _memoryviewslice):
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func             # <<<<<<<<<<<<<<
 *     else:
 *         to_object_func = NULL
 */
    __Pyx_TraceLine(1098,0,__PYX_ERR(1, 1098, __pyx_L1_error))
    __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func;
    __pyx_v_to_dtype_func = __pyx_t_4;

    /* "View.MemoryView":1096
 *     cdef int (*to_dtype_func)(char *, object) except 0
 * 
 *     if isinstance(memview, _memoryviewslice):             # <<<<<<<<<<<<<<
 *         to_object_func = (<_memoryviewslice> memview).to_object_func
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1100
 *         to_dtype_func = (<_memoryviewslice> memview).to_dtype_func
 *     else:
 *         to_object_func = NULL             # <<<<<<<<<<<<<<
 *         to_dtype_func = NULL
 * 
 */
  __Pyx_TraceLine(1100,0,__PYX_ERR(1, 1100, __pyx_L1_error))
  /*else*/ {
    __pyx_v_to_object_func = NULL;

    /* "View.MemoryView":1101
 *     else:
 *         to_object_func = NULL
 *         to_dtype_func = NULL             # <<<<<<<<<<<<<<
 * 
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,
 */
    __Pyx_TraceLine(1101,0,__PYX_ERR(1, 1101, __pyx_L1_error))
    __pyx_v_to_dtype_func = NULL;
  }
  __pyx_L3:;

  /* "View.MemoryView":1103
 *         to_dtype_func = NULL
 * 
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,             # <<<<<<<<<<<<<<
 *                                 to_object_func, to_dtype_func,
 *                                 memview.dtype_is_object)
 */
  __Pyx_TraceLine(1103,0,__PYX_ERR(1, 1103, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);

  /* "View.MemoryView":1105
 *     return memoryview_fromslice(memviewslice[0], memview.view.ndim,
 *                                 to_object_func, to_dtype_func,
 *                                 memview.dtype_is_object)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1105,0,__PYX_ERR(1, 1105, __pyx_L1_error))
  __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 1103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1089
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice):             # <<<<<<<<<<<<<<
 *     """
 *     Create a new memoryview object from a given memoryview object and slice.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "View.MemoryView":1111
 * 
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:             # <<<<<<<<<<<<<<
 *     if arg < 0:
 *         return -arg
 */

static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) {
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("abs_py_ssize_t", __pyx_f[1], 1111, 1, __PYX_ERR(1, 1111, __pyx_L1_error));

  /* "View.MemoryView":1112
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:             # <<<<<<<<<<<<<<
 *         return -arg
 *     else:
 */
  __Pyx_TraceLine(1112,1,__PYX_ERR(1, 1112, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_arg < 0) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1113
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:
 *         return -arg             # <<<<<<<<<<<<<<
 *     else:
 *         return arg
 */
    __Pyx_TraceLine(1113,1,__PYX_ERR(1, 1113, __pyx_L1_error))
    __pyx_r = (-__pyx_v_arg);
    goto __pyx_L0;

    /* "View.MemoryView":1112
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:
 *     if arg < 0:             # <<<<<<<<<<<<<<
 *         return -arg
 *     else:
 */
  }

  /* "View.MemoryView":1115
 *         return -arg
 *     else:
 *         return arg             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_get_best_slice_order')
 */
  __Pyx_TraceLine(1115,1,__PYX_ERR(1, 1115, __pyx_L1_error))
  /*else*/ {
    __pyx_r = __pyx_v_arg;
    goto __pyx_L0;
  }

  /* "View.MemoryView":1111
 * 
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:             # <<<<<<<<<<<<<<
 *     if arg < 0:
 *         return -arg
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.abs_py_ssize_t", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1118
 * 
 * @cname('__pyx_get_best_slice_order')
 * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     Figure out the best memory access order for a given slice.
 */

static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) {
  int __pyx_v_i;
  Py_ssize_t __pyx_v_c_stride;
  Py_ssize_t __pyx_v_f_stride;
  char __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("get_best_order", __pyx_f[1], 1118, 1, __PYX_ERR(1, 1118, __pyx_L1_error));

  /* "View.MemoryView":1123
 *     """
 *     cdef int i
 *     cdef Py_ssize_t c_stride = 0             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t f_stride = 0
 * 
 */
  __Pyx_TraceLine(1123,1,__PYX_ERR(1, 1123, __pyx_L1_error))
  __pyx_v_c_stride = 0;

  /* "View.MemoryView":1124
 *     cdef int i
 *     cdef Py_ssize_t c_stride = 0
 *     cdef Py_ssize_t f_stride = 0             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim - 1, -1, -1):
 */
  __Pyx_TraceLine(1124,1,__PYX_ERR(1, 1124, __pyx_L1_error))
  __pyx_v_f_stride = 0;

  /* "View.MemoryView":1126
 *     cdef Py_ssize_t f_stride = 0
 * 
 *     for i in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]
 */
  __Pyx_TraceLine(1126,1,__PYX_ERR(1, 1126, __pyx_L1_error))
  for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":1127
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             c_stride = mslice.strides[i]
 *             break
 */
    __Pyx_TraceLine(1127,1,__PYX_ERR(1, 1127, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1128
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __Pyx_TraceLine(1128,1,__PYX_ERR(1, 1128, __pyx_L1_error))
      __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]);

      /* "View.MemoryView":1129
 *         if mslice.shape[i] > 1:
 *             c_stride = mslice.strides[i]
 *             break             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim):
 */
      __Pyx_TraceLine(1129,1,__PYX_ERR(1, 1129, __pyx_L1_error))
      goto __pyx_L4_break;

      /* "View.MemoryView":1127
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             c_stride = mslice.strides[i]
 *             break
 */
    }
  }
  __pyx_L4_break:;

  /* "View.MemoryView":1131
 *             break
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]
 */
  __Pyx_TraceLine(1131,1,__PYX_ERR(1, 1131, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_ndim;
  __pyx_t_3 = __pyx_t_1;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "View.MemoryView":1132
 * 
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             f_stride = mslice.strides[i]
 *             break
 */
    __Pyx_TraceLine(1132,1,__PYX_ERR(1, 1132, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1133
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]             # <<<<<<<<<<<<<<
 *             break
 * 
 */
      __Pyx_TraceLine(1133,1,__PYX_ERR(1, 1133, __pyx_L1_error))
      __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]);

      /* "View.MemoryView":1134
 *         if mslice.shape[i] > 1:
 *             f_stride = mslice.strides[i]
 *             break             # <<<<<<<<<<<<<<
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):
 */
      __Pyx_TraceLine(1134,1,__PYX_ERR(1, 1134, __pyx_L1_error))
      goto __pyx_L7_break;

      /* "View.MemoryView":1132
 * 
 *     for i in range(ndim):
 *         if mslice.shape[i] > 1:             # <<<<<<<<<<<<<<
 *             f_stride = mslice.strides[i]
 *             break
 */
    }
  }
  __pyx_L7_break:;

  /* "View.MemoryView":1136
 *             break
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):             # <<<<<<<<<<<<<<
 *         return 'C'
 *     else:
 */
  __Pyx_TraceLine(1136,1,__PYX_ERR(1, 1136, __pyx_L1_error))
  __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1137
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):
 *         return 'C'             # <<<<<<<<<<<<<<
 *     else:
 *         return 'F'
 */
    __Pyx_TraceLine(1137,1,__PYX_ERR(1, 1137, __pyx_L1_error))
    __pyx_r = 'C';
    goto __pyx_L0;

    /* "View.MemoryView":1136
 *             break
 * 
 *     if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride):             # <<<<<<<<<<<<<<
 *         return 'C'
 *     else:
 */
  }

  /* "View.MemoryView":1139
 *         return 'C'
 *     else:
 *         return 'F'             # <<<<<<<<<<<<<<
 * 
 * @cython.cdivision(True)
 */
  __Pyx_TraceLine(1139,1,__PYX_ERR(1, 1139, __pyx_L1_error))
  /*else*/ {
    __pyx_r = 'F';
    goto __pyx_L0;
  }

  /* "View.MemoryView":1118
 * 
 * @cname('__pyx_get_best_slice_order')
 * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     Figure out the best memory access order for a given slice.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.get_best_order", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1142
 * 
 * @cython.cdivision(True)
 * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides,             # <<<<<<<<<<<<<<
 *                                    char *dst_data, Py_ssize_t *dst_strides,
 *                                    Py_ssize_t *src_shape, Py_ssize_t *dst_shape,
 */

static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent;
  Py_ssize_t __pyx_v_dst_extent;
  Py_ssize_t __pyx_v_src_stride;
  Py_ssize_t __pyx_v_dst_stride;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;

  /* "View.MemoryView":1149
 * 
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t src_extent = src_shape[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]
 */
  __pyx_v_src_extent = (__pyx_v_src_shape[0]);

  /* "View.MemoryView":1150
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t src_extent = src_shape[0]
 *     cdef Py_ssize_t dst_extent = dst_shape[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t src_stride = src_strides[0]
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 */
  __pyx_v_dst_extent = (__pyx_v_dst_shape[0]);

  /* "View.MemoryView":1151
 *     cdef Py_ssize_t src_extent = src_shape[0]
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 */
  __pyx_v_src_stride = (__pyx_v_src_strides[0]);

  /* "View.MemoryView":1152
 *     cdef Py_ssize_t dst_extent = dst_shape[0]
 *     cdef Py_ssize_t src_stride = src_strides[0]
 *     cdef Py_ssize_t dst_stride = dst_strides[0]             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 1:
 */
  __pyx_v_dst_stride = (__pyx_v_dst_strides[0]);

  /* "View.MemoryView":1154
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 */
  __pyx_t_1 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1155
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
    __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L5_bool_binop_done;
    }

    /* "View.MemoryView":1156
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):             # <<<<<<<<<<<<<<
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 *        else:
 */
    __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize);
    if (__pyx_t_2) {
      __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride));
    }
    __pyx_t_3 = (__pyx_t_2 != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L5_bool_binop_done:;

    /* "View.MemoryView":1155
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
    if (__pyx_t_1) {

      /* "View.MemoryView":1157
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)             # <<<<<<<<<<<<<<
 *        else:
 *            for i in range(dst_extent):
 */
      (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent)));

      /* "View.MemoryView":1155
 * 
 *     if ndim == 1:
 *        if (src_stride > 0 and dst_stride > 0 and             # <<<<<<<<<<<<<<
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 */
      goto __pyx_L4;
    }

    /* "View.MemoryView":1159
 *            memcpy(dst_data, src_data, itemsize * dst_extent)
 *        else:
 *            for i in range(dst_extent):             # <<<<<<<<<<<<<<
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride
 */
    /*else*/ {
      __pyx_t_4 = __pyx_v_dst_extent;
      __pyx_t_5 = __pyx_t_4;
      for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
        __pyx_v_i = __pyx_t_6;

        /* "View.MemoryView":1160
 *        else:
 *            for i in range(dst_extent):
 *                memcpy(dst_data, src_data, itemsize)             # <<<<<<<<<<<<<<
 *                src_data += src_stride
 *                dst_data += dst_stride
 */
        (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize));

        /* "View.MemoryView":1161
 *            for i in range(dst_extent):
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride             # <<<<<<<<<<<<<<
 *                dst_data += dst_stride
 *     else:
 */
        __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride);

        /* "View.MemoryView":1162
 *                memcpy(dst_data, src_data, itemsize)
 *                src_data += src_stride
 *                dst_data += dst_stride             # <<<<<<<<<<<<<<
 *     else:
 *         for i in range(dst_extent):
 */
        __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride);
      }
    }
    __pyx_L4:;

    /* "View.MemoryView":1154
 *     cdef Py_ssize_t dst_stride = dst_strides[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *        if (src_stride > 0 and dst_stride > 0 and
 *            <size_t> src_stride == itemsize == <size_t> dst_stride):
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1164
 *                dst_data += dst_stride
 *     else:
 *         for i in range(dst_extent):             # <<<<<<<<<<<<<<
 *             _copy_strided_to_strided(src_data, src_strides + 1,
 *                                      dst_data, dst_strides + 1,
 */
  /*else*/ {
    __pyx_t_4 = __pyx_v_dst_extent;
    __pyx_t_5 = __pyx_t_4;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "View.MemoryView":1165
 *     else:
 *         for i in range(dst_extent):
 *             _copy_strided_to_strided(src_data, src_strides + 1,             # <<<<<<<<<<<<<<
 *                                      dst_data, dst_strides + 1,
 *                                      src_shape + 1, dst_shape + 1,
 */
      _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize);

      /* "View.MemoryView":1169
 *                                      src_shape + 1, dst_shape + 1,
 *                                      ndim - 1, itemsize)
 *             src_data += src_stride             # <<<<<<<<<<<<<<
 *             dst_data += dst_stride
 * 
 */
      __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride);

      /* "View.MemoryView":1170
 *                                      ndim - 1, itemsize)
 *             src_data += src_stride
 *             dst_data += dst_stride             # <<<<<<<<<<<<<<
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,
 */
      __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride);
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1142
 * 
 * @cython.cdivision(True)
 * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides,             # <<<<<<<<<<<<<<
 *                                    char *dst_data, Py_ssize_t *dst_strides,
 *                                    Py_ssize_t *src_shape, Py_ssize_t *dst_shape,
 */

  /* function exit code */
}

/* "View.MemoryView":1172
 *             dst_data += dst_stride
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 */

static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) {
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("copy_strided_to_strided", __pyx_f[1], 1172, 1, __PYX_ERR(1, 1172, __pyx_L1_error));

  /* "View.MemoryView":1175
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 *     _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides,             # <<<<<<<<<<<<<<
 *                              src.shape, dst.shape, ndim, itemsize)
 * 
 */
  __Pyx_TraceLine(1175,1,__PYX_ERR(1, 1175, __pyx_L1_error))
  _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize);

  /* "View.MemoryView":1172
 *             dst_data += dst_stride
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.copy_strided_to_strided", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
}

/* "View.MemoryView":1179
 * 
 * @cname('__pyx_memoryview_slice_get_size')
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 */

static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) {
  Py_ssize_t __pyx_v_shape;
  Py_ssize_t __pyx_v_size;
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t *__pyx_t_2;
  Py_ssize_t *__pyx_t_3;
  Py_ssize_t *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("slice_get_size", __pyx_f[1], 1179, 1, __PYX_ERR(1, 1179, __pyx_L1_error));

  /* "View.MemoryView":1181
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 * 
 *     for shape in src.shape[:ndim]:
 */
  __Pyx_TraceLine(1181,1,__PYX_ERR(1, 1181, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_src->memview->view.itemsize;
  __pyx_v_size = __pyx_t_1;

  /* "View.MemoryView":1183
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 * 
 *     for shape in src.shape[:ndim]:             # <<<<<<<<<<<<<<
 *         size *= shape
 * 
 */
  __Pyx_TraceLine(1183,1,__PYX_ERR(1, 1183, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v_src->shape + __pyx_v_ndim);
  for (__pyx_t_4 = __pyx_v_src->shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
    __pyx_t_2 = __pyx_t_4;
    __pyx_v_shape = (__pyx_t_2[0]);

    /* "View.MemoryView":1184
 * 
 *     for shape in src.shape[:ndim]:
 *         size *= shape             # <<<<<<<<<<<<<<
 * 
 *     return size
 */
    __Pyx_TraceLine(1184,1,__PYX_ERR(1, 1184, __pyx_L1_error))
    __pyx_v_size = (__pyx_v_size * __pyx_v_shape);
  }

  /* "View.MemoryView":1186
 *         size *= shape
 * 
 *     return size             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_fill_contig_strides_array')
 */
  __Pyx_TraceLine(1186,1,__PYX_ERR(1, 1186, __pyx_L1_error))
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "View.MemoryView":1179
 * 
 * @cname('__pyx_memoryview_slice_get_size')
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.slice_get_size", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1189
 * 
 * @cname('__pyx_fill_contig_strides_array')
 * cdef Py_ssize_t fill_contig_strides_array(             # <<<<<<<<<<<<<<
 *                 Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride,
 *                 int ndim, char order) nogil:
 */

static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) {
  int __pyx_v_idx;
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("fill_contig_strides_array", __pyx_f[1], 1189, 1, __PYX_ERR(1, 1189, __pyx_L1_error));

  /* "View.MemoryView":1198
 *     cdef int idx
 * 
 *     if order == 'F':             # <<<<<<<<<<<<<<
 *         for idx in range(ndim):
 *             strides[idx] = stride
 */
  __Pyx_TraceLine(1198,1,__PYX_ERR(1, 1198, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_order == 'F') != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1199
 * 
 *     if order == 'F':
 *         for idx in range(ndim):             # <<<<<<<<<<<<<<
 *             strides[idx] = stride
 *             stride *= shape[idx]
 */
    __Pyx_TraceLine(1199,1,__PYX_ERR(1, 1199, __pyx_L1_error))
    __pyx_t_2 = __pyx_v_ndim;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_idx = __pyx_t_4;

      /* "View.MemoryView":1200
 *     if order == 'F':
 *         for idx in range(ndim):
 *             strides[idx] = stride             # <<<<<<<<<<<<<<
 *             stride *= shape[idx]
 *     else:
 */
      __Pyx_TraceLine(1200,1,__PYX_ERR(1, 1200, __pyx_L1_error))
      (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride;

      /* "View.MemoryView":1201
 *         for idx in range(ndim):
 *             strides[idx] = stride
 *             stride *= shape[idx]             # <<<<<<<<<<<<<<
 *     else:
 *         for idx in range(ndim - 1, -1, -1):
 */
      __Pyx_TraceLine(1201,1,__PYX_ERR(1, 1201, __pyx_L1_error))
      __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx]));
    }

    /* "View.MemoryView":1198
 *     cdef int idx
 * 
 *     if order == 'F':             # <<<<<<<<<<<<<<
 *         for idx in range(ndim):
 *             strides[idx] = stride
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1203
 *             stride *= shape[idx]
 *     else:
 *         for idx in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *             strides[idx] = stride
 *             stride *= shape[idx]
 */
  __Pyx_TraceLine(1203,1,__PYX_ERR(1, 1203, __pyx_L1_error))
  /*else*/ {
    for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) {
      __pyx_v_idx = __pyx_t_2;

      /* "View.MemoryView":1204
 *     else:
 *         for idx in range(ndim - 1, -1, -1):
 *             strides[idx] = stride             # <<<<<<<<<<<<<<
 *             stride *= shape[idx]
 * 
 */
      __Pyx_TraceLine(1204,1,__PYX_ERR(1, 1204, __pyx_L1_error))
      (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride;

      /* "View.MemoryView":1205
 *         for idx in range(ndim - 1, -1, -1):
 *             strides[idx] = stride
 *             stride *= shape[idx]             # <<<<<<<<<<<<<<
 * 
 *     return stride
 */
      __Pyx_TraceLine(1205,1,__PYX_ERR(1, 1205, __pyx_L1_error))
      __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx]));
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1207
 *             stride *= shape[idx]
 * 
 *     return stride             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 */
  __Pyx_TraceLine(1207,1,__PYX_ERR(1, 1207, __pyx_L1_error))
  __pyx_r = __pyx_v_stride;
  goto __pyx_L0;

  /* "View.MemoryView":1189
 * 
 * @cname('__pyx_fill_contig_strides_array')
 * cdef Py_ssize_t fill_contig_strides_array(             # <<<<<<<<<<<<<<
 *                 Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride,
 *                 int ndim, char order) nogil:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.fill_contig_strides_array", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1210
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 * cdef void *copy_data_to_temp(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                              __Pyx_memviewslice *tmpslice,
 *                              char order,
 */

static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) {
  int __pyx_v_i;
  void *__pyx_v_result;
  size_t __pyx_v_itemsize;
  size_t __pyx_v_size;
  void *__pyx_r;
  __Pyx_TraceDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_memoryview_obj *__pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("copy_data_to_temp", __pyx_f[1], 1210, 1, __PYX_ERR(1, 1210, __pyx_L1_error));

  /* "View.MemoryView":1221
 *     cdef void *result
 * 
 *     cdef size_t itemsize = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 *     cdef size_t size = slice_get_size(src, ndim)
 * 
 */
  __Pyx_TraceLine(1221,1,__PYX_ERR(1, 1221, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_src->memview->view.itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":1222
 * 
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef size_t size = slice_get_size(src, ndim)             # <<<<<<<<<<<<<<
 * 
 *     result = malloc(size)
 */
  __Pyx_TraceLine(1222,1,__PYX_ERR(1, 1222, __pyx_L1_error))
  __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim);

  /* "View.MemoryView":1224
 *     cdef size_t size = slice_get_size(src, ndim)
 * 
 *     result = malloc(size)             # <<<<<<<<<<<<<<
 *     if not result:
 *         _err(MemoryError, NULL)
 */
  __Pyx_TraceLine(1224,1,__PYX_ERR(1, 1224, __pyx_L1_error))
  __pyx_v_result = malloc(__pyx_v_size);

  /* "View.MemoryView":1225
 * 
 *     result = malloc(size)
 *     if not result:             # <<<<<<<<<<<<<<
 *         _err(MemoryError, NULL)
 * 
 */
  __Pyx_TraceLine(1225,1,__PYX_ERR(1, 1225, __pyx_L1_error))
  __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1226
 *     result = malloc(size)
 *     if not result:
 *         _err(MemoryError, NULL)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(1226,1,__PYX_ERR(1, 1226, __pyx_L1_error))
    __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 1226, __pyx_L1_error)

    /* "View.MemoryView":1225
 * 
 *     result = malloc(size)
 *     if not result:             # <<<<<<<<<<<<<<
 *         _err(MemoryError, NULL)
 * 
 */
  }

  /* "View.MemoryView":1229
 * 
 * 
 *     tmpslice.data = <char *> result             # <<<<<<<<<<<<<<
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):
 */
  __Pyx_TraceLine(1229,1,__PYX_ERR(1, 1229, __pyx_L1_error))
  __pyx_v_tmpslice->data = ((char *)__pyx_v_result);

  /* "View.MemoryView":1230
 * 
 *     tmpslice.data = <char *> result
 *     tmpslice.memview = src.memview             # <<<<<<<<<<<<<<
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]
 */
  __Pyx_TraceLine(1230,1,__PYX_ERR(1, 1230, __pyx_L1_error))
  __pyx_t_4 = __pyx_v_src->memview;
  __pyx_v_tmpslice->memview = __pyx_t_4;

  /* "View.MemoryView":1231
 *     tmpslice.data = <char *> result
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         tmpslice.shape[i] = src.shape[i]
 *         tmpslice.suboffsets[i] = -1
 */
  __Pyx_TraceLine(1231,1,__PYX_ERR(1, 1231, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_ndim;
  __pyx_t_5 = __pyx_t_3;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "View.MemoryView":1232
 *     tmpslice.memview = src.memview
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]             # <<<<<<<<<<<<<<
 *         tmpslice.suboffsets[i] = -1
 * 
 */
    __Pyx_TraceLine(1232,1,__PYX_ERR(1, 1232, __pyx_L1_error))
    (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]);

    /* "View.MemoryView":1233
 *     for i in range(ndim):
 *         tmpslice.shape[i] = src.shape[i]
 *         tmpslice.suboffsets[i] = -1             # <<<<<<<<<<<<<<
 * 
 *     fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize,
 */
    __Pyx_TraceLine(1233,1,__PYX_ERR(1, 1233, __pyx_L1_error))
    (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L;
  }

  /* "View.MemoryView":1235
 *         tmpslice.suboffsets[i] = -1
 * 
 *     fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize,             # <<<<<<<<<<<<<<
 *                               ndim, order)
 * 
 */
  __Pyx_TraceLine(1235,1,__PYX_ERR(1, 1235, __pyx_L1_error))
  (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order));

  /* "View.MemoryView":1239
 * 
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if tmpslice.shape[i] == 1:
 *             tmpslice.strides[i] = 0
 */
  __Pyx_TraceLine(1239,1,__PYX_ERR(1, 1239, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_ndim;
  __pyx_t_5 = __pyx_t_3;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
    __pyx_v_i = __pyx_t_6;

    /* "View.MemoryView":1240
 * 
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:             # <<<<<<<<<<<<<<
 *             tmpslice.strides[i] = 0
 * 
 */
    __Pyx_TraceLine(1240,1,__PYX_ERR(1, 1240, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1241
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:
 *             tmpslice.strides[i] = 0             # <<<<<<<<<<<<<<
 * 
 *     if slice_is_contig(src[0], order, ndim):
 */
      __Pyx_TraceLine(1241,1,__PYX_ERR(1, 1241, __pyx_L1_error))
      (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0;

      /* "View.MemoryView":1240
 * 
 *     for i in range(ndim):
 *         if tmpslice.shape[i] == 1:             # <<<<<<<<<<<<<<
 *             tmpslice.strides[i] = 0
 * 
 */
    }
  }

  /* "View.MemoryView":1243
 *             tmpslice.strides[i] = 0
 * 
 *     if slice_is_contig(src[0], order, ndim):             # <<<<<<<<<<<<<<
 *         memcpy(result, src.data, size)
 *     else:
 */
  __Pyx_TraceLine(1243,1,__PYX_ERR(1, 1243, __pyx_L1_error))
  __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1244
 * 
 *     if slice_is_contig(src[0], order, ndim):
 *         memcpy(result, src.data, size)             # <<<<<<<<<<<<<<
 *     else:
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)
 */
    __Pyx_TraceLine(1244,1,__PYX_ERR(1, 1244, __pyx_L1_error))
    (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size));

    /* "View.MemoryView":1243
 *             tmpslice.strides[i] = 0
 * 
 *     if slice_is_contig(src[0], order, ndim):             # <<<<<<<<<<<<<<
 *         memcpy(result, src.data, size)
 *     else:
 */
    goto __pyx_L9;
  }

  /* "View.MemoryView":1246
 *         memcpy(result, src.data, size)
 *     else:
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  __Pyx_TraceLine(1246,1,__PYX_ERR(1, 1246, __pyx_L1_error))
  /*else*/ {
    copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize);
  }
  __pyx_L9:;

  /* "View.MemoryView":1248
 *         copy_strided_to_strided(src, tmpslice, ndim, itemsize)
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1248,1,__PYX_ERR(1, 1248, __pyx_L1_error))
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "View.MemoryView":1210
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 * cdef void *copy_data_to_temp(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                              __Pyx_memviewslice *tmpslice,
 *                              char order,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1253
 * 
 * @cname('__pyx_memoryview_err_extents')
 * cdef int _err_extents(int i, Py_ssize_t extent1,             # <<<<<<<<<<<<<<
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 */

static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err_extents", 0);
  __Pyx_TraceCall("_err_extents", __pyx_f[1], 1253, 0, __PYX_ERR(1, 1253, __pyx_L1_error));

  /* "View.MemoryView":1256
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 *                                                         (i, extent1, extent2))             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_err_dim')
 */
  __Pyx_TraceLine(1256,0,__PYX_ERR(1, 1256, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "View.MemoryView":1255
 * cdef int _err_extents(int i, Py_ssize_t extent1,
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %             # <<<<<<<<<<<<<<
 *                                                         (i, extent1, extent2))
 * 
 */
  __Pyx_TraceLine(1255,0,__PYX_ERR(1, 1255, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1255, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1255, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_4, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __PYX_ERR(1, 1255, __pyx_L1_error)

  /* "View.MemoryView":1253
 * 
 * @cname('__pyx_memoryview_err_extents')
 * cdef int _err_extents(int i, Py_ssize_t extent1,             # <<<<<<<<<<<<<<
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1259
 * 
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:             # <<<<<<<<<<<<<<
 *     raise error(msg.decode('ascii') % dim)
 * 
 */

static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err_dim", 0);
  __Pyx_TraceCall("_err_dim", __pyx_f[1], 1259, 0, __PYX_ERR(1, 1259, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_error);

  /* "View.MemoryView":1260
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:
 *     raise error(msg.decode('ascii') % dim)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_err')
 */
  __Pyx_TraceLine(1260,0,__PYX_ERR(1, 1260, __pyx_L1_error))
  __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(__pyx_v_error);
  __pyx_t_3 = __pyx_v_error; __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, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 1260, __pyx_L1_error)

  /* "View.MemoryView":1259
 * 
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:             # <<<<<<<<<<<<<<
 *     raise error(msg.decode('ascii') % dim)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1263
 * 
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:             # <<<<<<<<<<<<<<
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))
 */

static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_err", 0);
  __Pyx_TraceCall("_err", __pyx_f[1], 1263, 0, __PYX_ERR(1, 1263, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_error);

  /* "View.MemoryView":1264
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:             # <<<<<<<<<<<<<<
 *         raise error(msg.decode('ascii'))
 *     else:
 */
  __Pyx_TraceLine(1264,0,__PYX_ERR(1, 1264, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_msg != NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "View.MemoryView":1265
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))             # <<<<<<<<<<<<<<
 *     else:
 *         raise error
 */
    __Pyx_TraceLine(1265,0,__PYX_ERR(1, 1265, __pyx_L1_error))
    __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1265, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_error);
    __pyx_t_4 = __pyx_v_error; __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1265, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 1265, __pyx_L1_error)

    /* "View.MemoryView":1264
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:
 *     if msg != NULL:             # <<<<<<<<<<<<<<
 *         raise error(msg.decode('ascii'))
 *     else:
 */
  }

  /* "View.MemoryView":1267
 *         raise error(msg.decode('ascii'))
 *     else:
 *         raise error             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_copy_contents')
 */
  __Pyx_TraceLine(1267,0,__PYX_ERR(1, 1267, __pyx_L1_error))
  /*else*/ {
    __Pyx_Raise(__pyx_v_error, 0, 0, 0);
    __PYX_ERR(1, 1267, __pyx_L1_error)
  }

  /* "View.MemoryView":1263
 * 
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:             # <<<<<<<<<<<<<<
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "View.MemoryView":1270
 * 
 * @cname('__pyx_memoryview_copy_contents')
 * cdef int memoryview_copy_contents(__Pyx_memviewslice src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice dst,
 *                                   int src_ndim, int dst_ndim,
 */

static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) {
  void *__pyx_v_tmpdata;
  size_t __pyx_v_itemsize;
  int __pyx_v_i;
  char __pyx_v_order;
  int __pyx_v_broadcasting;
  int __pyx_v_direct_copy;
  __Pyx_memviewslice __pyx_v_tmp;
  int __pyx_v_ndim;
  int __pyx_r;
  __Pyx_TraceDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  void *__pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("memoryview_copy_contents", __pyx_f[1], 1270, 1, __PYX_ERR(1, 1270, __pyx_L1_error));

  /* "View.MemoryView":1278
 *     Check for overlapping memory and verify the shapes.
 *     """
 *     cdef void *tmpdata = NULL             # <<<<<<<<<<<<<<
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef int i
 */
  __Pyx_TraceLine(1278,1,__PYX_ERR(1, 1278, __pyx_L1_error))
  __pyx_v_tmpdata = NULL;

  /* "View.MemoryView":1279
 *     """
 *     cdef void *tmpdata = NULL
 *     cdef size_t itemsize = src.memview.view.itemsize             # <<<<<<<<<<<<<<
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)
 */
  __Pyx_TraceLine(1279,1,__PYX_ERR(1, 1279, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_src.memview->view.itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "View.MemoryView":1281
 *     cdef size_t itemsize = src.memview.view.itemsize
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)             # <<<<<<<<<<<<<<
 *     cdef bint broadcasting = False
 *     cdef bint direct_copy = False
 */
  __Pyx_TraceLine(1281,1,__PYX_ERR(1, 1281, __pyx_L1_error))
  __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim);

  /* "View.MemoryView":1282
 *     cdef int i
 *     cdef char order = get_best_order(&src, src_ndim)
 *     cdef bint broadcasting = False             # <<<<<<<<<<<<<<
 *     cdef bint direct_copy = False
 *     cdef __Pyx_memviewslice tmp
 */
  __Pyx_TraceLine(1282,1,__PYX_ERR(1, 1282, __pyx_L1_error))
  __pyx_v_broadcasting = 0;

  /* "View.MemoryView":1283
 *     cdef char order = get_best_order(&src, src_ndim)
 *     cdef bint broadcasting = False
 *     cdef bint direct_copy = False             # <<<<<<<<<<<<<<
 *     cdef __Pyx_memviewslice tmp
 * 
 */
  __Pyx_TraceLine(1283,1,__PYX_ERR(1, 1283, __pyx_L1_error))
  __pyx_v_direct_copy = 0;

  /* "View.MemoryView":1286
 *     cdef __Pyx_memviewslice tmp
 * 
 *     if src_ndim < dst_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 */
  __Pyx_TraceLine(1286,1,__PYX_ERR(1, 1286, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1287
 * 
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)             # <<<<<<<<<<<<<<
 *     elif dst_ndim < src_ndim:
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 */
    __Pyx_TraceLine(1287,1,__PYX_ERR(1, 1287, __pyx_L1_error))
    __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim);

    /* "View.MemoryView":1286
 *     cdef __Pyx_memviewslice tmp
 * 
 *     if src_ndim < dst_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1288
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 */
  __Pyx_TraceLine(1288,1,__PYX_ERR(1, 1288, __pyx_L1_error))
  __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1289
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:
 *         broadcast_leading(&dst, dst_ndim, src_ndim)             # <<<<<<<<<<<<<<
 * 
 *     cdef int ndim = max(src_ndim, dst_ndim)
 */
    __Pyx_TraceLine(1289,1,__PYX_ERR(1, 1289, __pyx_L1_error))
    __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim);

    /* "View.MemoryView":1288
 *     if src_ndim < dst_ndim:
 *         broadcast_leading(&src, src_ndim, dst_ndim)
 *     elif dst_ndim < src_ndim:             # <<<<<<<<<<<<<<
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 */
  }
  __pyx_L3:;

  /* "View.MemoryView":1291
 *         broadcast_leading(&dst, dst_ndim, src_ndim)
 * 
 *     cdef int ndim = max(src_ndim, dst_ndim)             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim):
 */
  __Pyx_TraceLine(1291,1,__PYX_ERR(1, 1291, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_dst_ndim;
  __pyx_t_4 = __pyx_v_src_ndim;
  if (((__pyx_t_3 > __pyx_t_4) != 0)) {
    __pyx_t_5 = __pyx_t_3;
  } else {
    __pyx_t_5 = __pyx_t_4;
  }
  __pyx_v_ndim = __pyx_t_5;

  /* "View.MemoryView":1293
 *     cdef int ndim = max(src_ndim, dst_ndim)
 * 
 *     for i in range(ndim):             # <<<<<<<<<<<<<<
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:
 */
  __Pyx_TraceLine(1293,1,__PYX_ERR(1, 1293, __pyx_L1_error))
  __pyx_t_5 = __pyx_v_ndim;
  __pyx_t_3 = __pyx_t_5;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;

    /* "View.MemoryView":1294
 * 
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:             # <<<<<<<<<<<<<<
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 */
    __Pyx_TraceLine(1294,1,__PYX_ERR(1, 1294, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1295
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:             # <<<<<<<<<<<<<<
 *                 broadcasting = True
 *                 src.strides[i] = 0
 */
      __Pyx_TraceLine(1295,1,__PYX_ERR(1, 1295, __pyx_L1_error))
      __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0);
      if (__pyx_t_2) {

        /* "View.MemoryView":1296
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:
 *                 broadcasting = True             # <<<<<<<<<<<<<<
 *                 src.strides[i] = 0
 *             else:
 */
        __Pyx_TraceLine(1296,1,__PYX_ERR(1, 1296, __pyx_L1_error))
        __pyx_v_broadcasting = 1;

        /* "View.MemoryView":1297
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 *                 src.strides[i] = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 */
        __Pyx_TraceLine(1297,1,__PYX_ERR(1, 1297, __pyx_L1_error))
        (__pyx_v_src.strides[__pyx_v_i]) = 0;

        /* "View.MemoryView":1295
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:
 *             if src.shape[i] == 1:             # <<<<<<<<<<<<<<
 *                 broadcasting = True
 *                 src.strides[i] = 0
 */
        goto __pyx_L7;
      }

      /* "View.MemoryView":1299
 *                 src.strides[i] = 0
 *             else:
 *                 _err_extents(i, dst.shape[i], src.shape[i])             # <<<<<<<<<<<<<<
 * 
 *         if src.suboffsets[i] >= 0:
 */
      __Pyx_TraceLine(1299,1,__PYX_ERR(1, 1299, __pyx_L1_error))
      /*else*/ {
        __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1299, __pyx_L1_error)
      }
      __pyx_L7:;

      /* "View.MemoryView":1294
 * 
 *     for i in range(ndim):
 *         if src.shape[i] != dst.shape[i]:             # <<<<<<<<<<<<<<
 *             if src.shape[i] == 1:
 *                 broadcasting = True
 */
    }

    /* "View.MemoryView":1301
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 * 
 *         if src.suboffsets[i] >= 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 */
    __Pyx_TraceLine(1301,1,__PYX_ERR(1, 1301, __pyx_L1_error))
    __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1302
 * 
 *         if src.suboffsets[i] >= 0:
 *             _err_dim(ValueError, "Dimension %d is not direct", i)             # <<<<<<<<<<<<<<
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 */
      __Pyx_TraceLine(1302,1,__PYX_ERR(1, 1302, __pyx_L1_error))
      __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1302, __pyx_L1_error)

      /* "View.MemoryView":1301
 *                 _err_extents(i, dst.shape[i], src.shape[i])
 * 
 *         if src.suboffsets[i] >= 0:             # <<<<<<<<<<<<<<
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 */
    }
  }

  /* "View.MemoryView":1304
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):             # <<<<<<<<<<<<<<
 * 
 *         if not slice_is_contig(src, order, ndim):
 */
  __Pyx_TraceLine(1304,1,__PYX_ERR(1, 1304, __pyx_L1_error))
  __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1306
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 * 
 *         if not slice_is_contig(src, order, ndim):             # <<<<<<<<<<<<<<
 *             order = get_best_order(&dst, ndim)
 * 
 */
    __Pyx_TraceLine(1306,1,__PYX_ERR(1, 1306, __pyx_L1_error))
    __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1307
 * 
 *         if not slice_is_contig(src, order, ndim):
 *             order = get_best_order(&dst, ndim)             # <<<<<<<<<<<<<<
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)
 */
      __Pyx_TraceLine(1307,1,__PYX_ERR(1, 1307, __pyx_L1_error))
      __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim);

      /* "View.MemoryView":1306
 *     if slices_overlap(&src, &dst, ndim, itemsize):
 * 
 *         if not slice_is_contig(src, order, ndim):             # <<<<<<<<<<<<<<
 *             order = get_best_order(&dst, ndim)
 * 
 */
    }

    /* "View.MemoryView":1309
 *             order = get_best_order(&dst, ndim)
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)             # <<<<<<<<<<<<<<
 *         src = tmp
 * 
 */
    __Pyx_TraceLine(1309,1,__PYX_ERR(1, 1309, __pyx_L1_error))
    __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(1, 1309, __pyx_L1_error)
    __pyx_v_tmpdata = __pyx_t_7;

    /* "View.MemoryView":1310
 * 
 *         tmpdata = copy_data_to_temp(&src, &tmp, order, ndim)
 *         src = tmp             # <<<<<<<<<<<<<<
 * 
 *     if not broadcasting:
 */
    __Pyx_TraceLine(1310,1,__PYX_ERR(1, 1310, __pyx_L1_error))
    __pyx_v_src = __pyx_v_tmp;

    /* "View.MemoryView":1304
 *             _err_dim(ValueError, "Dimension %d is not direct", i)
 * 
 *     if slices_overlap(&src, &dst, ndim, itemsize):             # <<<<<<<<<<<<<<
 * 
 *         if not slice_is_contig(src, order, ndim):
 */
  }

  /* "View.MemoryView":1312
 *         src = tmp
 * 
 *     if not broadcasting:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1312,1,__PYX_ERR(1, 1312, __pyx_L1_error))
  __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0);
  if (__pyx_t_2) {

    /* "View.MemoryView":1315
 * 
 * 
 *         if slice_is_contig(src, 'C', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 */
    __Pyx_TraceLine(1315,1,__PYX_ERR(1, 1315, __pyx_L1_error))
    __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1316
 * 
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)             # <<<<<<<<<<<<<<
 *         elif slice_is_contig(src, 'F', ndim):
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 */
      __Pyx_TraceLine(1316,1,__PYX_ERR(1, 1316, __pyx_L1_error))
      __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim);

      /* "View.MemoryView":1315
 * 
 * 
 *         if slice_is_contig(src, 'C', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 */
      goto __pyx_L12;
    }

    /* "View.MemoryView":1317
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 */
    __Pyx_TraceLine(1317,1,__PYX_ERR(1, 1317, __pyx_L1_error))
    __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1318
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):
 *             direct_copy = slice_is_contig(dst, 'F', ndim)             # <<<<<<<<<<<<<<
 * 
 *         if direct_copy:
 */
      __Pyx_TraceLine(1318,1,__PYX_ERR(1, 1318, __pyx_L1_error))
      __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim);

      /* "View.MemoryView":1317
 *         if slice_is_contig(src, 'C', ndim):
 *             direct_copy = slice_is_contig(dst, 'C', ndim)
 *         elif slice_is_contig(src, 'F', ndim):             # <<<<<<<<<<<<<<
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 */
    }
    __pyx_L12:;

    /* "View.MemoryView":1320
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 *         if direct_copy:             # <<<<<<<<<<<<<<
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    __Pyx_TraceLine(1320,1,__PYX_ERR(1, 1320, __pyx_L1_error))
    __pyx_t_2 = (__pyx_v_direct_copy != 0);
    if (__pyx_t_2) {

      /* "View.MemoryView":1322
 *         if direct_copy:
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 */
      __Pyx_TraceLine(1322,1,__PYX_ERR(1, 1322, __pyx_L1_error))
      __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

      /* "View.MemoryView":1323
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))             # <<<<<<<<<<<<<<
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)
 */
      __Pyx_TraceLine(1323,1,__PYX_ERR(1, 1323, __pyx_L1_error))
      (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim)));

      /* "View.MemoryView":1324
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 *             free(tmpdata)
 *             return 0
 */
      __Pyx_TraceLine(1324,1,__PYX_ERR(1, 1324, __pyx_L1_error))
      __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

      /* "View.MemoryView":1325
 *             memcpy(dst.data, src.data, slice_get_size(&src, ndim))
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
      __Pyx_TraceLine(1325,1,__PYX_ERR(1, 1325, __pyx_L1_error))
      free(__pyx_v_tmpdata);

      /* "View.MemoryView":1326
 *             refcount_copying(&dst, dtype_is_object, ndim, True)
 *             free(tmpdata)
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):
 */
      __Pyx_TraceLine(1326,1,__PYX_ERR(1, 1326, __pyx_L1_error))
      __pyx_r = 0;
      goto __pyx_L0;

      /* "View.MemoryView":1320
 *             direct_copy = slice_is_contig(dst, 'F', ndim)
 * 
 *         if direct_copy:             # <<<<<<<<<<<<<<
 * 
 *             refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    }

    /* "View.MemoryView":1312
 *         src = tmp
 * 
 *     if not broadcasting:             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":1328
 *             return 0
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1328,1,__PYX_ERR(1, 1328, __pyx_L1_error))
  __pyx_t_2 = (__pyx_v_order == 'F');
  if (__pyx_t_2) {
    __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim));
  }
  __pyx_t_8 = (__pyx_t_2 != 0);
  if (__pyx_t_8) {

    /* "View.MemoryView":1331
 * 
 * 
 *         transpose_memslice(&src)             # <<<<<<<<<<<<<<
 *         transpose_memslice(&dst)
 * 
 */
    __Pyx_TraceLine(1331,1,__PYX_ERR(1, 1331, __pyx_L1_error))
    __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1331, __pyx_L1_error)

    /* "View.MemoryView":1332
 * 
 *         transpose_memslice(&src)
 *         transpose_memslice(&dst)             # <<<<<<<<<<<<<<
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 */
    __Pyx_TraceLine(1332,1,__PYX_ERR(1, 1332, __pyx_L1_error))
    __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1332, __pyx_L1_error)

    /* "View.MemoryView":1328
 *             return 0
 * 
 *     if order == 'F' == get_best_order(&dst, ndim):             # <<<<<<<<<<<<<<
 * 
 * 
 */
  }

  /* "View.MemoryView":1334
 *         transpose_memslice(&dst)
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 */
  __Pyx_TraceLine(1334,1,__PYX_ERR(1, 1334, __pyx_L1_error))
  __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

  /* "View.MemoryView":1335
 * 
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)             # <<<<<<<<<<<<<<
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 * 
 */
  __Pyx_TraceLine(1335,1,__PYX_ERR(1, 1335, __pyx_L1_error))
  copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize);

  /* "View.MemoryView":1336
 *     refcount_copying(&dst, dtype_is_object, ndim, False)
 *     copy_strided_to_strided(&src, &dst, ndim, itemsize)
 *     refcount_copying(&dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 * 
 *     free(tmpdata)
 */
  __Pyx_TraceLine(1336,1,__PYX_ERR(1, 1336, __pyx_L1_error))
  __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

  /* "View.MemoryView":1338
 *     refcount_copying(&dst, dtype_is_object, ndim, True)
 * 
 *     free(tmpdata)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  __Pyx_TraceLine(1338,1,__PYX_ERR(1, 1338, __pyx_L1_error))
  free(__pyx_v_tmpdata);

  /* "View.MemoryView":1339
 * 
 *     free(tmpdata)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 */
  __Pyx_TraceLine(1339,1,__PYX_ERR(1, 1339, __pyx_L1_error))
  __pyx_r = 0;
  goto __pyx_L0;

  /* "View.MemoryView":1270
 * 
 * @cname('__pyx_memoryview_copy_contents')
 * cdef int memoryview_copy_contents(__Pyx_memviewslice src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice dst,
 *                                   int src_ndim, int dst_ndim,
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    __Pyx_PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  return __pyx_r;
}

/* "View.MemoryView":1342
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 * cdef void broadcast_leading(__Pyx_memviewslice *mslice,             # <<<<<<<<<<<<<<
 *                             int ndim,
 *                             int ndim_other) nogil:
 */

static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) {
  int __pyx_v_i;
  int __pyx_v_offset;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("broadcast_leading", __pyx_f[1], 1342, 1, __PYX_ERR(1, 1342, __pyx_L1_error));

  /* "View.MemoryView":1346
 *                             int ndim_other) nogil:
 *     cdef int i
 *     cdef int offset = ndim_other - ndim             # <<<<<<<<<<<<<<
 * 
 *     for i in range(ndim - 1, -1, -1):
 */
  __Pyx_TraceLine(1346,1,__PYX_ERR(1, 1346, __pyx_L1_error))
  __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim);

  /* "View.MemoryView":1348
 *     cdef int offset = ndim_other - ndim
 * 
 *     for i in range(ndim - 1, -1, -1):             # <<<<<<<<<<<<<<
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]
 */
  __Pyx_TraceLine(1348,1,__PYX_ERR(1, 1348, __pyx_L1_error))
  for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) {
    __pyx_v_i = __pyx_t_1;

    /* "View.MemoryView":1349
 * 
 *     for i in range(ndim - 1, -1, -1):
 *         mslice.shape[i + offset] = mslice.shape[i]             # <<<<<<<<<<<<<<
 *         mslice.strides[i + offset] = mslice.strides[i]
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 */
    __Pyx_TraceLine(1349,1,__PYX_ERR(1, 1349, __pyx_L1_error))
    (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]);

    /* "View.MemoryView":1350
 *     for i in range(ndim - 1, -1, -1):
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]             # <<<<<<<<<<<<<<
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 * 
 */
    __Pyx_TraceLine(1350,1,__PYX_ERR(1, 1350, __pyx_L1_error))
    (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]);

    /* "View.MemoryView":1351
 *         mslice.shape[i + offset] = mslice.shape[i]
 *         mslice.strides[i + offset] = mslice.strides[i]
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]             # <<<<<<<<<<<<<<
 * 
 *     for i in range(offset):
 */
    __Pyx_TraceLine(1351,1,__PYX_ERR(1, 1351, __pyx_L1_error))
    (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]);
  }

  /* "View.MemoryView":1353
 *         mslice.suboffsets[i + offset] = mslice.suboffsets[i]
 * 
 *     for i in range(offset):             # <<<<<<<<<<<<<<
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]
 */
  __Pyx_TraceLine(1353,1,__PYX_ERR(1, 1353, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_offset;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "View.MemoryView":1354
 * 
 *     for i in range(offset):
 *         mslice.shape[i] = 1             # <<<<<<<<<<<<<<
 *         mslice.strides[i] = mslice.strides[0]
 *         mslice.suboffsets[i] = -1
 */
    __Pyx_TraceLine(1354,1,__PYX_ERR(1, 1354, __pyx_L1_error))
    (__pyx_v_mslice->shape[__pyx_v_i]) = 1;

    /* "View.MemoryView":1355
 *     for i in range(offset):
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]             # <<<<<<<<<<<<<<
 *         mslice.suboffsets[i] = -1
 * 
 */
    __Pyx_TraceLine(1355,1,__PYX_ERR(1, 1355, __pyx_L1_error))
    (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]);

    /* "View.MemoryView":1356
 *         mslice.shape[i] = 1
 *         mslice.strides[i] = mslice.strides[0]
 *         mslice.suboffsets[i] = -1             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(1356,1,__PYX_ERR(1, 1356, __pyx_L1_error))
    (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L;
  }

  /* "View.MemoryView":1342
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 * cdef void broadcast_leading(__Pyx_memviewslice *mslice,             # <<<<<<<<<<<<<<
 *                             int ndim,
 *                             int ndim_other) nogil:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.broadcast_leading", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
}

/* "View.MemoryView":1364
 * 
 * @cname('__pyx_memoryview_refcount_copying')
 * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object,             # <<<<<<<<<<<<<<
 *                            int ndim, bint inc) nogil:
 * 
 */

static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) {
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("refcount_copying", __pyx_f[1], 1364, 1, __PYX_ERR(1, 1364, __pyx_L1_error));

  /* "View.MemoryView":1368
 * 
 * 
 *     if dtype_is_object:             # <<<<<<<<<<<<<<
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,
 *                                            dst.strides, ndim, inc)
 */
  __Pyx_TraceLine(1368,1,__PYX_ERR(1, 1368, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_dtype_is_object != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1369
 * 
 *     if dtype_is_object:
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,             # <<<<<<<<<<<<<<
 *                                            dst.strides, ndim, inc)
 * 
 */
    __Pyx_TraceLine(1369,1,__PYX_ERR(1, 1369, __pyx_L1_error))
    __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc);

    /* "View.MemoryView":1368
 * 
 * 
 *     if dtype_is_object:             # <<<<<<<<<<<<<<
 *         refcount_objects_in_slice_with_gil(dst.data, dst.shape,
 *                                            dst.strides, ndim, inc)
 */
  }

  /* "View.MemoryView":1364
 * 
 * @cname('__pyx_memoryview_refcount_copying')
 * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object,             # <<<<<<<<<<<<<<
 *                            int ndim, bint inc) nogil:
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.refcount_copying", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
}

/* "View.MemoryView":1373
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil')
 * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 */

static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0);
  __Pyx_TraceCall("refcount_objects_in_slice_with_gil", __pyx_f[1], 1373, 0, __PYX_ERR(1, 1373, __pyx_L1_error));

  /* "View.MemoryView":1376
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 *     refcount_objects_in_slice(data, shape, strides, ndim, inc)             # <<<<<<<<<<<<<<
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 */
  __Pyx_TraceLine(1376,0,__PYX_ERR(1, 1376, __pyx_L1_error))
  __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc);

  /* "View.MemoryView":1373
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil')
 * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice_with_gil", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
}

/* "View.MemoryView":1379
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                     Py_ssize_t *strides, int ndim, bint inc):
 *     cdef Py_ssize_t i
 */

static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0);
  __Pyx_TraceCall("refcount_objects_in_slice", __pyx_f[1], 1379, 0, __PYX_ERR(1, 1379, __pyx_L1_error));

  /* "View.MemoryView":1383
 *     cdef Py_ssize_t i
 * 
 *     for i in range(shape[0]):             # <<<<<<<<<<<<<<
 *         if ndim == 1:
 *             if inc:
 */
  __Pyx_TraceLine(1383,0,__PYX_ERR(1, 1383, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_shape[0]);
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;

    /* "View.MemoryView":1384
 * 
 *     for i in range(shape[0]):
 *         if ndim == 1:             # <<<<<<<<<<<<<<
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])
 */
    __Pyx_TraceLine(1384,0,__PYX_ERR(1, 1384, __pyx_L1_error))
    __pyx_t_4 = ((__pyx_v_ndim == 1) != 0);
    if (__pyx_t_4) {

      /* "View.MemoryView":1385
 *     for i in range(shape[0]):
 *         if ndim == 1:
 *             if inc:             # <<<<<<<<<<<<<<
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 */
      __Pyx_TraceLine(1385,0,__PYX_ERR(1, 1385, __pyx_L1_error))
      __pyx_t_4 = (__pyx_v_inc != 0);
      if (__pyx_t_4) {

        /* "View.MemoryView":1386
 *         if ndim == 1:
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])             # <<<<<<<<<<<<<<
 *             else:
 *                 Py_DECREF((<PyObject **> data)[0])
 */
        __Pyx_TraceLine(1386,0,__PYX_ERR(1, 1386, __pyx_L1_error))
        Py_INCREF((((PyObject **)__pyx_v_data)[0]));

        /* "View.MemoryView":1385
 *     for i in range(shape[0]):
 *         if ndim == 1:
 *             if inc:             # <<<<<<<<<<<<<<
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 */
        goto __pyx_L6;
      }

      /* "View.MemoryView":1388
 *                 Py_INCREF((<PyObject **> data)[0])
 *             else:
 *                 Py_DECREF((<PyObject **> data)[0])             # <<<<<<<<<<<<<<
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,
 */
      __Pyx_TraceLine(1388,0,__PYX_ERR(1, 1388, __pyx_L1_error))
      /*else*/ {
        Py_DECREF((((PyObject **)__pyx_v_data)[0]));
      }
      __pyx_L6:;

      /* "View.MemoryView":1384
 * 
 *     for i in range(shape[0]):
 *         if ndim == 1:             # <<<<<<<<<<<<<<
 *             if inc:
 *                 Py_INCREF((<PyObject **> data)[0])
 */
      goto __pyx_L5;
    }

    /* "View.MemoryView":1390
 *                 Py_DECREF((<PyObject **> data)[0])
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,             # <<<<<<<<<<<<<<
 *                                       ndim - 1, inc)
 * 
 */
    __Pyx_TraceLine(1390,0,__PYX_ERR(1, 1390, __pyx_L1_error))
    /*else*/ {

      /* "View.MemoryView":1391
 *         else:
 *             refcount_objects_in_slice(data, shape + 1, strides + 1,
 *                                       ndim - 1, inc)             # <<<<<<<<<<<<<<
 * 
 *         data += strides[0]
 */
      __Pyx_TraceLine(1391,0,__PYX_ERR(1, 1391, __pyx_L1_error))
      __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc);
    }
    __pyx_L5:;

    /* "View.MemoryView":1393
 *                                       ndim - 1, inc)
 * 
 *         data += strides[0]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_TraceLine(1393,0,__PYX_ERR(1, 1393, __pyx_L1_error))
    __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0]));
  }

  /* "View.MemoryView":1379
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                     Py_ssize_t *strides, int ndim, bint inc):
 *     cdef Py_ssize_t i
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "View.MemoryView":1399
 * 
 * @cname('__pyx_memoryview_slice_assign_scalar')
 * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim,             # <<<<<<<<<<<<<<
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 */

static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) {
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("slice_assign_scalar", __pyx_f[1], 1399, 1, __PYX_ERR(1, 1399, __pyx_L1_error));

  /* "View.MemoryView":1402
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 *     refcount_copying(dst, dtype_is_object, ndim, False)             # <<<<<<<<<<<<<<
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,
 *                          itemsize, item)
 */
  __Pyx_TraceLine(1402,1,__PYX_ERR(1, 1402, __pyx_L1_error))
  __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0);

  /* "View.MemoryView":1403
 *                               bint dtype_is_object) nogil:
 *     refcount_copying(dst, dtype_is_object, ndim, False)
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,             # <<<<<<<<<<<<<<
 *                          itemsize, item)
 *     refcount_copying(dst, dtype_is_object, ndim, True)
 */
  __Pyx_TraceLine(1403,1,__PYX_ERR(1, 1403, __pyx_L1_error))
  __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item);

  /* "View.MemoryView":1405
 *     _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim,
 *                          itemsize, item)
 *     refcount_copying(dst, dtype_is_object, ndim, True)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1405,1,__PYX_ERR(1, 1405, __pyx_L1_error))
  __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1);

  /* "View.MemoryView":1399
 * 
 * @cname('__pyx_memoryview_slice_assign_scalar')
 * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim,             # <<<<<<<<<<<<<<
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView.slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
}

/* "View.MemoryView":1409
 * 
 * @cname('__pyx_memoryview__slice_assign_scalar')
 * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                               Py_ssize_t *strides, int ndim,
 *                               size_t itemsize, void *item) nogil:
 */

static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) {
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_stride;
  Py_ssize_t __pyx_v_extent;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("_slice_assign_scalar", __pyx_f[1], 1409, 1, __PYX_ERR(1, 1409, __pyx_L1_error));

  /* "View.MemoryView":1413
 *                               size_t itemsize, void *item) nogil:
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t stride = strides[0]             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t extent = shape[0]
 * 
 */
  __Pyx_TraceLine(1413,1,__PYX_ERR(1, 1413, __pyx_L1_error))
  __pyx_v_stride = (__pyx_v_strides[0]);

  /* "View.MemoryView":1414
 *     cdef Py_ssize_t i
 *     cdef Py_ssize_t stride = strides[0]
 *     cdef Py_ssize_t extent = shape[0]             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 1:
 */
  __Pyx_TraceLine(1414,1,__PYX_ERR(1, 1414, __pyx_L1_error))
  __pyx_v_extent = (__pyx_v_shape[0]);

  /* "View.MemoryView":1416
 *     cdef Py_ssize_t extent = shape[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 */
  __Pyx_TraceLine(1416,1,__PYX_ERR(1, 1416, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_1) {

    /* "View.MemoryView":1417
 * 
 *     if ndim == 1:
 *         for i in range(extent):             # <<<<<<<<<<<<<<
 *             memcpy(data, item, itemsize)
 *             data += stride
 */
    __Pyx_TraceLine(1417,1,__PYX_ERR(1, 1417, __pyx_L1_error))
    __pyx_t_2 = __pyx_v_extent;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_i = __pyx_t_4;

      /* "View.MemoryView":1418
 *     if ndim == 1:
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)             # <<<<<<<<<<<<<<
 *             data += stride
 *     else:
 */
      __Pyx_TraceLine(1418,1,__PYX_ERR(1, 1418, __pyx_L1_error))
      (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize));

      /* "View.MemoryView":1419
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 *             data += stride             # <<<<<<<<<<<<<<
 *     else:
 *         for i in range(extent):
 */
      __Pyx_TraceLine(1419,1,__PYX_ERR(1, 1419, __pyx_L1_error))
      __pyx_v_data = (__pyx_v_data + __pyx_v_stride);
    }

    /* "View.MemoryView":1416
 *     cdef Py_ssize_t extent = shape[0]
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         for i in range(extent):
 *             memcpy(data, item, itemsize)
 */
    goto __pyx_L3;
  }

  /* "View.MemoryView":1421
 *             data += stride
 *     else:
 *         for i in range(extent):             # <<<<<<<<<<<<<<
 *             _slice_assign_scalar(data, shape + 1, strides + 1,
 *                                 ndim - 1, itemsize, item)
 */
  __Pyx_TraceLine(1421,1,__PYX_ERR(1, 1421, __pyx_L1_error))
  /*else*/ {
    __pyx_t_2 = __pyx_v_extent;
    __pyx_t_3 = __pyx_t_2;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_i = __pyx_t_4;

      /* "View.MemoryView":1422
 *     else:
 *         for i in range(extent):
 *             _slice_assign_scalar(data, shape + 1, strides + 1,             # <<<<<<<<<<<<<<
 *                                 ndim - 1, itemsize, item)
 *             data += stride
 */
      __Pyx_TraceLine(1422,1,__PYX_ERR(1, 1422, __pyx_L1_error))
      __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item);

      /* "View.MemoryView":1424
 *             _slice_assign_scalar(data, shape + 1, strides + 1,
 *                                 ndim - 1, itemsize, item)
 *             data += stride             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(1424,1,__PYX_ERR(1, 1424, __pyx_L1_error))
      __pyx_v_data = (__pyx_v_data + __pyx_v_stride);
    }
  }
  __pyx_L3:;

  /* "View.MemoryView":1409
 * 
 * @cname('__pyx_memoryview__slice_assign_scalar')
 * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                               Py_ssize_t *strides, int ndim,
 *                               size_t itemsize, void *item) nogil:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("View.MemoryView._slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
}

/* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,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_pyx_type)) != 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_pyx_checksum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(1, 1, __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___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

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

static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__65)
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0);
  __Pyx_TraceCall("__pyx_unpickle_Enum", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xb068931, 0x82a3537, 0x6ae9995):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 */
  __Pyx_TraceLine(4,0,__PYX_ERR(1, 4, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__66, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xb068931, 0x82a3537, 0x6ae9995):
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 */
    __Pyx_TraceLine(5,0,__PYX_ERR(1, 5, __pyx_L1_error))
    __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError);
    __pyx_t_4 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v___pyx_PickleError = __pyx_t_1;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum not in (0xb068931, 0x82a3537, 0x6ae9995):
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)             # <<<<<<<<<<<<<<
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __Pyx_TraceLine(6,0,__PYX_ERR(1, 6, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_v___pyx_PickleError);
    __pyx_t_1 = __pyx_v___pyx_PickleError; __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(1, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xb068931, 0x82a3537, 0x6ae9995):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 */
  __Pyx_TraceLine(7,0,__PYX_ERR(1, 7, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v___pyx_type);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __Pyx_TraceLine(8,0,__PYX_ERR(1, 8, __pyx_L1_error))
  __pyx_t_3 = (__pyx_v___pyx_state != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "(tree fragment)":9
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 */
    __Pyx_TraceLine(9,0,__PYX_ERR(1, 9, __pyx_L1_error))
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error)
    __pyx_t_4 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xb068931, 0x82a3537, 0x6ae9995) = (name))" % __pyx_checksum)
 *     __pyx_result = Enum.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 */
  __Pyx_TraceLine(10,0,__PYX_ERR(1, 10, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0);
  __Pyx_TraceCall("__pyx_unpickle_Enum__set_state", __pyx_f[1], 11, 0, __PYX_ERR(1, 11, __pyx_L1_error));

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  __Pyx_TraceLine(12,0,__PYX_ERR(1, 12, __pyx_L1_error))
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v___pyx_result->name);
  __Pyx_DECREF(__pyx_v___pyx_result->name);
  __pyx_v___pyx_result->name = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  __Pyx_TraceLine(13,0,__PYX_ERR(1, 13, __pyx_L1_error))
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 13, __pyx_L1_error)
  }
  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_4 = ((__pyx_t_3 > 1) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_4 != 0);
  __pyx_t_2 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "(tree fragment)":14
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])             # <<<<<<<<<<<<<<
 */
    __Pyx_TraceLine(14,0,__PYX_ERR(1, 14, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 14, __pyx_L1_error)
    }
    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_10discretize_11_extensions_8tree_ext_TreeCell __pyx_vtable_10discretize_11_extensions_8tree_ext_TreeCell;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext_TreeCell(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *)o);
  p->__pyx_vtab = __pyx_vtabptr_10discretize_11_extensions_8tree_ext_TreeCell;
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext_TreeCell(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_edges(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5edges_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_faces(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5faces_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_center(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6center_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_origin(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6origin_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_x0(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_2x0_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_h(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1h_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_dim(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3dim_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_index(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_5index_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_neighbors(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_9neighbors_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell__index_loc(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_10_index_loc_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell__level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_6_level_1__get__(o);
}

static PyMethodDef __pyx_methods_10discretize_11_extensions_8tree_ext_TreeCell[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_1__reduce_cython__, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_8TreeCell___reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_8TreeCell_3__setstate_cython__, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_8TreeCell_2__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_10discretize_11_extensions_8tree_ext_TreeCell[] = {
  {(char *)"nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_nodes, 0, (char *)"Indices for this cell's nodes within its parent tree mesh.\n\n        This property returns the indices of the nodes in the parent\n        tree mesh which correspond to this tree cell's nodes.\n\n        Returns\n        -------\n        list of int\n            Indices for this cell's nodes within its parent tree mesh\n        ", 0},
  {(char *)"edges", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_edges, 0, (char *)"Indices for this cell's edges within its parent tree mesh.\n\n        This property returns the indices of the edges in the parent\n        tree mesh which correspond to this tree cell's edges.\n\n        Returns\n        -------\n        list of int\n            Indices for this cell's edges within its parent tree mesh\n        ", 0},
  {(char *)"faces", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_faces, 0, (char *)"Indices for this cell's faces within its parent tree mesh.\n\n        This property returns the indices of the faces in the parent\n        tree mesh which correspond to this tree cell's faces.\n\n        Returns\n        -------\n        list of int\n            Indices for this cell's faces within its parent tree mesh\n        ", 0},
  {(char *)"center", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_center, 0, (char *)"Cell center location for the tree cell.\n\n        Returns\n        -------\n        (dim) numpy.ndarray\n            Cell center location for the tree cell\n        ", 0},
  {(char *)"origin", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_origin, 0, (char *)"Origin location ('anchor point') for the tree cell.\n\n        This property returns the origin location (or 'anchor point') for the\n        tree cell. The origin location is defined as the bottom-left-front\n        corner of the tree cell.\n\n        Returns\n        -------\n        (dim) numpy.ndarray\n            Origin location ('anchor point') for the tree cell\n        ", 0},
  {(char *)"x0", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_x0, 0, (char *)"Origin location ('anchor point') for the tree cell.\n\n        This property returns the origin location (or 'anchor point') for the\n        tree cell. The origin location is defined as the bottom-left-front\n        corner of the tree cell.\n\n        Returns\n        -------\n        (dim) numpy.ndarray\n            Origin location ('anchor point') for the tree cell\n        ", 0},
  {(char *)"h", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_h, 0, (char *)"Cell dimension along each axis direction.\n\n        This property returns a 1D array containing the dimensions of the\n        tree cell along the x, y (and z) directions, respectively.\n\n        Returns\n        -------\n        (dim) numpy.ndarray\n            Cell dimension along each axis direction\n        ", 0},
  {(char *)"dim", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_dim, 0, (char *)"Dimension of the tree cell; 1, 2 or 3.\n\n        Returns\n        -------\n        int\n            Dimension of the tree cell; 1, 2 or 3\n        ", 0},
  {(char *)"index", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_index, 0, (char *)"Index of the tree cell within its parent tree mesh.\n\n        Returns\n        -------\n        int\n            Index of the tree cell within its parent tree mesh\n        ", 0},
  {(char *)"neighbors", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell_neighbors, 0, (char *)"Indices for this cell's neighbors within its parent tree mesh.\n\n        Returns a list containing the indexes for the cell's neighbors.\n        The ordering of the neighboring cells (i.e. the list) is\n        [-x, +x, -y, +y, -z, +z]. For each entry in the list, there\n        are several cases:\n\n            - *ind >= 0:* the cell has a single neighbor in this direct and *ind* denotes its index\n            - *ind = -1:* the neighbour in this direction lies outside the mesh\n            - *ind = [ind_1, ind_2, ...]:* When the level changes between cells it shares a boarder with more than 1 cell in this direction (2 if `dim==2`, 4 if `dim==3`).\n\n        Returns\n        -------\n        list of int or (list of int)\n            Indices for this cell's neighbors within its parent tree mesh\n        ", 0},
  {(char *)"_index_loc", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell__index_loc, 0, (char *)0, 0},
  {(char *)"_level", __pyx_getprop_10discretize_11_extensions_8tree_ext_8TreeCell__level, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext_TreeCell = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.TreeCell", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext_TreeCell, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "A class for defining cells within instances of :class:`~discretize.TreeMesh`.\n\n    This cannot be created in python, it can only be accessed by indexing the\n    :class:`~discretize.TreeMesh` object. ``TreeCell`` is the object being passed\n    to the user defined refine function when calling the\n    :py:attr:`~discretize.TreeMesh.refine` method for a :class:`~discretize.TreeMesh`.\n\n    Examples\n    --------\n    Here, we define a basic :class:`~discretize.TreeMesh` whose refinement is defined\n    by a simple function handle. After we have finalized the mesh, we index a ``TreeCell``\n    from the mesh. Once indexed, the user may examine its properties (center location,\n    dimensions, index of its neighbors, etc...)\n\n    >>> from discretize import TreeMesh\n    >>> import numpy as np\n\n    Refine a tree mesh radially outward from the center\n\n    >>> mesh = TreeMesh([32,32])\n    >>> def func(cell):\n    ...     r = np.linalg.norm(cell.center-0.5)\n    ...     return mesh.max_level if r<0.2 else mesh.max_level-2\n    >>> mesh.refine(func)\n\n    Then we can index the mesh to get access to the cell,\n\n    >>> tree_cell = mesh[16]\n    >>> tree_cell.origin\n    array([0.375, 0.25 ])\n\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10discretize_11_extensions_8tree_ext_TreeCell, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_10discretize_11_extensions_8tree_ext_TreeCell, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext_TreeCell, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext__TreeMesh(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)o);
  p->_cell_centers = Py_None; Py_INCREF(Py_None);
  p->_nodes = Py_None; Py_INCREF(Py_None);
  p->_hanging_nodes = Py_None; Py_INCREF(Py_None);
  p->_edges_x = Py_None; Py_INCREF(Py_None);
  p->_edges_y = Py_None; Py_INCREF(Py_None);
  p->_edges_z = Py_None; Py_INCREF(Py_None);
  p->_hanging_edges_x = Py_None; Py_INCREF(Py_None);
  p->_hanging_edges_y = Py_None; Py_INCREF(Py_None);
  p->_hanging_edges_z = Py_None; Py_INCREF(Py_None);
  p->_faces_x = Py_None; Py_INCREF(Py_None);
  p->_faces_y = Py_None; Py_INCREF(Py_None);
  p->_faces_z = Py_None; Py_INCREF(Py_None);
  p->_hanging_faces_x = Py_None; Py_INCREF(Py_None);
  p->_hanging_faces_y = Py_None; Py_INCREF(Py_None);
  p->_hanging_faces_z = Py_None; Py_INCREF(Py_None);
  p->_h_gridded = Py_None; Py_INCREF(Py_None);
  p->_cell_volumes = Py_None; Py_INCREF(Py_None);
  p->_face_areas = Py_None; Py_INCREF(Py_None);
  p->_edge_lengths = Py_None; Py_INCREF(Py_None);
  p->_average_face_x_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_face_y_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_face_z_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_face_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_face_to_cell_vector = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_edge = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_edge_x = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_edge_y = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_edge_z = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_face = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_face_x = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_face_y = Py_None; Py_INCREF(Py_None);
  p->_average_node_to_face_z = Py_None; Py_INCREF(Py_None);
  p->_average_edge_x_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_edge_y_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_edge_z_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_edge_to_cell = Py_None; Py_INCREF(Py_None);
  p->_average_edge_to_cell_vector = Py_None; Py_INCREF(Py_None);
  p->_average_cell_to_face = Py_None; Py_INCREF(Py_None);
  p->_average_cell_vector_to_face = Py_None; Py_INCREF(Py_None);
  p->_average_cell_to_face_x = Py_None; Py_INCREF(Py_None);
  p->_average_cell_to_face_y = Py_None; Py_INCREF(Py_None);
  p->_average_cell_to_face_z = Py_None; Py_INCREF(Py_None);
  p->_face_divergence = Py_None; Py_INCREF(Py_None);
  p->_edge_curl = Py_None; Py_INCREF(Py_None);
  p->_nodal_gradient = Py_None; Py_INCREF(Py_None);
  p->__pyx___ubc_order = Py_None; Py_INCREF(Py_None);
  p->__pyx___ubc_indArr = Py_None; Py_INCREF(Py_None);
  p->_xs.data = NULL;
  p->_xs.memview = NULL;
  p->_ys.data = NULL;
  p->_ys.memview = NULL;
  p->_zs.data = NULL;
  p->_zs.memview = NULL;
  p->_origin.data = NULL;
  p->_origin.memview = NULL;
  if (unlikely(__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext__TreeMesh(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_95__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_cell_centers);
  Py_CLEAR(p->_nodes);
  Py_CLEAR(p->_hanging_nodes);
  Py_CLEAR(p->_edges_x);
  Py_CLEAR(p->_edges_y);
  Py_CLEAR(p->_edges_z);
  Py_CLEAR(p->_hanging_edges_x);
  Py_CLEAR(p->_hanging_edges_y);
  Py_CLEAR(p->_hanging_edges_z);
  Py_CLEAR(p->_faces_x);
  Py_CLEAR(p->_faces_y);
  Py_CLEAR(p->_faces_z);
  Py_CLEAR(p->_hanging_faces_x);
  Py_CLEAR(p->_hanging_faces_y);
  Py_CLEAR(p->_hanging_faces_z);
  Py_CLEAR(p->_h_gridded);
  Py_CLEAR(p->_cell_volumes);
  Py_CLEAR(p->_face_areas);
  Py_CLEAR(p->_edge_lengths);
  Py_CLEAR(p->_average_face_x_to_cell);
  Py_CLEAR(p->_average_face_y_to_cell);
  Py_CLEAR(p->_average_face_z_to_cell);
  Py_CLEAR(p->_average_face_to_cell);
  Py_CLEAR(p->_average_face_to_cell_vector);
  Py_CLEAR(p->_average_node_to_cell);
  Py_CLEAR(p->_average_node_to_edge);
  Py_CLEAR(p->_average_node_to_edge_x);
  Py_CLEAR(p->_average_node_to_edge_y);
  Py_CLEAR(p->_average_node_to_edge_z);
  Py_CLEAR(p->_average_node_to_face);
  Py_CLEAR(p->_average_node_to_face_x);
  Py_CLEAR(p->_average_node_to_face_y);
  Py_CLEAR(p->_average_node_to_face_z);
  Py_CLEAR(p->_average_edge_x_to_cell);
  Py_CLEAR(p->_average_edge_y_to_cell);
  Py_CLEAR(p->_average_edge_z_to_cell);
  Py_CLEAR(p->_average_edge_to_cell);
  Py_CLEAR(p->_average_edge_to_cell_vector);
  Py_CLEAR(p->_average_cell_to_face);
  Py_CLEAR(p->_average_cell_vector_to_face);
  Py_CLEAR(p->_average_cell_to_face_x);
  Py_CLEAR(p->_average_cell_to_face_y);
  Py_CLEAR(p->_average_cell_to_face_z);
  Py_CLEAR(p->_face_divergence);
  Py_CLEAR(p->_edge_curl);
  Py_CLEAR(p->_nodal_gradient);
  Py_CLEAR(p->__pyx___ubc_order);
  Py_CLEAR(p->__pyx___ubc_indArr);
  __PYX_XDEC_MEMVIEW(&p->_xs, 1);
  __PYX_XDEC_MEMVIEW(&p->_ys, 1);
  __PYX_XDEC_MEMVIEW(&p->_zs, 1);
  __PYX_XDEC_MEMVIEW(&p->_origin, 1);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext__TreeMesh(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)o;
  if (p->_cell_centers) {
    e = (*v)(p->_cell_centers, a); if (e) return e;
  }
  if (p->_nodes) {
    e = (*v)(p->_nodes, a); if (e) return e;
  }
  if (p->_hanging_nodes) {
    e = (*v)(p->_hanging_nodes, a); if (e) return e;
  }
  if (p->_edges_x) {
    e = (*v)(p->_edges_x, a); if (e) return e;
  }
  if (p->_edges_y) {
    e = (*v)(p->_edges_y, a); if (e) return e;
  }
  if (p->_edges_z) {
    e = (*v)(p->_edges_z, a); if (e) return e;
  }
  if (p->_hanging_edges_x) {
    e = (*v)(p->_hanging_edges_x, a); if (e) return e;
  }
  if (p->_hanging_edges_y) {
    e = (*v)(p->_hanging_edges_y, a); if (e) return e;
  }
  if (p->_hanging_edges_z) {
    e = (*v)(p->_hanging_edges_z, a); if (e) return e;
  }
  if (p->_faces_x) {
    e = (*v)(p->_faces_x, a); if (e) return e;
  }
  if (p->_faces_y) {
    e = (*v)(p->_faces_y, a); if (e) return e;
  }
  if (p->_faces_z) {
    e = (*v)(p->_faces_z, a); if (e) return e;
  }
  if (p->_hanging_faces_x) {
    e = (*v)(p->_hanging_faces_x, a); if (e) return e;
  }
  if (p->_hanging_faces_y) {
    e = (*v)(p->_hanging_faces_y, a); if (e) return e;
  }
  if (p->_hanging_faces_z) {
    e = (*v)(p->_hanging_faces_z, a); if (e) return e;
  }
  if (p->_h_gridded) {
    e = (*v)(p->_h_gridded, a); if (e) return e;
  }
  if (p->_cell_volumes) {
    e = (*v)(p->_cell_volumes, a); if (e) return e;
  }
  if (p->_face_areas) {
    e = (*v)(p->_face_areas, a); if (e) return e;
  }
  if (p->_edge_lengths) {
    e = (*v)(p->_edge_lengths, a); if (e) return e;
  }
  if (p->_average_face_x_to_cell) {
    e = (*v)(p->_average_face_x_to_cell, a); if (e) return e;
  }
  if (p->_average_face_y_to_cell) {
    e = (*v)(p->_average_face_y_to_cell, a); if (e) return e;
  }
  if (p->_average_face_z_to_cell) {
    e = (*v)(p->_average_face_z_to_cell, a); if (e) return e;
  }
  if (p->_average_face_to_cell) {
    e = (*v)(p->_average_face_to_cell, a); if (e) return e;
  }
  if (p->_average_face_to_cell_vector) {
    e = (*v)(p->_average_face_to_cell_vector, a); if (e) return e;
  }
  if (p->_average_node_to_cell) {
    e = (*v)(p->_average_node_to_cell, a); if (e) return e;
  }
  if (p->_average_node_to_edge) {
    e = (*v)(p->_average_node_to_edge, a); if (e) return e;
  }
  if (p->_average_node_to_edge_x) {
    e = (*v)(p->_average_node_to_edge_x, a); if (e) return e;
  }
  if (p->_average_node_to_edge_y) {
    e = (*v)(p->_average_node_to_edge_y, a); if (e) return e;
  }
  if (p->_average_node_to_edge_z) {
    e = (*v)(p->_average_node_to_edge_z, a); if (e) return e;
  }
  if (p->_average_node_to_face) {
    e = (*v)(p->_average_node_to_face, a); if (e) return e;
  }
  if (p->_average_node_to_face_x) {
    e = (*v)(p->_average_node_to_face_x, a); if (e) return e;
  }
  if (p->_average_node_to_face_y) {
    e = (*v)(p->_average_node_to_face_y, a); if (e) return e;
  }
  if (p->_average_node_to_face_z) {
    e = (*v)(p->_average_node_to_face_z, a); if (e) return e;
  }
  if (p->_average_edge_x_to_cell) {
    e = (*v)(p->_average_edge_x_to_cell, a); if (e) return e;
  }
  if (p->_average_edge_y_to_cell) {
    e = (*v)(p->_average_edge_y_to_cell, a); if (e) return e;
  }
  if (p->_average_edge_z_to_cell) {
    e = (*v)(p->_average_edge_z_to_cell, a); if (e) return e;
  }
  if (p->_average_edge_to_cell) {
    e = (*v)(p->_average_edge_to_cell, a); if (e) return e;
  }
  if (p->_average_edge_to_cell_vector) {
    e = (*v)(p->_average_edge_to_cell_vector, a); if (e) return e;
  }
  if (p->_average_cell_to_face) {
    e = (*v)(p->_average_cell_to_face, a); if (e) return e;
  }
  if (p->_average_cell_vector_to_face) {
    e = (*v)(p->_average_cell_vector_to_face, a); if (e) return e;
  }
  if (p->_average_cell_to_face_x) {
    e = (*v)(p->_average_cell_to_face_x, a); if (e) return e;
  }
  if (p->_average_cell_to_face_y) {
    e = (*v)(p->_average_cell_to_face_y, a); if (e) return e;
  }
  if (p->_average_cell_to_face_z) {
    e = (*v)(p->_average_cell_to_face_z, a); if (e) return e;
  }
  if (p->_face_divergence) {
    e = (*v)(p->_face_divergence, a); if (e) return e;
  }
  if (p->_edge_curl) {
    e = (*v)(p->_edge_curl, a); if (e) return e;
  }
  if (p->_nodal_gradient) {
    e = (*v)(p->_nodal_gradient, a); if (e) return e;
  }
  if (p->__pyx___ubc_order) {
    e = (*v)(p->__pyx___ubc_order, a); if (e) return e;
  }
  if (p->__pyx___ubc_indArr) {
    e = (*v)(p->__pyx___ubc_indArr, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext__TreeMesh(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)o;
  tmp = ((PyObject*)p->_cell_centers);
  p->_cell_centers = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_nodes);
  p->_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_nodes);
  p->_hanging_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_edges_x);
  p->_edges_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_edges_y);
  p->_edges_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_edges_z);
  p->_edges_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_edges_x);
  p->_hanging_edges_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_edges_y);
  p->_hanging_edges_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_edges_z);
  p->_hanging_edges_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_faces_x);
  p->_faces_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_faces_y);
  p->_faces_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_faces_z);
  p->_faces_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_faces_x);
  p->_hanging_faces_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_faces_y);
  p->_hanging_faces_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_hanging_faces_z);
  p->_hanging_faces_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_h_gridded);
  p->_h_gridded = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_cell_volumes);
  p->_cell_volumes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_face_areas);
  p->_face_areas = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_edge_lengths);
  p->_edge_lengths = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_face_x_to_cell);
  p->_average_face_x_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_face_y_to_cell);
  p->_average_face_y_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_face_z_to_cell);
  p->_average_face_z_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_face_to_cell);
  p->_average_face_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_face_to_cell_vector);
  p->_average_face_to_cell_vector = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_cell);
  p->_average_node_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_edge);
  p->_average_node_to_edge = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_edge_x);
  p->_average_node_to_edge_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_edge_y);
  p->_average_node_to_edge_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_edge_z);
  p->_average_node_to_edge_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_face);
  p->_average_node_to_face = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_face_x);
  p->_average_node_to_face_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_face_y);
  p->_average_node_to_face_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_node_to_face_z);
  p->_average_node_to_face_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_edge_x_to_cell);
  p->_average_edge_x_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_edge_y_to_cell);
  p->_average_edge_y_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_edge_z_to_cell);
  p->_average_edge_z_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_edge_to_cell);
  p->_average_edge_to_cell = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_edge_to_cell_vector);
  p->_average_edge_to_cell_vector = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_cell_to_face);
  p->_average_cell_to_face = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_cell_vector_to_face);
  p->_average_cell_vector_to_face = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_cell_to_face_x);
  p->_average_cell_to_face_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_cell_to_face_y);
  p->_average_cell_to_face_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_average_cell_to_face_z);
  p->_average_cell_to_face_z = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_face_divergence);
  p->_face_divergence = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_edge_curl);
  p->_edge_curl = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_nodal_gradient);
  p->_nodal_gradient = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx___ubc_order);
  p->__pyx___ubc_order = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx___ubc_indArr);
  p->__pyx___ubc_indArr = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}
static PyObject *__pyx_sq_item_10discretize_11_extensions_8tree_ext__TreeMesh(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_finalized(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9finalized_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_fill(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_4fill_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_max_used_level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14max_used_level_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_max_level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9max_level_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_cells(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_cells_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_edges_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_edges_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_edges_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_edges_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_edges_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_edges_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7n_faces_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_hanging_faces_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13n_total_faces_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9n_faces_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15n_total_faces_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17n_hanging_faces_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_centers(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_centers_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13hanging_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_h_gridded(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9h_gridded_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7edges_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_edges_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_edges(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_edges_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7faces_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15hanging_faces_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_faces(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14boundary_faces_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_face_outward_normals(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29boundary_face_outward_normals_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_volumes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12cell_volumes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_areas(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10face_areas_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_12edge_lengths_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_boundary_indices(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21cell_boundary_indices_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_boundary_indices(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21face_boundary_indices_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_divergence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15face_divergence_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_curl(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9edge_curl_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodal_gradient(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_14nodal_gradient_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodal_laplacian(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15nodal_laplacian_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23stencil_cell_gradient_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_x_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_x_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_y_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_y_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_z_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_edge_z_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_cell_vector(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_edge_to_cell_vector_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_face(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_edge_to_face_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_x_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_x_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_y_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_y_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_z_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_face_z_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_face_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_to_cell_vector(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_face_to_cell_vector_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_cell(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_cell_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_edge_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_edge_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_node_to_face_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_node_to_face_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_20average_cell_to_face_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_vector_to_face(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27average_cell_vector_to_face_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_x(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_x_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_y(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_y_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_z(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_22average_cell_to_face_z_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_face_to_boundary_face(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_face_to_boundary_face_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_edge_to_boundary_edge(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_edge_to_boundary_edge_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_node_to_boundary_node(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29project_node_to_boundary_node_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10cell_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10edge_nodes_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh__ubc_indArr(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11_ubc_indArr_1__get__(o);
}

static PyObject *__pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh__ubc_order(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_10_ubc_order_1__get__(o);
}

static PyMethodDef __pyx_methods_10discretize_11_extensions_8tree_ext__TreeMesh[] = {
  {"_clear_cache", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_5_clear_cache, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_4_clear_cache},
  {"refine", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_7refine, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_6refine},
  {"refine_ball", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_9refine_ball, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_8refine_ball},
  {"refine_box", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_11refine_box, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_10refine_box},
  {"refine_line", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_13refine_line, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_12refine_line},
  {"refine_triangle", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_15refine_triangle, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_14refine_triangle},
  {"refine_vertical_trianglular_prism", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_17refine_vertical_trianglular_prism, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_16refine_vertical_trianglular_prism},
  {"refine_tetrahedron", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_19refine_tetrahedron, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_18refine_tetrahedron},
  {"insert_cells", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_21insert_cells, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_20insert_cells},
  {"finalize", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_23finalize, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_22finalize},
  {"number", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_25number, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_24number},
  {"_set_origin", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_27_set_origin, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_26_set_origin},
  {"get_boundary_cells", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_29get_boundary_cells, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_28get_boundary_cells},
  {"get_cells_along_line", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_31get_cells_along_line, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_30get_cells_along_line},
  {"_face_divergence_2D", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_33_face_divergence_2D, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_32_face_divergence_2D},
  {"_face_divergence_3D", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_35_face_divergence_3D, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_34_face_divergence_3D},
  {"average_cell_to_total_face_x", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_37average_cell_to_total_face_x, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_36average_cell_to_total_face_x},
  {"average_cell_to_total_face_y", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_39average_cell_to_total_face_y, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_38average_cell_to_total_face_y},
  {"average_cell_to_total_face_z", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_41average_cell_to_total_face_z, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_40average_cell_to_total_face_z},
  {"_deflate_edges_x", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_43_deflate_edges_x, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_42_deflate_edges_x},
  {"_deflate_edges_y", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_45_deflate_edges_y, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_44_deflate_edges_y},
  {"_deflate_edges_z", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_47_deflate_edges_z, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_46_deflate_edges_z},
  {"_deflate_edges", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_49_deflate_edges, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_48_deflate_edges},
  {"_deflate_faces", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_51_deflate_faces, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_50_deflate_faces},
  {"_deflate_faces_x", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_53_deflate_faces_x, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_52_deflate_faces_x},
  {"_deflate_faces_y", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_55_deflate_faces_y, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_54_deflate_faces_y},
  {"_deflate_faces_z", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_57_deflate_faces_z, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_56_deflate_faces_z},
  {"_deflate_nodes", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_59_deflate_nodes, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_58_deflate_nodes},
  {"_get_containing_cell_index", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_61_get_containing_cell_index, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_60_get_containing_cell_index},
  {"_get_containing_cell_indexes", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_63_get_containing_cell_indexes, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_62_get_containing_cell_indexes},
  {"_count_cells_per_index", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_65_count_cells_per_index, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_64_count_cells_per_index},
  {"_cell_levels_by_indexes", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_67_cell_levels_by_indexes, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_66_cell_levels_by_indexes},
  {"_getFaceP", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_69_getFaceP, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_68_getFaceP},
  {"_getFacePxx", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_71_getFacePxx, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_70_getFacePxx},
  {"_getFacePxxx", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_73_getFacePxxx, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_72_getFacePxxx},
  {"_getEdgeP", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_75_getEdgeP, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_74_getEdgeP},
  {"_getEdgePxx", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_77_getEdgePxx, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_76_getEdgePxx},
  {"_getEdgePxxx", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_79_getEdgePxxx, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_78_getEdgePxxx},
  {"_getEdgeIntMat", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_81_getEdgeIntMat, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_80_getEdgeIntMat},
  {"_getFaceIntMat", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_83_getFaceIntMat, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_82_getFaceIntMat},
  {"_getNodeIntMat", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_85_getNodeIntMat, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_84_getNodeIntMat},
  {"_getCellIntMat", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_87_getCellIntMat, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_86_getCellIntMat},
  {"__getstate__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_89__getstate__, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_88__getstate__},
  {"__setstate__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_91__setstate__, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_90__setstate__},
  {"_vol_avg_from_tree", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_97_vol_avg_from_tree, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_96_vol_avg_from_tree},
  {"_vol_avg_to_tens", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_99_vol_avg_to_tens, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_98_vol_avg_to_tens},
  {"_vol_avg_from_tens", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_101_vol_avg_from_tens, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_100_vol_avg_from_tens},
  {"get_overlapping_cells", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_103get_overlapping_cells, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_102get_overlapping_cells},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_105__reduce_cython__, METH_NOARGS, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_104__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_107__setstate_cython__, METH_O, __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_106__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_10discretize_11_extensions_8tree_ext__TreeMesh[] = {
  {(char *)"finalized", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_finalized, 0, (char *)"Whether tree mesh is finalized.\n\n        This property returns a boolean stating whether the tree mesh has\n        been finalized; i.e. no further mesh refinement will be carried out.\n        A tree mesh must be finalized before it can be used to call most\n        of its properties or construct operators.\n        When finalized, mesh refinement is no longer enabled.\n\n        Returns\n        -------\n        bool\n            Returns *True* if finalized, *False* otherwise\n        ", 0},
  {(char *)"fill", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_fill, 0, (char *)"How 'filled' the tree mesh is compared to the underlying tensor mesh.\n\n        This property outputs the ratio between the number of cells in the\n        tree mesh and the number of cells in the underlying tensor mesh;\n        where the underlying tensor mesh is equivalent to the uniform tensor\n        mesh that uses the smallest cell size. Thus the output is a number between 0 and 1.\n\n        Returns\n        -------\n        float\n            A fractional percent denoting how 'filled' the tree mesh is\n        ", 0},
  {(char *)"max_used_level", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_max_used_level, 0, (char *)"Maximum refinement level used.\n\n        Returns the maximum refinement level used to construct the\n        tree mesh. The maximum used level is equal or less than the\n        maximum allowable level; see :py:attr:`.~TreeMesh.max_level`.\n\n        Returns\n        -------\n        int\n            Maximum level used when refining the mesh\n        ", 0},
  {(char *)"max_level", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_max_level, 0, (char *)"Maximum allowable refinement level for the mesh.\n\n        The maximum refinement level for a tree mesh depends on\n        the number of underlying tensor mesh cells along each axis\n        direction; which are always powers of 2. Where *N* is the\n        number of underlying tensor mesh cells along a given axis, then the\n        maximum allowable level of refinement :math:`k_{max}` is given by:\n\n        .. math::\n            k_{max} = \\log_2(N)\n\n        Returns\n        -------\n        int\n            Maximum allowable refinement level for the mesh\n\n        ", 0},
  {(char *)"n_cells", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_cells, 0, (char *)"Total number of cells in the mesh.\n\n        Returns\n        -------\n        int\n            Number of cells in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nC**\n        ", 0},
  {(char *)"n_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_nodes, 0, (char *)"Total number of nodes in the mesh.\n\n        Returns\n        -------\n        int\n            Number of nodes in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nN**\n        ", 0},
  {(char *)"n_total_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_nodes, 0, (char *)"Number of hanging and non-hanging nodes.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging nodes\n        ", 0},
  {(char *)"n_hanging_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_nodes, 0, (char *)"Number of hanging nodes.\n\n        Returns\n        -------\n        int\n            Number of hanging nodes\n        ", 0},
  {(char *)"n_edges", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges, 0, (char *)"Total number of edges in the mesh.\n\n        Returns\n        -------\n        int\n            Total number of edges in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nE**\n        ", 0},
  {(char *)"n_hanging_edges", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges, 0, (char *)"Total number of hanging edges in all dimensions.\n\n        Returns\n        -------\n        int\n            Number of hanging edges in all dimensions\n        ", 0},
  {(char *)"n_total_edges", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges, 0, (char *)"Total number of hanging and non-hanging edges in all dimensions.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging edges in all dimensions\n        ", 0},
  {(char *)"n_edges_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_x, 0, (char *)"Number of x-edges in the mesh.\n\n        This property returns the number of edges that\n        are parallel to the x-axis; i.e. x-edges.\n\n        Returns\n        -------\n        int\n            Number of x-edges in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nEx**\n        ", 0},
  {(char *)"n_edges_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_y, 0, (char *)"Number of y-edges in the mesh.\n\n        This property returns the number of edges that\n        are parallel to the y-axis; i.e. y-edges.\n\n        Returns\n        -------\n        int\n            Number of y-edges in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nEy**\n        ", 0},
  {(char *)"n_edges_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_edges_z, 0, (char *)"Number of z-edges in the mesh.\n\n        This property returns the number of edges that\n        are parallel to the z-axis; i.e. z-edges.\n\n        Returns\n        -------\n        int\n            Number of z-edges in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nEz**\n        ", 0},
  {(char *)"n_total_edges_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_x, 0, (char *)"Number of hanging and non-hanging x-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging x-edges in the mesh\n        ", 0},
  {(char *)"n_total_edges_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_y, 0, (char *)"Number of hanging and non-hanging y-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging y-edges in the mesh\n        ", 0},
  {(char *)"n_total_edges_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_edges_z, 0, (char *)"Number of hanging and non-hanging z-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging z-edges in the mesh\n        ", 0},
  {(char *)"n_hanging_edges_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_x, 0, (char *)"Number of hanging x-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging x-edges in the mesh\n        ", 0},
  {(char *)"n_hanging_edges_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_y, 0, (char *)"Number of hanging y-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging y-edges in the mesh\n        ", 0},
  {(char *)"n_hanging_edges_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_edges_z, 0, (char *)"Number of hanging z-edges in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging z-edges in the mesh\n        ", 0},
  {(char *)"n_faces", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces, 0, (char *)"Total number of faces in the mesh.\n\n        Returns\n        -------\n        int\n            Total number of faces in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nF**\n        ", 0},
  {(char *)"n_hanging_faces", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces, 0, (char *)"Total number of hanging faces in the mesh.\n\n        Returns\n        -------\n        int\n            Total number of non-hanging faces in the mesh\n        ", 0},
  {(char *)"n_total_faces", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces, 0, (char *)"Total number of hanging and non-hanging faces in the mesh.\n\n        Returns\n        -------\n        int\n            Total number of non-hanging faces in the mesh\n        ", 0},
  {(char *)"n_faces_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_x, 0, (char *)"Number of x-faces in the mesh.\n\n        This property returns the number of faces whose normal\n        vector is parallel to the x-axis; i.e. x-faces.\n\n        Returns\n        -------\n        int\n            Number of x-faces in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nFx**\n        ", 0},
  {(char *)"n_faces_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_y, 0, (char *)"Number of y-faces in the mesh.\n\n        This property returns the number of faces whose normal\n        vector is parallel to the y-axis; i.e. y-faces.\n\n        Returns\n        -------\n        int\n            Number of y-faces in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nFy**\n        ", 0},
  {(char *)"n_faces_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_faces_z, 0, (char *)"Number of z-faces in the mesh.\n\n        This property returns the number of faces whose normal\n        vector is parallel to the z-axis; i.e. z-faces.\n\n        Returns\n        -------\n        int\n            Number of z-faces in the mesh\n\n        Notes\n        -----\n        Property also accessible as using the shorthand **nFz**\n        ", 0},
  {(char *)"n_total_faces_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_x, 0, (char *)"Number of hanging and non-hanging x-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging x-faces in the mesh\n        ", 0},
  {(char *)"n_total_faces_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_y, 0, (char *)"Number of hanging and non-hanging y-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging y-faces in the mesh\n        ", 0},
  {(char *)"n_total_faces_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_total_faces_z, 0, (char *)"Number of hanging and non-hanging z-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging and non-hanging z-faces in the mesh\n        ", 0},
  {(char *)"n_hanging_faces_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_x, 0, (char *)"Number of hanging x-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging x-faces in the mesh\n        ", 0},
  {(char *)"n_hanging_faces_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_y, 0, (char *)"Number of hanging y-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging y-faces in the mesh\n        ", 0},
  {(char *)"n_hanging_faces_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_n_hanging_faces_z, 0, (char *)"Number of hanging z-faces in the mesh.\n\n        Returns\n        -------\n        int\n            Number of hanging z-faces in the mesh\n        ", 0},
  {(char *)"cell_centers", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_centers, 0, (char *)"Gridded cell center locations.\n\n        This property returns a numpy array of shape (n_cells, dim)\n        containing gridded cell center locations for all cells in the\n        mesh.\n\n        Returns\n        -------\n        (n_cells, dim) numpy.ndarray of float\n            Gridded cell center locations\n        ", 0},
  {(char *)"nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodes, 0, (char *)"Gridded non-hanging nodes locations.\n\n        This property returns a numpy array of shape (n_nodes, dim)\n        containing gridded locations for all non-hanging nodes in the\n        mesh.\n\n        Returns\n        -------\n        (n_nodes, dim) numpy.ndarray of float\n            Gridded non-hanging node locations\n        ", 0},
  {(char *)"hanging_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_nodes, 0, (char *)"Gridded hanging node locations.\n\n        This property returns a numpy array of shape (n_hanging_nodes, dim)\n        containing gridded locations for all hanging nodes in the\n        mesh.\n\n        Returns\n        -------\n        (n_hanging_nodes, dim) numpy.ndarray of float\n            Gridded hanging node locations\n        ", 0},
  {(char *)"boundary_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_nodes, 0, (char *)"Gridded boundary node locations.\n\n        This property returns a numpy array of shape\n        (n_boundary_nodes, dim) containing the gridded locations\n        of the nodes on the boundary of the mesh.\n\n        Returns\n        -------\n        (n_boundary_nodes, dim) numpy.ndarray of float\n            Gridded boundary node locations\n        ", 0},
  {(char *)"h_gridded", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_h_gridded, 0, (char *)"Gridded cell dimensions.\n\n        This property returns a numpy array of shape (n_cells, dim)\n        containing the dimensions of the cells along each axis\n        direction in order. E.g. the columns of *h_gridded* for a\n        3D tree mesh would be ordered [hx,hy,hz].\n\n        Returns\n        -------\n        (n_cells, dim) numpy.ndarray of float\n            Gridded cell dimensions\n        ", 0},
  {(char *)"edges_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_x, 0, (char *)"Gridded locations of non-hanging x-edges.\n\n        This property returns a numpy array of shape (n_edges_x, dim)\n        containing gridded locations for all non-hanging x-edges.\n\n        Returns\n        -------\n        (n_edges_x, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging x-edges\n        ", 0},
  {(char *)"hanging_edges_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_x, 0, (char *)"Gridded locations of hanging x-edges.\n\n        This property returns a numpy array of shape (n_hanging_edges_x, dim)\n        containing gridded locations for all hanging x-edges.\n\n        Returns\n        -------\n        (n_hanging_edges_x, dim) numpy.ndarray of float\n            Gridded locations of all hanging x-edges\n        ", 0},
  {(char *)"edges_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_y, 0, (char *)"Gridded locations of non-hanging y-edges.\n\n        This property returns a numpy array of shape (n_edges_y, dim)\n        containing gridded locations for all non-hanging y-edges.\n\n        Returns\n        -------\n        (n_edges_y, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging y-edges\n        ", 0},
  {(char *)"hanging_edges_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_y, 0, (char *)"Gridded locations of hanging y-edges.\n\n        This property returns a numpy array of shape (n_haning_edges_y, dim)\n        containing gridded locations for all hanging y-edges.\n\n        Returns\n        -------\n        (n_haning_edges_y, dim) numpy.ndarray of float\n            Gridded locations of all hanging y-edges\n        ", 0},
  {(char *)"edges_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edges_z, 0, (char *)"Gridded locations of non-hanging z-edges.\n\n        This property returns a numpy array of shape (n_edges_z, dim)\n        containing gridded locations for all non-hanging z-edges.\n\n        Returns\n        -------\n        (n_edges_z, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging z-edges\n        ", 0},
  {(char *)"hanging_edges_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_edges_z, 0, (char *)"Gridded locations of hanging z-edges.\n\n        This property returns a numpy array of shape (n_hanging_edges_z, dim)\n        containing gridded locations for all hanging z-edges.\n\n        Returns\n        -------\n        (n_hanging_edges_z, dim) numpy.ndarray of float\n            Gridded locations of all hanging z-edges\n        ", 0},
  {(char *)"boundary_edges", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_edges, 0, (char *)"Gridded boundary edge locations.\n\n        This property returns a numpy array of shape\n        (n_boundary_edges, dim) containing the gridded locations\n        of the edges on the boundary of the mesh. The returned\n        quantity is organized *np.r_[edges_x, edges_y, edges_z]* .\n\n        Returns\n        -------\n        (n_boundary_edges, dim) numpy.ndarray of float\n            Gridded boundary edge locations\n        ", 0},
  {(char *)"faces_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_x, 0, (char *)"Gridded locations of non-hanging x-faces.\n\n        This property returns a numpy array of shape (n_faces_x, dim)\n        containing gridded locations for all non-hanging x-faces.\n\n        Returns\n        -------\n        (n_faces_x, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging x-faces\n        ", 0},
  {(char *)"faces_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_y, 0, (char *)"Gridded locations of non-hanging y-faces.\n\n        This property returns a numpy array of shape (n_faces_y, dim)\n        containing gridded locations for all non-hanging y-faces.\n\n        Returns\n        -------\n        (n_faces_y, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging y-faces\n        ", 0},
  {(char *)"faces_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_faces_z, 0, (char *)"Gridded locations of non-hanging z-faces.\n\n        This property returns a numpy array of shape (n_faces_z, dim)\n        containing gridded locations for all non-hanging z-faces.\n\n        Returns\n        -------\n        (n_faces_z, dim) numpy.ndarray of float\n            Gridded locations of all non-hanging z-faces\n        ", 0},
  {(char *)"hanging_faces_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_x, 0, (char *)"Gridded locations of hanging x-faces.\n\n        This property returns a numpy array of shape (n_hanging_faces_x, dim)\n        containing gridded locations for all hanging x-faces.\n\n        Returns\n        -------\n        (n_hanging_faces_x, dim) numpy.ndarray of float\n            Gridded locations of all hanging x-faces\n        ", 0},
  {(char *)"hanging_faces_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_y, 0, (char *)"Gridded locations of hanging y-faces.\n\n        This property returns a numpy array of shape (n_hanging_faces_y, dim)\n        containing gridded locations for all hanging y-faces.\n\n        Returns\n        -------\n        (n_hanging_faces_y, dim) numpy.ndarray of float\n            Gridded locations of all hanging y-faces\n        ", 0},
  {(char *)"hanging_faces_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_hanging_faces_z, 0, (char *)"Gridded locations of hanging z-faces.\n\n        This property returns a numpy array of shape (n_hanging_faces_z, dim)\n        containing gridded locations for all hanging z-faces.\n\n        Returns\n        -------\n        (n_hanging_faces_z, dim) numpy.ndarray of float\n            Gridded locations of all hanging z-faces\n        ", 0},
  {(char *)"boundary_faces", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_faces, 0, (char *)"Gridded boundary face locations.\n\n        This property returns a numpy array of shape\n        (n_boundary_faces, dim) containing the gridded locations\n        of the faces on the boundary of the mesh. The returned\n        quantity is organized *np.r_[faces_x, faces_y, faces_z]* .\n\n        Returns\n        -------\n        (n_boundary_faces, dim) numpy.ndarray of float\n            Gridded boundary face locations\n        ", 0},
  {(char *)"boundary_face_outward_normals", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_boundary_face_outward_normals, 0, (char *)"Outward normals of boundary faces.\n\n        For all boundary faces in the mesh, this property returns\n        the unit vectors denoting the outward normals to the boundary.\n\n        Returns\n        -------\n        (n_boundary_faces, dim) numpy.ndarray of float\n            Outward normals of boundary faces\n        ", 0},
  {(char *)"cell_volumes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_volumes, 0, (char *)"Return cell volumes.\n\n        Calling this property will compute and return a 1D array\n        containing the volumes of mesh cells.\n\n        Returns\n        -------\n        (n_cells) numpy.ndarray\n            The quantity returned depends on the dimensions of the mesh:\n\n              - *2D:* Returns the cell areas\n              - *3D:* Returns the cell volumes\n\n        ", 0},
  {(char *)"face_areas", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_areas, 0, (char *)"Returns the areas of all cell faces.\n\n        Calling this property will compute and return the areas of all\n        mesh faces as a 1D numpy array.\n\n        Returns\n        -------\n        (n_faces) numpy.ndarray\n            The length of the quantity returned depends on the dimensions of the mesh:\n\n            - *2D:* returns the x-face and y-face areas; i.e. y-edge and x-edge lengths,\n              respectively\n            - *3D:* returns the x, y and z-face areas in order\n        ", 0},
  {(char *)"edge_lengths", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_lengths, 0, (char *)"Returns the lengths of all edges in the mesh.\n\n        Calling this property will compute and return the lengths of all\n        edges in the mesh.\n\n        Returns\n        -------\n        (n_edges) numpy.ndarray\n            The length of the quantity returned depends on the dimensions of the mesh:\n\n            - *2D:* returns the x-edge and y-edge lengths in order\n            - *3D:* returns the x, y and z-edge lengths in order\n        ", 0},
  {(char *)"cell_boundary_indices", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_boundary_indices, 0, (char *)"Returns the indices of the x, y (and z) boundary cells.\n\n        This property returns the indices of the cells on the x, y (and z)\n        boundaries, respectively. Note that each axis direction will\n        have both a lower and upper boundary. The property will\n        return the indices corresponding to the lower and upper\n        boundaries separately.\n\n        E.g. for a 2D domain, there are 2 x-boundaries and 2 y-boundaries (4 in total).\n        In this case, the return is a list of length 4 organized\n        [ind_Bx1, ind_Bx2, ind_By1, ind_By2]::\n\n                       By2\n                + ------------- +\n                |               |\n                |               |\n            Bx1 |               | Bx2\n                |               |\n                |               |\n                + ------------- +\n                       By1\n\n\n        Returns\n        -------\n        ind_bx1 ind_bx2, ind_by1, ind_by2 : numpy.ndarray of int\n            The length of each array in the list is equal to the number of faces\n            on that particular boundary.\n        ind_bz1, ind_bz2 : numpy.ndarray of int, optional\n            Returned if `dim` is 3.\n\n        Examples\n        --------\n        Here, we construct a small 2D tree mesh and return the indices\n        of the x and y-boundary cells.\n\n        >>> from discretize import TreeMesh\n        >>> import numpy as np\n        >>> import matplotlib.pyplot as plt\n\n        >>> hx = np.ones(16)\n        >>> hy = np.ones(16)\n        >>> mesh = TreeMesh([hx, hy])\n        >>> mesh.refine_ball([4.0,4.0], [4.0], [4])\n        >>> ind_Bx1, ind_Bx2, ind_By1, ind_By2 = mesh.cell_boundary_indices\n\n        >>> ax = plt.subplot(111)\n        >>> mesh.plot_grid(ax=ax)\n        >>> ax.scatter(*mesh.cell_centers[ind_Bx1].T)\n        >>> plt.show()\n        ", 0},
  {(char *)"face_boundary_indices", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_boundary_indices, 0, (char *)"Returns the indices of the x, y (and z) boundary faces.\n\n        This property returns the indices of the faces on the x, y (and z)\n        boundaries, respectively. Note that each axis direction will\n        have both a lower and upper boundary. The property will\n        return the indices corresponding to the lower and upper\n        boundaries separately.\n\n        E.g. for a 2D domain, there are 2 x-boundaries and 2 y-boundaries (4 in total).\n        In this case, the return is a list of length 4 organized\n        [ind_Bx1, ind_Bx2, ind_By1, ind_By2]::\n\n                       By2\n                + ------------- +\n                |               |\n                |               |\n            Bx1 |               | Bx2\n                |               |\n                |               |\n                + ------------- +\n                       By1\n\n\n        Returns\n        -------\n        ind_bx1 ind_bx2, ind_by1, ind_by2 : numpy.ndarray of int\n            The length of each array in the list is equal to the number of faces\n            on that particular boundary.\n        ind_bz1, ind_bz2 : numpy.ndarray of int, optional\n\n        Examples\n        --------\n        Here, we construct a small 2D tree mesh and return the indices\n        of the x and y-boundary faces.\n\n        >>> from discretize import TreeMesh\n        >>> import numpy as np\n        >>> import matplotlib.pyplot as plt\n\n        >>> hx = np.ones(16)\n        >>> hy = np.ones(16)\n        >>> mesh = TreeMesh([hx, hy])\n        >>> mesh.refine_ball([4.0,4.0], [4.0], [4])\n        >>> ind_Bx1, ind_Bx2, ind_By1, ind_By2 = mesh.face_boundary_indices\n\n        >>> ax = plt.subplot(111)\n        >>> mesh.plot_grid(ax=ax)\n        >>> ax.scatter(*mesh.faces_x[ind_Bx1].T)\n        >>> plt.show()\n        ", 0},
  {(char *)"face_divergence", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_face_divergence, 0, (char *)"Face divergence operator (faces to cell-centres).\n\n        This property constructs the 2nd order numerical divergence operator\n        that maps from faces to cell centers. The operator is a sparse matrix\n        :math:`\\mathbf{D_f}` that can be applied as a matrix-vector product to\n        a discrete vector :math:`\\mathbf{u}` that lives on mesh faces; i.e.::\n\n            div_u = Df @ u\n\n        Once constructed, the operator is stored permanently as a property of the mesh.\n        *See notes for additional details.*\n\n        Returns\n        -------\n        (n_cells, n_faces) scipy.sparse.csr_matrix\n            The numerical divergence operator from faces to cell centers\n\n        Notes\n        -----\n        In continuous space, the divergence operator is defined as:\n\n        .. math::\n            \\phi = \\nabla \\cdot \\vec{u} = \\frac{\\partial u_x}{\\partial x}\n            + \\frac{\\partial u_y}{\\partial y} + \\frac{\\partial u_z}{\\partial z}\n\n        Where :math:`\\mathbf{u}` is the discrete representation of the continuous variable\n        :math:`\\vec{u}` on cell faces and :math:`\\boldsymbol{\\phi}` is the discrete\n        representation of :math:`\\phi` at cell centers, **face_divergence** constructs a\n        discrete linear operator :math:`\\mathbf{D_f}` such that:\n\n        .. math::\n            \\boldsymbol{\\phi} = \\mathbf{D_f \\, u}\n\n        For each cell, the computation of the face divergence can be expressed\n        according to the integral form below. For cell :math:`i` whose corresponding\n        faces are indexed as a subset :math:`K` from the set of all mesh faces:\n\n        .. math::\n            \\phi_i = \\frac{1}{V_i} \\sum_{k \\in K} A_k \\, \\vec{u}_k \\cdot \\hat{n}_k\n\n        where :math:`V_i` is the volume of cell :math:`i`, :math:`A_k` is\n        the surface area of face *k*, :math:`\\vec{u}_k` is the value of\n        :math:`\\vec{u}` on face *k*, and :math:`\\hat{n}_k`\n        represents"" the outward normal vector of face *k* for cell *i*.\n        ", 0},
  {(char *)"edge_curl", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_curl, 0, (char *)"Edge curl operator (edges to faces)\n\n        This property constructs the 2nd order numerical curl operator\n        that maps from edges to faces. The operator is a sparse matrix\n        :math:`\\mathbf{C_e}` that can be applied as a matrix-vector product\n        to a discrete vector quantity **u** that lives\n        on the edges; i.e.::\n\n            curl_u = Ce @ u\n\n        Once constructed, the operator is stored permanently as a property of the mesh.\n\n        Returns\n        -------\n        (n_faces, n_edges) scipy.sparse.csr_matrix\n            The numerical curl operator from edges to faces\n\n        Notes\n        -----\n        In continuous space, the curl operator is defined as:\n\n        .. math::\n            \\vec{w} = \\nabla \\times \\vec{u} =\n            \\begin{vmatrix}\n            \\hat{x} & \\hat{y} & \\hat{z} \\\\\n            \\partial_x & \\partial_y & \\partial_z \\\\\n            u_x & u_y & u_z\n            \\end{vmatrix}\n\n        Where :math:`\\mathbf{u}` is the discrete representation of the continuous variable\n        :math:`\\vec{u}` on cell edges and :math:`\\mathbf{w}` is the discrete\n        representation of the curl on the faces, **edge_curl** constructs a\n        discrete linear operator :math:`\\mathbf{C_e}` such that:\n\n        .. math::\n            \\mathbf{w} = \\mathbf{C_e \\, u}\n\n        The computation of the curl on mesh faces can be expressed\n        according to the integral form below. For face :math:`i` bordered by\n        a set of edges indexed by subset :math:`K`:\n\n        .. math::\n            w_i = \\frac{1}{A_i} \\sum_{k \\in K} \\vec{u}_k \\cdot \\vec{\\ell}_k\n\n        where :math:`A_i` is the surface area of face *i*,\n        :math:`u_k` is the value of :math:`\\vec{u}` on face *k*,\n        and \\vec{\\ell}_k is the path along edge *k*.\n        ", 0},
  {(char *)"nodal_gradient", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodal_gradient, 0, (char *)"Nodal gradient operator (nodes to edges)\n\n        This property constructs the 2nd order numerical gradient operator\n        that maps from nodes to edges. The operator is a sparse matrix\n        :math:`\\mathbf{G_n}` that can be applied as a matrix-vector product\n        to a discrete scalar quantity :math:`\\boldsymbol{\\phi}` that\n        lives on the nodes, i.e.::\n\n            grad_phi = Gn @ phi\n\n        Once constructed, the operator is stored permanently as a property of the mesh.\n\n        Returns\n        -------\n        (n_edges, n_nodes) scipy.sparse.csr_matrix\n            The numerical gradient operator from nodes to edges\n\n        Notes\n        -----\n        In continuous space, the gradient operator is defined as:\n\n        .. math::\n            \\vec{u} = \\nabla \\phi = \\frac{\\partial \\phi}{\\partial x}\\hat{x}\n            + \\frac{\\partial \\phi}{\\partial y}\\hat{y}\n            + \\frac{\\partial \\phi}{\\partial z}\\hat{z}\n\n        Where :math:`\\boldsymbol{\\phi}` is the discrete representation of the continuous variable\n        :math:`\\phi` on the nodes and :math:`\\mathbf{u}` is the discrete\n        representation of :math:`\\vec{u}` on the edges, **nodal_gradient** constructs a\n        discrete linear operator :math:`\\mathbf{G_n}` such that:\n\n        .. math::\n            \\mathbf{u} = \\mathbf{G_n} \\, \\boldsymbol{\\phi}\n\n        The Cartesian components of :math:`\\vec{u}` are defined on their corresponding\n        edges (x, y or z) as follows; e.g. the x-component of the gradient is defined\n        on x-edges. For edge :math:`i` which defines a straight path\n        of length :math:`h_i` between adjacent nodes :math:`n_1` and :math:`n_2`:\n\n        .. math::\n            u_i = \\frac{\\phi_{n_2} - \\phi_{n_1}}{h_i}\n\n        Note that :math:`u_i \\in \\mathbf{u}` may correspond to a value on an\n        x, y or z edge. See the example below.\n        ", 0},
  {(char *)"nodal_laplacian", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_nodal_laplacian, 0, (char *)"Not implemented on the TreeMesh.", 0},
  {(char *)"stencil_cell_gradient_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_x, 0, (char *)"Differencing operator along x-direction to total (including hanging) x faces.\n\n        This property constructs a differencing operator along the x-axis\n        that acts on cell centered quantities; i.e. the stencil for the\n        x-component of the cell gradient. The operator computes the\n        differences between the values at adjacent cell centers along the\n        x-direction, and places the result on the x-faces. The operator is a sparse\n        matrix :math:`\\mathbf{G_x}` that can be applied as a matrix-vector\n        product to a cell centered quantity :math:`\\boldsymbol{\\phi}`, i.e.::\n\n            diff_phi_x = Gx @ phi\n\n        By default, the operator assumes zero-Neumann boundary conditions\n        on the scalar quantity.\n\n        Returns\n        -------\n        (n_total_faces_x, n_cells) scipy.sparse.csr_matrix\n            The stencil for the x-component of the cell gradient\n        ", 0},
  {(char *)"stencil_cell_gradient_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_y, 0, (char *)"Differencing operator along y-direction to total (including hanging) y faces.\n\n        This property constructs a differencing operator along the y-axis\n        that acts on cell centered quantities; i.e. the stencil for the\n        y-component of the cell gradient. The operator computes the\n        differences between the values at adjacent cell centers along the\n        y-direction, and places the result on the y-faces. The operator is a sparse\n        matrix :math:`\\mathbf{G_y}` that can be applied as a matrix-vector\n        product to a cell centered quantity :math:`\\boldsymbol{\\phi}`, i.e.::\n\n            diff_phi_y = Gy @ phi\n\n        By default, the operator assumes zero-Neumann boundary conditions\n        on the scalar quantity.\n\n        Returns\n        -------\n        (n_total_faces_y, n_cells) scipy.sparse.csr_matrix\n            The stencil for the y-component of the cell gradient\n        ", 0},
  {(char *)"stencil_cell_gradient_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_stencil_cell_gradient_z, 0, (char *)"Differencing operator along z-direction to total (including hanging) z faces.\n\n        This property constructs a differencing operator along the z-axis\n        that acts on cell centered quantities; i.e. the stencil for the\n        z-component of the cell gradient. The operator computes the\n        differences between the values at adjacent cell centers along the\n        z-direction, and places the result on the z-faces. The operator is a sparse\n        matrix :math:`\\mathbf{G_z}` that can be applied as a matrix-vector\n        product to a cell centered quantity :math:`\\boldsymbol{\\phi}`, i.e.::\n\n            diff_phi_z = Gz @ phi\n\n        By default, the operator assumes zero-Neumann boundary conditions\n        on the scalar quantity.\n\n        Returns\n        -------\n        (n_total_faces_z, n_cells) scipy.sparse.csr_matrix\n            The stencil for the z-component of the cell gradient\n        ", 0},
  {(char *)"average_edge_x_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_x_to_cell, 0, (char *)"Averaging operator from x-edges to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from x-edges to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on x-edges must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_edges_x) scipy.sparse.csr_matrix\n            The scalar averaging operator from x-edges to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_x}` be a discrete scalar quantity that\n        lives on x-edges. **average_edge_x_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{xc}}` that projects\n        :math:`\\boldsymbol{\\phi_x}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{xc}} \\, \\boldsymbol{\\phi_x}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its x-edges. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Axc @ phi_x\n        ", 0},
  {(char *)"average_edge_y_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_y_to_cell, 0, (char *)"Averaging operator from y-edges to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from y-edges to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on y-edges must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_edges_y) scipy.sparse.csr_matrix\n            The scalar averaging operator from y-edges to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_y}` be a discrete scalar quantity that\n        lives on y-edges. **average_edge_y_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{yc}}` that projects\n        :math:`\\boldsymbol{\\phi_y}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{yc}} \\, \\boldsymbol{\\phi_y}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its y-edges. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Ayc @ phi_y\n        ", 0},
  {(char *)"average_edge_z_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_z_to_cell, 0, (char *)"Averaging operator from z-edges to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from z-edges to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on z-edges must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_edges_z) scipy.sparse.csr_matrix\n            The scalar averaging operator from z-edges to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_z}` be a discrete scalar quantity that\n        lives on z-edges. **average_edge_z_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{zc}}` that projects\n        :math:`\\boldsymbol{\\phi_z}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{zc}} \\, \\boldsymbol{\\phi_z}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its z-edges. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Azc @ phi_z\n        ", 0},
  {(char *)"average_edge_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_cell, 0, (char *)"Averaging operator from edges to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from edges to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on mesh edges must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_edges) scipy.sparse.csr_matrix\n            The scalar averaging operator from edges to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_e}` be a discrete scalar quantity that\n        lives on mesh edges. **average_edge_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{ec}}` that projects\n        :math:`\\boldsymbol{\\phi_e}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{ec}} \\, \\boldsymbol{\\phi_e}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its edges. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Aec @ phi_e\n        ", 0},
  {(char *)"average_edge_to_cell_vector", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_cell_vector, 0, (char *)"Averaging operator from edges to cell centers (vector quantities).\n\n        This property constructs the averaging operator that independently maps the\n        Cartesian components of vector quantities from edges to cell centers.\n        This averaging operators is used when a discrete vector quantity defined on mesh edges\n        must be approximated at cell centers. Once constructed, the operator is\n        stored permanently as a property of the mesh.\n\n        Be aware that the Cartesian components of the original vector\n        are defined on their respective edges; e.g. the x-component lives\n        on x-edges. However, the x, y and z components are being averaged\n        separately to cell centers. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            u_c = Aec @ u_e\n\n        Returns\n        -------\n        (dim * n_cells, n_edges) scipy.sparse.csr_matrix\n            The vector averaging operator from edges to cell centers. Since we\n            are averaging a vector quantity to cell centers, the first dimension\n            of the operator is the mesh dimension times the number of cells.\n\n        Notes\n        -----\n        Let :math:`\\mathbf{u_e}` be the discrete representation of a vector\n        quantity whose Cartesian components are defined on their respective edges;\n        e.g. :math:`u_x` is defined on x-edges.\n        **average_edge_to_cell_vector** constructs a discrete linear operator\n        :math:`\\mathbf{A_{ec}}` that projects each Cartesian component of\n        :math:`\\mathbf{u_e}` independently to cell centers, i.e.:\n\n        .. math::\n            \\mathbf{u_c} = \\mathbf{A_{ec}} \\, \\mathbf{u_e}\n\n        where :math:`\\mathbf{u_c}` is a discrete vector quantity whose Cartesian\n        components defined at the cell centers and organized into a 1D array of\n        the form np.r_[ux, uy, uz]. For each cell, and for each Cartesian component,\n        we are simply taking the ""average of the values\n        defined on the cell's corresponding edges and placing the result at\n        the cell's center.\n        ", 0},
  {(char *)"average_edge_to_face", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_edge_to_face, 0, (char *)"Averaging operator from edges to faces.\n\n        This property constructs the averaging operator that maps uantities from edges to faces.\n        This averaging operators is used when a discrete quantity defined on mesh edges\n        must be approximated at faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            u_f = Aef @ u_e\n\n        Once constructed, the operator is stored permanently as a property of the mesh.\n\n        Returns\n        -------\n        (n_faces, n_edges) scipy.sparse.csr_matrix\n            The averaging operator from edges to faces.\n\n        Notes\n        -----\n        Let :math:`\\mathbf{u_e}` be the discrete representation of aquantity whose\n        that is defined on the edges. **average_edge_to_face**\n        constructs a discrete linear operator :math:`\\mathbf{A_{ef}}` that\n        projects :math:`\\mathbf{u_e}` to its corresponding face, i.e.:\n\n        .. math::\n            \\mathbf{u_f} = \\mathbf{A_{ef}} \\, \\mathbf{u_e}\n\n        where :math:`\\mathbf{u_f}` is a quantity defined on the respective faces.\n        ", 0},
  {(char *)"average_face_x_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_x_to_cell, 0, (char *)"Averaging operator from x-faces to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from x-faces to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on x-faces must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh.\n\n        Returns\n        -------\n        (n_cells, n_faces_x) scipy.sparse.csr_matrix\n            The scalar averaging operator from x-faces to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_x}` be a discrete scalar quantity that\n        lives on x-faces. **average_face_x_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{xc}}` that projects\n        :math:`\\boldsymbol{\\phi_x}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{xc}} \\, \\boldsymbol{\\phi_x}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its x-faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Axc @ phi_x\n        ", 0},
  {(char *)"average_face_y_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_y_to_cell, 0, (char *)"Averaging operator from y-faces to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from y-faces to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on x-faces must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_faces_y) scipy.sparse.csr_matrix\n            The scalar averaging operator from y-faces to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_y}` be a discrete scalar quantity that\n        lives on y-faces. **average_face_y_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{yc}}` that projects\n        :math:`\\boldsymbol{\\phi_y}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{yc}} \\, \\boldsymbol{\\phi_y}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its y-faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Ayc @ phi_y\n        ", 0},
  {(char *)"average_face_z_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_z_to_cell, 0, (char *)"Averaging operator from z-faces to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from z-faces to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on z-faces must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_faces_z) scipy.sparse.csr_matrix\n            The scalar averaging operator from z-faces to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_z}` be a discrete scalar quantity that\n        lives on z-faces. **average_face_z_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{zc}}` that projects\n        :math:`\\boldsymbol{\\phi_z}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{zc}} \\, \\boldsymbol{\\phi_z}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its z-faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Azc @ phi_z\n        ", 0},
  {(char *)"average_face_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_to_cell, 0, (char *)"Averaging operator from faces to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from faces to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on mesh faces must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_faces) scipy.sparse.csr_matrix\n            The scalar averaging operator from faces to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_f}` be a discrete scalar quantity that\n        lives on mesh faces. **average_face_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{fc}}` that projects\n        :math:`\\boldsymbol{\\phi_f}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{fc}} \\, \\boldsymbol{\\phi_f}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Afc @ phi_f\n        ", 0},
  {(char *)"average_face_to_cell_vector", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_face_to_cell_vector, 0, (char *)"Averaging operator from faces to cell centers (vector quantities).\n\n        This property constructs the averaging operator that independently maps the\n        Cartesian components of vector quantities from faces to cell centers.\n        This averaging operators is used when a discrete vector quantity defined on mesh faces\n        must be approximated at cell centers. Once constructed, the operator is\n        stored permanently as a property of the mesh.\n\n        Be aware that the Cartesian components of the original vector\n        are defined on their respective faces; e.g. the x-component lives\n        on x-faces. However, the x, y and z components are being averaged\n        separately to cell centers. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            u_c = Afc @ u_f\n\n        Returns\n        -------\n        (dim * n_cells, n_faces) scipy.sparse.csr_matrix\n            The vector averaging operator from faces to cell centers. Since we\n            are averaging a vector quantity to cell centers, the first dimension\n            of the operator is the mesh dimension times the number of cells.\n\n        Notes\n        -----\n        Let :math:`\\mathbf{u_f}` be the discrete representation of a vector\n        quantity whose Cartesian components are defined on their respective faces;\n        e.g. :math:`u_x` is defined on x-faces.\n        **average_face_to_cell_vector** constructs a discrete linear operator\n        :math:`\\mathbf{A_{fc}}` that projects each Cartesian component of\n        :math:`\\mathbf{u_f}` independently to cell centers, i.e.:\n\n        .. math::\n            \\mathbf{u_c} = \\mathbf{A_{fc}} \\, \\mathbf{u_f}\n\n        where :math:`\\mathbf{u_c}` is a discrete vector quantity whose Cartesian\n        components defined at the cell centers and organized into a 1D array of\n        the form np.r_[ux, uy, uz]. For each cell, and for each Cartesian component,\n        we are simply taking the ""average of the values\n        defined on the cell's corresponding faces and placing the result at\n        the cell's center.\n        ", 0},
  {(char *)"average_node_to_cell", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_cell, 0, (char *)"Averaging operator from nodes to cell centers (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to cell centers. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to cell centers. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_cells, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to cell centers\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_n}` be a discrete scalar quantity that\n        lives on mesh nodes. **average_node_to_cell** constructs a discrete\n        linear operator :math:`\\mathbf{A_{nc}}` that projects\n        :math:`\\boldsymbol{\\phi_f}` to cell centers, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_c} = \\mathbf{A_{nc}} \\, \\boldsymbol{\\phi_n}\n\n        where :math:`\\boldsymbol{\\phi_c}` approximates the value of the scalar\n        quantity at cell centers. For each cell, we are simply averaging\n        the values defined on its nodes. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_c = Anc @ phi_n\n        ", 0},
  {(char *)"average_node_to_edge_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_x, 0, (char *)"Averaging operator from nodes to x edges (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to edges.\n\n        Returns\n        -------\n        (n_edges_x, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to edges\n        ", 0},
  {(char *)"average_node_to_edge_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_y, 0, (char *)"Averaging operator from nodes to y edges (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to edges.\n\n        Returns\n        -------\n        (n_edges_y, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to edges\n        ", 0},
  {(char *)"average_node_to_edge_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge_z, 0, (char *)"Averaging operator from nodes to z edges (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to edges.\n\n        Returns\n        -------\n        (n_edges_z, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to edges\n        ", 0},
  {(char *)"average_node_to_edge", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_edge, 0, (char *)"Averaging operator from nodes to edges (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges; scalar at edges is organized in a 1D numpy.array\n        of the form [x-edges, y-edges, z-edges]. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to edges. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_edges, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to edges\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_n}` be a discrete scalar quantity that\n        lives on mesh nodes. **average_node_to_edge** constructs a discrete\n        linear operator :math:`\\mathbf{A_{ne}}` that projects\n        :math:`\\boldsymbol{\\phi_n}` to edges, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_e} = \\mathbf{A_{ne}} \\, \\boldsymbol{\\phi_n}\n\n        where :math:`\\boldsymbol{\\phi_e}` approximates the value of the scalar\n        quantity at edges. For each edge, we are simply averaging\n        the values defined on the nodes it connects. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_e = Ane @ phi_n\n        ", 0},
  {(char *)"average_node_to_face_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_x, 0, (char *)"Averaging operator from nodes to x faces (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_x, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to faces\n        ", 0},
  {(char *)"average_node_to_face_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_y, 0, (char *)"Averaging operator from nodes to y faces (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_y, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to faces\n        ", 0},
  {(char *)"average_node_to_face_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face_z, 0, (char *)"Averaging operator from nodes to z faces (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_z, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to faces\n        ", 0},
  {(char *)"average_node_to_face", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_node_to_face, 0, (char *)"Averaging operator from nodes to faces (scalar quantities).\n\n        This property constructs a 2nd order averaging operator that maps scalar\n        quantities from nodes to edges; scalar at faces is organized in a 1D numpy.array\n        of the form [x-faces, y-faces, z-faces]. This averaging operator is\n        used when a discrete scalar quantity defined on mesh nodes must be\n        projected to faces. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_faces, n_nodes) scipy.sparse.csr_matrix\n            The scalar averaging operator from nodes to faces\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_n}` be a discrete scalar quantity that\n        lives on mesh nodes. **average_node_to_face** constructs a discrete\n        linear operator :math:`\\mathbf{A_{nf}}` that projects\n        :math:`\\boldsymbol{\\phi_n}` to faces, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_f} = \\mathbf{A_{nf}} \\, \\boldsymbol{\\phi_n}\n\n        where :math:`\\boldsymbol{\\phi_f}` approximates the value of the scalar\n        quantity at faces. For each face, we are simply averaging the values at\n        the nodes which outline the face. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            phi_f = Anf @ phi_n\n        ", 0},
  {(char *)"average_cell_to_face", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face, 0, (char *)"Averaging operator from cell centers to faces (scalar quantities).\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces. Once constructed, the operator is stored\n        permanently as a property of the mesh. *See notes*.\n\n        Returns\n        -------\n        (n_faces, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from cell centers to faces\n\n        Notes\n        -----\n        Let :math:`\\boldsymbol{\\phi_c}` be a discrete scalar quantity that\n        lives at cell centers. **average_cell_to_face** constructs a discrete\n        linear operator :math:`\\mathbf{A_{cf}}` that projects\n        :math:`\\boldsymbol{\\phi_c}` to faces, i.e.:\n\n        .. math::\n            \\boldsymbol{\\phi_f} = \\mathbf{A_{cf}} \\, \\boldsymbol{\\phi_c}\n\n        where :math:`\\boldsymbol{\\phi_f}` approximates the value of the scalar\n        quantity at the faces. For each face, we are performing a weighted average\n        between the values at adjacent cell centers. In 1D, where adjacent cells\n        :math:`i` and :math:`i+1` have widths :math:`h_i` and :math:`h_{i+1}`,\n        :math:`\\phi` on face is approximated by:\n\n        .. math::\n            \\phi_{i \\! + \\! 1/2} \\approx \\frac{h_{i+1} \\phi_i + h_i \\phi_{i+1}}{h_i + h_{i+1}}\n\n        On boundary faces, nearest neighbour is used to extrapolate the value\n        from the nearest cell center. Once the operator is construct, the averaging\n        is implemented as a matrix vector product, i.e.::\n\n            phi_f = Acf @ phi_c\n        ", 0},
  {(char *)"average_cell_vector_to_face", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_vector_to_face, 0, (char *)"Averaging operator from cell centers to faces (vector quantities).\n\n        This property constructs the averaging operator that independently maps the\n        Cartesian components of vector quantities from cell centers to faces.\n        This averaging operators is used when a discrete vector quantity defined at\n        cell centers must be approximated on the faces. Once constructed, the operator is\n        stored permanently as a property of the mesh.\n\n        Be aware that the Cartesian components of the original vector\n        are defined seperately at cell centers in a 1D numpy.array organized [ux, uy, uz].\n        Once projected to faces, the Cartesian components are defined on their respective\n        faces; e.g. the x-component lives on x-faces. The operation is implemented as a\n        matrix vector product, i.e.::\n\n            u_f = Acf @ u_c\n\n        Returns\n        -------\n        (n_faces, dim * n_cells) scipy.sparse.csr_matrix\n            The vector averaging operator from cell centers to faces. Since we\n            are averaging a vector quantity from cell centers, the second dimension\n            of the operator is the mesh dimension times the number of cells.\n\n        Notes\n        -----\n        Let :math:`\\mathbf{u_c}` be the discrete representation of a vector\n        quantity whose Cartesian components are defined separately at cell centers.\n        **average_cell_vector_to_face** constructs a discrete linear operator\n        :math:`\\mathbf{A_{cf}}` that projects each Cartesian component of\n        :math:`\\mathbf{u_c}` to the faces, i.e.:\n\n        .. math::\n            \\mathbf{u_f} = \\mathbf{A_{cf}} \\, \\mathbf{u_c}\n\n        where :math:`\\mathbf{u_f}` is the discrete vector quantity whose Cartesian\n        components are approximated on their respective cell faces; e.g. the x-component is\n        approximated on x-faces. For each face (x, y or z), we are simply taking a weighted average\n        between ""the values of the correct Cartesian component at the corresponding cell centers.\n\n        E.g. for the x-component, which is projected to x-faces, the weighted average on\n        a 2D mesh would be:\n\n        .. math::\n            u_x(i \\! + \\! 1/2, j) = \\frac{h_{i+1} u_x (i,j) + h_i u_x(i \\! + \\! 1,j)}{hx_i + hx_{i+1}}\n\n        where :math:`h_i` and :math:`h_{i+1}` represent the cell respective cell widths\n        in the x-direction. For boundary faces, nearest neighbor is used to extrapolate\n        the values.\n        ", 0},
  {(char *)"average_cell_to_face_x", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_x, 0, (char *)"Averaging operator from cell centers to x faces (scalar quantities).\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_x, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from cell centers to x faces\n        ", 0},
  {(char *)"average_cell_to_face_y", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_y, 0, (char *)"Averaging operator from cell centers to y faces (scalar quantities).\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_y, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from cell centers to y faces\n        ", 0},
  {(char *)"average_cell_to_face_z", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_average_cell_to_face_z, 0, (char *)"Averaging operator from cell centers to z faces (scalar quantities).\n\n        This property constructs an averaging operator that maps scalar\n        quantities from cell centers to face. This averaging operator is\n        used when a discrete scalar quantity defined cell centers must be\n        projected to faces.\n\n        Returns\n        -------\n        (n_faces_z, n_cells) scipy.sparse.csr_matrix\n            The scalar averaging operator from cell centers to z faces\n        ", 0},
  {(char *)"project_face_to_boundary_face", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_face_to_boundary_face, 0, (char *)"Projection matrix from all faces to boundary faces.\n\n        Constructs and returns a matrix :math:`\\mathbf{P}` that projects from\n        all mesh faces to boundary faces. That is, for a discrete vector\n        :math:`\\mathbf{u}` that lives on the faces, the values on the boundary\n        faces :math:`\\mathbf{u_b}` can be extracted via the following\n        matrix-vector product::\n\n            ub = P @ u\n\n        Returns\n        -------\n        scipy.sparse.csr_matrix\n            (n_boundary_faces, n_faces) Projection matrix with shape\n        ", 0},
  {(char *)"project_edge_to_boundary_edge", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_edge_to_boundary_edge, 0, (char *)"Projection matrix from all edges to boundary edges.\n\n        Constructs and returns a matrix :math:`\\mathbf{P}` that projects from\n        all mesh edges to boundary edges. That is, for a discrete vector\n        :math:`\\mathbf{u}` that lives on the edges, the values on the boundary\n        edges :math:`\\mathbf{u_b}` can be extracted via the following\n        matrix-vector product::\n\n            ub = P @ u\n\n        Returns\n        -------\n        (n_boundary_edges, n_edges) scipy.sparse.csr_matrix\n            Projection matrix with shape\n        ", 0},
  {(char *)"project_node_to_boundary_node", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_project_node_to_boundary_node, 0, (char *)"Projection matrix from all nodes to boundary nodes.\n\n        Constructs and returns a matrix :math:`\\mathbf{P}` that projects from\n        all mesh nodes to boundary nodes. That is, for a discrete scalar\n        :math:`\\mathbf{u}` that lives on the nodes, the values on the boundary\n        nodes :math:`\\mathbf{u_b}` can be extracted via the following\n        matrix-vector product::\n\n            ub = P @ u\n\n        Returns\n        -------\n        (n_boundary_nodes, n_nodes) scipy.sparse.csr_matrix\n            Projection matrix with shape\n        ", 0},
  {(char *)"cell_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_cell_nodes, 0, (char *)"The index of all nodes for each cell.\n\n        These indices point to non-hanging and hanging nodes.\n\n        Returns\n        -------\n        numpy.ndarray of int\n            Index array of shape (n_cells, 4) if 2D, or (n_cells, 8) if 3D\n\n        See also\n        --------\n        TreeMesh.total_nodes\n        ", 0},
  {(char *)"edge_nodes", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh_edge_nodes, 0, (char *)"The index of nodes for every edge.\n\n        The index of the nodes at each end of every (including hanging) edge.\n\n        Returns\n        -------\n        (dim) tuple of numpy.ndarray of int\n            One numpy array for each edge type (x, y, (z)) for this mesh.\n\n        Notes\n        -----\n        These arrays will also index into the hanging nodes.\n        ", 0},
  {(char *)"_ubc_indArr", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh__ubc_indArr, 0, (char *)0, 0},
  {(char *)"_ubc_order", __pyx_getprop_10discretize_11_extensions_8tree_ext_9_TreeMesh__ubc_order, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence__TreeMesh = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_10discretize_11_extensions_8tree_ext__TreeMesh, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping__TreeMesh = {
  0, /*mp_length*/
  __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_93__getitem__, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext._TreeMesh", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence__TreeMesh, /*tp_as_sequence*/
  &__pyx_tp_as_mapping__TreeMesh, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "_TreeMesh(h, origin, bool diagonal_balance=False)", /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_10discretize_11_extensions_8tree_ext_9_TreeMesh_3__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext__TreeMesh, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine[8];
static int __pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine = 0;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine)))) {
    o = (PyObject*)__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine[--__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine];
    memset(o, 0, sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_level);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine)))) {
    __pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine[__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine++] = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)o;
  if (p->__pyx_v_level) {
    e = (*v)(p->__pyx_v_level, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine *)o;
  tmp = ((PyObject*)p->__pyx_v_level);
  p->__pyx_v_level = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.__pyx_scope_struct__refine", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx[8];
static int __pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx = 0;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx)))) {
    o = (PyObject*)__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx[--__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx];
    memset(o, 0, sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx)))) {
    __pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx[__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx++] = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)o;
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx *)o;
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.__pyx_scope_struct_1__getFacePxx", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx[8];
static int __pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx = 0;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx)))) {
    o = (PyObject*)__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx[--__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx];
    memset(o, 0, sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx)))) {
    __pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx[__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx++] = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)o;
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx *)o;
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.__pyx_scope_struct_2__getFacePxxx", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx[8];
static int __pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx = 0;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx)))) {
    o = (PyObject*)__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx[--__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx];
    memset(o, 0, sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx)))) {
    __pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx[__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx++] = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)o;
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx *)o;
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.__pyx_scope_struct_3__getEdgePxx", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx[8];
static int __pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx = 0;

static PyObject *__pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx)))) {
    o = (PyObject*)__pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx[--__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx];
    memset(o, 0, sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(PyObject *o) {
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx)))) {
    __pyx_freelist_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx[__pyx_freecount_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx++] = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)o;
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *p = (struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx *)o;
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = ((struct __pyx_obj_10discretize_11_extensions_8tree_ext__TreeMesh *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.__pyx_scope_struct_4__getEdgePxxx", /*tp_name*/
  sizeof(struct __pyx_obj_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx, /*tp_traverse*/
  __pyx_tp_clear_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_array __pyx_vtable_array;

static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_array_obj *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_array_obj *)o);
  p->__pyx_vtab = __pyx_vtabptr_array;
  p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None);
  p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_array(PyObject *o) {
  struct __pyx_array_obj *p = (struct __pyx_array_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_array___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->mode);
  Py_CLEAR(p->_format);
  (*Py_TYPE(o)->tp_free)(o);
}
static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_array___setitem__(o, i, v);
  }
  else {
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);
    return -1;
  }
}

static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) {
  PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n);
  if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {
    PyErr_Clear();
    v = __pyx_array___getattr__(o, n);
  }
  return v;
}

static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o);
}

static PyMethodDef __pyx_methods_array[] = {
  {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_array[] = {
  {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_array = {
  __pyx_array___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_array, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_array = {
  __pyx_array___len__, /*mp_length*/
  __pyx_array___getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_array = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  __pyx_array_getbuffer, /*bf_getbuffer*/
  0, /*bf_releasebuffer*/
};

static PyTypeObject __pyx_type___pyx_array = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.array", /*tp_name*/
  sizeof(struct __pyx_array_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_array, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_array, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_array, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  __pyx_tp_getattro_array, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_array, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_array, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_array, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_array, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_MemviewEnum_obj *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_MemviewEnum_obj *)o);
  p->name = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_Enum(PyObject *o) {
  struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->name);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_Enum(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o;
  if (p->name) {
    e = (*v)(p->name, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_Enum(PyObject *o) {
  PyObject* tmp;
  struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o;
  tmp = ((PyObject*)p->name);
  p->name = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_Enum[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type___pyx_MemviewEnum = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.Enum", /*tp_name*/
  sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_Enum, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_MemviewEnum___repr__, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_Enum, /*tp_traverse*/
  __pyx_tp_clear_Enum, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_Enum, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_MemviewEnum___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_Enum, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview;

static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_memoryview_obj *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_memoryview_obj *)o);
  p->__pyx_vtab = __pyx_vtabptr_memoryview;
  p->obj = Py_None; Py_INCREF(Py_None);
  p->_size = Py_None; Py_INCREF(Py_None);
  p->_array_interface = Py_None; Py_INCREF(Py_None);
  p->view.obj = NULL;
  if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_memoryview(PyObject *o) {
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_memoryview___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->obj);
  Py_CLEAR(p->_size);
  Py_CLEAR(p->_array_interface);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  if (p->obj) {
    e = (*v)(p->obj, a); if (e) return e;
  }
  if (p->_size) {
    e = (*v)(p->_size, a); if (e) return e;
  }
  if (p->_array_interface) {
    e = (*v)(p->_array_interface, a); if (e) return e;
  }
  if (p->view.obj) {
    e = (*v)(p->view.obj, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_memoryview(PyObject *o) {
  PyObject* tmp;
  struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o;
  tmp = ((PyObject*)p->obj);
  p->obj = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_size);
  p->_size = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_array_interface);
  p->_array_interface = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  Py_CLEAR(p->view.obj);
  return 0;
}
static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_memoryview___setitem__(o, i, v);
  }
  else {
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);
    return -1;
  }
}

static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o);
}

static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o);
}

static PyMethodDef __pyx_methods_memoryview[] = {
  {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0},
  {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0},
  {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0},
  {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_memoryview[] = {
  {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0},
  {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0},
  {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0},
  {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0},
  {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0},
  {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0},
  {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0},
  {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0},
  {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PySequenceMethods __pyx_tp_as_sequence_memoryview = {
  __pyx_memoryview___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_memoryview, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_memoryview = {
  __pyx_memoryview___len__, /*mp_length*/
  __pyx_memoryview___getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_memoryview = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  __pyx_memoryview_getbuffer, /*bf_getbuffer*/
  0, /*bf_releasebuffer*/
};

static PyTypeObject __pyx_type___pyx_memoryview = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext.memoryview", /*tp_name*/
  sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_memoryview, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_memoryview___repr__, /*tp_repr*/
  0, /*tp_as_number*/
  &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_memoryview___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_memoryview, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_memoryview, /*tp_traverse*/
  __pyx_tp_clear_memoryview, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_memoryview, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_memoryview, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_memoryview, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice;

static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_memoryviewslice_obj *p;
  PyObject *o = __pyx_tp_new_memoryview(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_memoryviewslice_obj *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice;
  p->from_object = Py_None; Py_INCREF(Py_None);
  p->from_slice.memview = NULL;
  return o;
}

static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) {
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_memoryviewslice___dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->from_object);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_memoryview(o);
}

static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e;
  if (p->from_object) {
    e = (*v)(p->from_object, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear__memoryviewslice(PyObject *o) {
  PyObject* tmp;
  struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o;
  __pyx_tp_clear_memoryview(o);
  tmp = ((PyObject*)p->from_object);
  p->from_object = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  __PYX_XDEC_MEMVIEW(&p->from_slice, 1);
  return 0;
}

static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o);
}

static PyMethodDef __pyx_methods__memoryviewslice[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = {
  {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type___pyx_memoryviewslice = {
  PyVarObject_HEAD_INIT(0, 0)
  "discretize._extensions.tree_ext._memoryviewslice", /*tp_name*/
  sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_memoryview___repr__, /*tp_repr*/
  #else
  0, /*tp_repr*/
  #endif
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_memoryview___str__, /*tp_str*/
  #else
  0, /*tp_str*/
  #endif
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "Internal class for passing memoryview slices to Python", /*tp_doc*/
  __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/
  __pyx_tp_clear__memoryviewslice, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods__memoryviewslice, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets__memoryviewslice, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new__memoryviewslice, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_tree_ext(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_tree_ext},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "tree_ext",
    0, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1},
  {&__pyx_kp_u_All_heights_must_be_positive, __pyx_k_All_heights_must_be_positive, sizeof(__pyx_k_All_heights_must_be_positive), 0, 1, 0, 0},
  {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0},
  {&__pyx_n_u_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 1, 0, 1},
  {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0},
  {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1},
  {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0},
  {&__pyx_n_u_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 1, 0, 1},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_k_Incompatible_checksums_0x_x_vs_0, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0), 0, 0, 1, 0},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0},
  {&__pyx_kp_u_Insert_cells_into_the_class_disc, __pyx_k_Insert_cells_into_the_class_disc, sizeof(__pyx_k_Insert_cells_into_the_class_disc), 0, 1, 0, 0},
  {&__pyx_kp_u_Invalid_argument_type, __pyx_k_Invalid_argument_type, sizeof(__pyx_k_Invalid_argument_type), 0, 1, 0, 0},
  {&__pyx_kp_u_Invalid_direction_must_be_x_y_or, __pyx_k_Invalid_direction_must_be_x_y_or, sizeof(__pyx_k_Invalid_direction_must_be_x_y_or), 0, 1, 0, 0},
  {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0},
  {&__pyx_kp_u_Last_character_of_edge_string_mu, __pyx_k_Last_character_of_edge_string_mu, sizeof(__pyx_k_Last_character_of_edge_string_mu), 0, 1, 0, 0},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0},
  {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0},
  {&__pyx_kp_u_Nodal_Laplacian_has_not_been_imp, __pyx_k_Nodal_Laplacian_has_not_been_imp, sizeof(__pyx_k_Nodal_Laplacian_has_not_been_imp), 0, 1, 0, 0},
  {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
  {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1},
  {&__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0},
  {&__pyx_kp_u_Path_not_found, __pyx_k_Path_not_found, sizeof(__pyx_k_Path_not_found), 0, 1, 0, 0},
  {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_Pxx, __pyx_k_Pxx, sizeof(__pyx_k_Pxx), 0, 0, 1, 1},
  {&__pyx_n_s_Pxxx, __pyx_k_Pxxx, sizeof(__pyx_k_Pxxx), 0, 0, 1, 1},
  {&__pyx_kp_u_Refine_class_discretize_TreeMesh, __pyx_k_Refine_class_discretize_TreeMesh, sizeof(__pyx_k_Refine_class_discretize_TreeMesh), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_class_discretize_TreeMesh_2, __pyx_k_Refine_class_discretize_TreeMesh_2, sizeof(__pyx_k_Refine_class_discretize_TreeMesh_2), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_the_class_discretize_Tree, __pyx_k_Refine_the_class_discretize_Tree, sizeof(__pyx_k_Refine_the_class_discretize_Tree), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_the_class_discretize_Tree_2, __pyx_k_Refine_the_class_discretize_Tree_2, sizeof(__pyx_k_Refine_the_class_discretize_Tree_2), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_the_class_discretize_Tree_3, __pyx_k_Refine_the_class_discretize_Tree_3, sizeof(__pyx_k_Refine_the_class_discretize_Tree_3), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_the_class_discretize_Tree_4, __pyx_k_Refine_the_class_discretize_Tree_4, sizeof(__pyx_k_Refine_the_class_discretize_Tree_4), 0, 1, 0, 0},
  {&__pyx_kp_u_Refine_the_class_discretize_Tree_5, __pyx_k_Refine_the_class_discretize_Tree_5, sizeof(__pyx_k_Refine_the_class_discretize_Tree_5), 0, 1, 0, 0},
  {&__pyx_kp_u_Returns_the_indices_of_the_x_y_a, __pyx_k_Returns_the_indices_of_the_x_y_a, sizeof(__pyx_k_Returns_the_indices_of_the_x_y_a), 0, 1, 0, 0},
  {&__pyx_kp_u_Returns_the_indices_of_the_x_y_a_2, __pyx_k_Returns_the_indices_of_the_x_y_a_2, sizeof(__pyx_k_Returns_the_indices_of_the_x_y_a_2), 0, 1, 0, 0},
  {&__pyx_kp_u_The_index_0_d_is_out_of_range, __pyx_k_The_index_0_d_is_out_of_range, sizeof(__pyx_k_The_index_0_d_is_out_of_range), 0, 1, 0, 0},
  {&__pyx_kp_u_There_are_no_z_edges_in_2D, __pyx_k_There_are_no_z_edges_in_2D, sizeof(__pyx_k_There_are_no_z_edges_in_2D), 0, 1, 0, 0},
  {&__pyx_kp_u_There_are_no_z_faces_in_2D, __pyx_k_There_are_no_z_faces_in_2D, sizeof(__pyx_k_There_are_no_z_faces_in_2D), 0, 1, 0, 0},
  {&__pyx_n_s_TreeCell, __pyx_k_TreeCell, sizeof(__pyx_k_TreeCell), 0, 0, 1, 1},
  {&__pyx_n_s_TreeMesh, __pyx_k_TreeMesh, sizeof(__pyx_k_TreeMesh), 0, 0, 1, 1},
  {&__pyx_kp_u_TreeMesh_cell_boundary_indices, __pyx_k_TreeMesh_cell_boundary_indices, sizeof(__pyx_k_TreeMesh_cell_boundary_indices), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_face_boundary_indices, __pyx_k_TreeMesh_face_boundary_indices, sizeof(__pyx_k_TreeMesh_face_boundary_indices), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_has_no_z_edges_in_2D, __pyx_k_TreeMesh_has_no_z_edges_in_2D, sizeof(__pyx_k_TreeMesh_has_no_z_edges_in_2D), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_has_no_z_faces_in_2D, __pyx_k_TreeMesh_has_no_z_faces_in_2D, sizeof(__pyx_k_TreeMesh_has_no_z_faces_in_2D), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_has_no_z_faces_in_2D_2, __pyx_k_TreeMesh_has_no_z_faces_in_2D_2, sizeof(__pyx_k_TreeMesh_has_no_z_faces_in_2D_2), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_insert_cells_line_1020, __pyx_k_TreeMesh_insert_cells_line_1020, sizeof(__pyx_k_TreeMesh_insert_cells_line_1020), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_ball_line_512, __pyx_k_TreeMesh_refine_ball_line_512, sizeof(__pyx_k_TreeMesh_refine_ball_line_512), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_box_line_601, __pyx_k_TreeMesh_refine_box_line_601, sizeof(__pyx_k_TreeMesh_refine_box_line_601), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_line_448, __pyx_k_TreeMesh_refine_line_448, sizeof(__pyx_k_TreeMesh_refine_line_448), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_line_line_686, __pyx_k_TreeMesh_refine_line_line_686, sizeof(__pyx_k_TreeMesh_refine_line_line_686), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_tetrahedron_lin, __pyx_k_TreeMesh_refine_tetrahedron_lin, sizeof(__pyx_k_TreeMesh_refine_tetrahedron_lin), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_triangle_line_7, __pyx_k_TreeMesh_refine_triangle_line_7, sizeof(__pyx_k_TreeMesh_refine_triangle_line_7), 0, 1, 0, 0},
  {&__pyx_kp_u_TreeMesh_refine_vertical_triang, __pyx_k_TreeMesh_refine_vertical_triang, sizeof(__pyx_k_TreeMesh_refine_vertical_triang), 0, 1, 0, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1},
  {&__pyx_kp_u__11, __pyx_k__11, sizeof(__pyx_k__11), 0, 1, 0, 0},
  {&__pyx_kp_u__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 1, 0, 0},
  {&__pyx_n_s__67, __pyx_k__67, sizeof(__pyx_k__67), 0, 0, 1, 1},
  {&__pyx_n_s_active_ind, __pyx_k_active_ind, sizeof(__pyx_k_active_ind), 0, 0, 1, 1},
  {&__pyx_n_s_allclose, __pyx_k_allclose, sizeof(__pyx_k_allclose), 0, 0, 1, 1},
  {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1},
  {&__pyx_kp_u_and_heights, __pyx_k_and_heights, sizeof(__pyx_k_and_heights), 0, 1, 0, 0},
  {&__pyx_kp_u_and_levels, __pyx_k_and_levels, sizeof(__pyx_k_and_levels), 0, 1, 0, 0},
  {&__pyx_n_s_any, __pyx_k_any, sizeof(__pyx_k_any), 0, 0, 1, 1},
  {&__pyx_n_s_arange, __pyx_k_arange, sizeof(__pyx_k_arange), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_asarray, __pyx_k_asarray, sizeof(__pyx_k_asarray), 0, 0, 1, 1},
  {&__pyx_n_s_atleast_1d, __pyx_k_atleast_1d, sizeof(__pyx_k_atleast_1d), 0, 0, 1, 1},
  {&__pyx_n_s_atleast_2d, __pyx_k_atleast_2d, sizeof(__pyx_k_atleast_2d), 0, 0, 1, 1},
  {&__pyx_n_s_aveFy2CC, __pyx_k_aveFy2CC, sizeof(__pyx_k_aveFy2CC), 0, 0, 1, 1},
  {&__pyx_n_s_average_cell_to_face_x, __pyx_k_average_cell_to_face_x, sizeof(__pyx_k_average_cell_to_face_x), 0, 0, 1, 1},
  {&__pyx_n_s_average_cell_to_face_y, __pyx_k_average_cell_to_face_y, sizeof(__pyx_k_average_cell_to_face_y), 0, 0, 1, 1},
  {&__pyx_n_s_average_cell_to_face_z, __pyx_k_average_cell_to_face_z, sizeof(__pyx_k_average_cell_to_face_z), 0, 0, 1, 1},
  {&__pyx_n_s_average_edge_to_face, __pyx_k_average_edge_to_face, sizeof(__pyx_k_average_edge_to_face), 0, 0, 1, 1},
  {&__pyx_n_s_average_edge_x_to_cell, __pyx_k_average_edge_x_to_cell, sizeof(__pyx_k_average_edge_x_to_cell), 0, 0, 1, 1},
  {&__pyx_n_s_average_edge_y_to_cell, __pyx_k_average_edge_y_to_cell, sizeof(__pyx_k_average_edge_y_to_cell), 0, 0, 1, 1},
  {&__pyx_n_s_average_edge_z_to_cell, __pyx_k_average_edge_z_to_cell, sizeof(__pyx_k_average_edge_z_to_cell), 0, 0, 1, 1},
  {&__pyx_n_s_average_face_x_to_cell, __pyx_k_average_face_x_to_cell, sizeof(__pyx_k_average_face_x_to_cell), 0, 0, 1, 1},
  {&__pyx_n_s_average_face_z_to_cell, __pyx_k_average_face_z_to_cell, sizeof(__pyx_k_average_face_z_to_cell), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_edge_x, __pyx_k_average_node_to_edge_x, sizeof(__pyx_k_average_node_to_edge_x), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_edge_y, __pyx_k_average_node_to_edge_y, sizeof(__pyx_k_average_node_to_edge_y), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_edge_z, __pyx_k_average_node_to_edge_z, sizeof(__pyx_k_average_node_to_edge_z), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_face_x, __pyx_k_average_node_to_face_x, sizeof(__pyx_k_average_node_to_face_x), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_face_y, __pyx_k_average_node_to_face_y, sizeof(__pyx_k_average_node_to_face_y), 0, 0, 1, 1},
  {&__pyx_n_s_average_node_to_face_z, __pyx_k_average_node_to_face_z, sizeof(__pyx_k_average_node_to_face_z), 0, 0, 1, 1},
  {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1},
  {&__pyx_n_s_bincount, __pyx_k_bincount, sizeof(__pyx_k_bincount), 0, 0, 1, 1},
  {&__pyx_n_s_block_diag, __pyx_k_block_diag, sizeof(__pyx_k_block_diag), 0, 0, 1, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1},
  {&__pyx_n_s_cell_boundary_indices, __pyx_k_cell_boundary_indices, sizeof(__pyx_k_cell_boundary_indices), 0, 0, 1, 1},
  {&__pyx_n_s_cell_centers, __pyx_k_cell_centers, sizeof(__pyx_k_cell_centers), 0, 0, 1, 1},
  {&__pyx_n_s_cell_volumes, __pyx_k_cell_volumes, sizeof(__pyx_k_cell_volumes), 0, 0, 1, 1},
  {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
  {&__pyx_n_s_clear_cache, __pyx_k_clear_cache, sizeof(__pyx_k_clear_cache), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_column_stack, __pyx_k_column_stack, sizeof(__pyx_k_column_stack), 0, 0, 1, 1},
  {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0},
  {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_u_csr, __pyx_k_csr, sizeof(__pyx_k_csr), 0, 1, 0, 1},
  {&__pyx_n_s_csr_matrix, __pyx_k_csr_matrix, sizeof(__pyx_k_csr_matrix), 0, 0, 1, 1},
  {&__pyx_n_s_cumsum, __pyx_k_cumsum, sizeof(__pyx_k_cumsum), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_edges, __pyx_k_deflate_edges, sizeof(__pyx_k_deflate_edges), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_edges_x, __pyx_k_deflate_edges_x, sizeof(__pyx_k_deflate_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_edges_y, __pyx_k_deflate_edges_y, sizeof(__pyx_k_deflate_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_edges_z, __pyx_k_deflate_edges_z, sizeof(__pyx_k_deflate_edges_z), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_faces, __pyx_k_deflate_faces, sizeof(__pyx_k_deflate_faces), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_faces_x, __pyx_k_deflate_faces_x, sizeof(__pyx_k_deflate_faces_x), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_faces_y, __pyx_k_deflate_faces_y, sizeof(__pyx_k_deflate_faces_y), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_faces_z, __pyx_k_deflate_faces_z, sizeof(__pyx_k_deflate_faces_z), 0, 0, 1, 1},
  {&__pyx_n_s_deflate_nodes, __pyx_k_deflate_nodes, sizeof(__pyx_k_deflate_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_diagonal_balance, __pyx_k_diagonal_balance, sizeof(__pyx_k_diagonal_balance), 0, 0, 1, 1},
  {&__pyx_n_s_diags, __pyx_k_diags, sizeof(__pyx_k_diags), 0, 0, 1, 1},
  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
  {&__pyx_n_s_dim, __pyx_k_dim, sizeof(__pyx_k_dim), 0, 0, 1, 1},
  {&__pyx_n_s_direction, __pyx_k_direction, sizeof(__pyx_k_direction), 0, 0, 1, 1},
  {&__pyx_kp_s_discretize__extensions_tree_ext, __pyx_k_discretize__extensions_tree_ext, sizeof(__pyx_k_discretize__extensions_tree_ext), 0, 0, 1, 0},
  {&__pyx_n_s_discretize__extensions_tree_ext_2, __pyx_k_discretize__extensions_tree_ext_2, sizeof(__pyx_k_discretize__extensions_tree_ext_2), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1},
  {&__pyx_n_s_edge_lengths, __pyx_k_edge_lengths, sizeof(__pyx_k_edge_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_edges_x, __pyx_k_edges_x, sizeof(__pyx_k_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_edges_y, __pyx_k_edges_y, sizeof(__pyx_k_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_edges_z, __pyx_k_edges_z, sizeof(__pyx_k_edges_z), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_eps, __pyx_k_eps, sizeof(__pyx_k_eps), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_n_s_eye, __pyx_k_eye, sizeof(__pyx_k_eye), 0, 0, 1, 1},
  {&__pyx_n_u_fXp, __pyx_k_fXp, sizeof(__pyx_k_fXp), 0, 1, 0, 1},
  {&__pyx_n_u_fYp, __pyx_k_fYp, sizeof(__pyx_k_fYp), 0, 1, 0, 1},
  {&__pyx_n_u_fZp, __pyx_k_fZp, sizeof(__pyx_k_fZp), 0, 1, 0, 1},
  {&__pyx_n_s_face_divergence_2D, __pyx_k_face_divergence_2D, sizeof(__pyx_k_face_divergence_2D), 0, 0, 1, 1},
  {&__pyx_n_s_face_divergence_3D, __pyx_k_face_divergence_3D, sizeof(__pyx_k_face_divergence_3D), 0, 0, 1, 1},
  {&__pyx_n_s_face_normals, __pyx_k_face_normals, sizeof(__pyx_k_face_normals), 0, 0, 1, 1},
  {&__pyx_n_s_faces_x, __pyx_k_faces_x, sizeof(__pyx_k_faces_x), 0, 0, 1, 1},
  {&__pyx_n_s_faces_y, __pyx_k_faces_y, sizeof(__pyx_k_faces_y), 0, 0, 1, 1},
  {&__pyx_n_s_faces_z, __pyx_k_faces_z, sizeof(__pyx_k_faces_z), 0, 0, 1, 1},
  {&__pyx_n_s_finalize, __pyx_k_finalize, sizeof(__pyx_k_finalize), 0, 0, 1, 1},
  {&__pyx_n_s_finfo, __pyx_k_finfo, sizeof(__pyx_k_finfo), 0, 0, 1, 1},
  {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1},
  {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1},
  {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1},
  {&__pyx_n_s_full, __pyx_k_full, sizeof(__pyx_k_full), 0, 0, 1, 1},
  {&__pyx_n_s_function, __pyx_k_function, sizeof(__pyx_k_function), 0, 0, 1, 1},
  {&__pyx_n_s_getEdgeP, __pyx_k_getEdgeP, sizeof(__pyx_k_getEdgeP), 0, 0, 1, 1},
  {&__pyx_n_s_getEdgePxx_locals_Pxx, __pyx_k_getEdgePxx_locals_Pxx, sizeof(__pyx_k_getEdgePxx_locals_Pxx), 0, 0, 1, 1},
  {&__pyx_n_s_getEdgePxxx_locals_Pxxx, __pyx_k_getEdgePxxx_locals_Pxxx, sizeof(__pyx_k_getEdgePxxx_locals_Pxxx), 0, 0, 1, 1},
  {&__pyx_n_s_getFaceP, __pyx_k_getFaceP, sizeof(__pyx_k_getFaceP), 0, 0, 1, 1},
  {&__pyx_n_s_getFacePxx_locals_Pxx, __pyx_k_getFacePxx_locals_Pxx, sizeof(__pyx_k_getFacePxx_locals_Pxx), 0, 0, 1, 1},
  {&__pyx_n_s_getFacePxxx_locals_Pxxx, __pyx_k_getFacePxxx_locals_Pxxx, sizeof(__pyx_k_getFacePxxx_locals_Pxxx), 0, 0, 1, 1},
  {&__pyx_n_s_get_containing_cell_indexes, __pyx_k_get_containing_cell_indexes, sizeof(__pyx_k_get_containing_cell_indexes), 0, 0, 1, 1},
  {&__pyx_n_s_getnnz, __pyx_k_getnnz, sizeof(__pyx_k_getnnz), 0, 0, 1, 1},
  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
  {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_hanging_edges_x, __pyx_k_hanging_edges_x, sizeof(__pyx_k_hanging_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_hanging_edges_y, __pyx_k_hanging_edges_y, sizeof(__pyx_k_hanging_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_hstack, __pyx_k_hstack, sizeof(__pyx_k_hstack), 0, 0, 1, 1},
  {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1},
  {&__pyx_n_s_imatmul, __pyx_k_imatmul, sizeof(__pyx_k_imatmul), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_in_tens_mesh, __pyx_k_in_tens_mesh, sizeof(__pyx_k_in_tens_mesh), 0, 0, 1, 1},
  {&__pyx_kp_u_inconsistent_number_of_line_segm, __pyx_k_inconsistent_number_of_line_segm, sizeof(__pyx_k_inconsistent_number_of_line_segm), 0, 1, 0, 0},
  {&__pyx_kp_u_inconsistent_number_of_triangles, __pyx_k_inconsistent_number_of_triangles, sizeof(__pyx_k_inconsistent_number_of_triangles), 0, 1, 0, 0},
  {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  {&__pyx_n_s_init___locals_is_pow2, __pyx_k_init___locals_is_pow2, sizeof(__pyx_k_init___locals_is_pow2), 0, 0, 1, 1},
  {&__pyx_n_s_insert_cells, __pyx_k_insert_cells, sizeof(__pyx_k_insert_cells), 0, 0, 1, 1},
  {&__pyx_n_s_int32, __pyx_k_int32, sizeof(__pyx_k_int32), 0, 0, 1, 1},
  {&__pyx_n_s_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1},
  {&__pyx_n_s_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 0, 1, 1},
  {&__pyx_n_s_is_pow2, __pyx_k_is_pow2, sizeof(__pyx_k_is_pow2), 0, 0, 1, 1},
  {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1},
  {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0},
  {&__pyx_kp_u_length_of_cell_width_vectors_mus, __pyx_k_length_of_cell_width_vectors_mus, sizeof(__pyx_k_length_of_cell_width_vectors_mus), 0, 1, 0, 0},
  {&__pyx_kp_u_level_length_must_match_the_poin, __pyx_k_level_length_must_match_the_poin, sizeof(__pyx_k_level_length_must_match_the_poin), 0, 1, 0, 0},
  {&__pyx_n_s_levels, __pyx_k_levels, sizeof(__pyx_k_levels), 0, 0, 1, 1},
  {&__pyx_n_s_lexsort, __pyx_k_lexsort, sizeof(__pyx_k_lexsort), 0, 0, 1, 1},
  {&__pyx_kp_u_line_nodes_array_must_be_N, __pyx_k_line_nodes_array_must_be_N, sizeof(__pyx_k_line_nodes_array_must_be_N), 0, 1, 0, 0},
  {&__pyx_n_s_locs, __pyx_k_locs, sizeof(__pyx_k_locs), 0, 0, 1, 1},
  {&__pyx_n_s_log2, __pyx_k_log2, sizeof(__pyx_k_log2), 0, 0, 1, 1},
  {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_matmul, __pyx_k_matmul, sizeof(__pyx_k_matmul), 0, 0, 1, 1},
  {&__pyx_n_s_max_level, __pyx_k_max_level, sizeof(__pyx_k_max_level), 0, 0, 1, 1},
  {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1},
  {&__pyx_n_s_meshin, __pyx_k_meshin, sizeof(__pyx_k_meshin), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_n_cells, __pyx_k_n_cells, sizeof(__pyx_k_n_cells), 0, 0, 1, 1},
  {&__pyx_n_s_n_edges, __pyx_k_n_edges, sizeof(__pyx_k_n_edges), 0, 0, 1, 1},
  {&__pyx_n_s_n_edges_x, __pyx_k_n_edges_x, sizeof(__pyx_k_n_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_edges_y, __pyx_k_n_edges_y, sizeof(__pyx_k_n_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_edges_z, __pyx_k_n_edges_z, sizeof(__pyx_k_n_edges_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_faces, __pyx_k_n_faces, sizeof(__pyx_k_n_faces), 0, 0, 1, 1},
  {&__pyx_n_s_n_faces_x, __pyx_k_n_faces_x, sizeof(__pyx_k_n_faces_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_faces_y, __pyx_k_n_faces_y, sizeof(__pyx_k_n_faces_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_faces_z, __pyx_k_n_faces_z, sizeof(__pyx_k_n_faces_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_edges, __pyx_k_n_hanging_edges, sizeof(__pyx_k_n_hanging_edges), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_edges_x, __pyx_k_n_hanging_edges_x, sizeof(__pyx_k_n_hanging_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_edges_y, __pyx_k_n_hanging_edges_y, sizeof(__pyx_k_n_hanging_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_edges_z, __pyx_k_n_hanging_edges_z, sizeof(__pyx_k_n_hanging_edges_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_faces, __pyx_k_n_hanging_faces, sizeof(__pyx_k_n_hanging_faces), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_faces_x, __pyx_k_n_hanging_faces_x, sizeof(__pyx_k_n_hanging_faces_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_faces_y, __pyx_k_n_hanging_faces_y, sizeof(__pyx_k_n_hanging_faces_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_faces_z, __pyx_k_n_hanging_faces_z, sizeof(__pyx_k_n_hanging_faces_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_hanging_nodes, __pyx_k_n_hanging_nodes, sizeof(__pyx_k_n_hanging_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_n_nodes, __pyx_k_n_nodes, sizeof(__pyx_k_n_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_edges, __pyx_k_n_total_edges, sizeof(__pyx_k_n_total_edges), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_edges_x, __pyx_k_n_total_edges_x, sizeof(__pyx_k_n_total_edges_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_edges_y, __pyx_k_n_total_edges_y, sizeof(__pyx_k_n_total_edges_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_edges_z, __pyx_k_n_total_edges_z, sizeof(__pyx_k_n_total_edges_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_faces, __pyx_k_n_total_faces, sizeof(__pyx_k_n_total_faces), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_faces_x, __pyx_k_n_total_faces_x, sizeof(__pyx_k_n_total_faces_x), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_faces_y, __pyx_k_n_total_faces_y, sizeof(__pyx_k_n_total_faces_y), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_faces_z, __pyx_k_n_total_faces_z, sizeof(__pyx_k_n_total_faces_z), 0, 0, 1, 1},
  {&__pyx_n_s_n_total_nodes, __pyx_k_n_total_nodes, sizeof(__pyx_k_n_total_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1},
  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
  {&__pyx_n_s_nodes, __pyx_k_nodes, sizeof(__pyx_k_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_nodes_x, __pyx_k_nodes_x, sizeof(__pyx_k_nodes_x), 0, 0, 1, 1},
  {&__pyx_n_s_nodes_y, __pyx_k_nodes_y, sizeof(__pyx_k_nodes_y), 0, 0, 1, 1},
  {&__pyx_n_s_nodes_z, __pyx_k_nodes_z, sizeof(__pyx_k_nodes_z), 0, 0, 1, 1},
  {&__pyx_n_s_nonzero, __pyx_k_nonzero, sizeof(__pyx_k_nonzero), 0, 0, 1, 1},
  {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
  {&__pyx_n_s_num, __pyx_k_num, sizeof(__pyx_k_num), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_kp_u_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 1, 0, 0},
  {&__pyx_kp_u_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 1, 0, 0},
  {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1},
  {&__pyx_n_s_ones, __pyx_k_ones, sizeof(__pyx_k_ones), 0, 0, 1, 1},
  {&__pyx_n_s_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 0, 1, 1},
  {&__pyx_n_s_origin, __pyx_k_origin, sizeof(__pyx_k_origin), 0, 0, 1, 1},
  {&__pyx_kp_u_origin_must_be_a_list_tuple_or_n, __pyx_k_origin_must_be_a_list_tuple_or_n, sizeof(__pyx_k_origin_must_be_a_list_tuple_or_n), 0, 1, 0, 0},
  {&__pyx_n_s_out_tens_mesh, __pyx_k_out_tens_mesh, sizeof(__pyx_k_out_tens_mesh), 0, 0, 1, 1},
  {&__pyx_n_s_output, __pyx_k_output, sizeof(__pyx_k_output), 0, 0, 1, 1},
  {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1},
  {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
  {&__pyx_n_s_points, __pyx_k_points, sizeof(__pyx_k_points), 0, 0, 1, 1},
  {&__pyx_kp_u_points_array_must_be_N, __pyx_k_points_array_must_be_N, sizeof(__pyx_k_points_array_must_be_N), 0, 1, 0, 0},
  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_radii, __pyx_k_radii, sizeof(__pyx_k_radii), 0, 0, 1, 1},
  {&__pyx_kp_u_radii_length_must_match_the_poin, __pyx_k_radii_length_must_match_the_poin, sizeof(__pyx_k_radii_length_must_match_the_poin), 0, 1, 0, 0},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
  {&__pyx_n_s_refine_locals_lambda, __pyx_k_refine_locals_lambda, sizeof(__pyx_k_refine_locals_lambda), 0, 0, 1, 1},
  {&__pyx_n_s_refine_triangle, __pyx_k_refine_triangle, sizeof(__pyx_k_refine_triangle), 0, 0, 1, 1},
  {&__pyx_kp_u_refine_vertical_trianglular_pris, __pyx_k_refine_vertical_trianglular_pris, sizeof(__pyx_k_refine_vertical_trianglular_pris), 0, 1, 0, 0},
  {&__pyx_n_s_require, __pyx_k_require, sizeof(__pyx_k_require), 0, 0, 1, 1},
  {&__pyx_n_s_requirements, __pyx_k_requirements, sizeof(__pyx_k_requirements), 0, 0, 1, 1},
  {&__pyx_n_s_reshape, __pyx_k_reshape, sizeof(__pyx_k_reshape), 0, 0, 1, 1},
  {&__pyx_n_s_rmatmul, __pyx_k_rmatmul, sizeof(__pyx_k_rmatmul), 0, 0, 1, 1},
  {&__pyx_n_s_scipy_sparse, __pyx_k_scipy_sparse, sizeof(__pyx_k_scipy_sparse), 0, 0, 1, 1},
  {&__pyx_kp_s_self__cell_cannot_be_converted_t, __pyx_k_self__cell_cannot_be_converted_t, sizeof(__pyx_k_self__cell_cannot_be_converted_t), 0, 0, 1, 0},
  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_shape_cells, __pyx_k_shape_cells, sizeof(__pyx_k_shape_cells), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_sp, __pyx_k_sp, sizeof(__pyx_k_sp), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_stencil_cell_gradient_x, __pyx_k_stencil_cell_gradient_x, sizeof(__pyx_k_stencil_cell_gradient_x), 0, 0, 1, 1},
  {&__pyx_n_u_stencil_cell_gradient_x, __pyx_k_stencil_cell_gradient_x, sizeof(__pyx_k_stencil_cell_gradient_x), 0, 1, 0, 1},
  {&__pyx_n_s_stencil_cell_gradient_y, __pyx_k_stencil_cell_gradient_y, sizeof(__pyx_k_stencil_cell_gradient_y), 0, 0, 1, 1},
  {&__pyx_n_u_stencil_cell_gradient_y, __pyx_k_stencil_cell_gradient_y, sizeof(__pyx_k_stencil_cell_gradient_y), 0, 1, 0, 1},
  {&__pyx_n_s_stencil_cell_gradient_z, __pyx_k_stencil_cell_gradient_z, sizeof(__pyx_k_stencil_cell_gradient_z), 0, 0, 1, 1},
  {&__pyx_n_u_stencil_cell_gradient_z, __pyx_k_stencil_cell_gradient_z, sizeof(__pyx_k_stencil_cell_gradient_z), 0, 1, 0, 1},
  {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1},
  {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
  {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0},
  {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0},
  {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0},
  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
  {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_tetra, __pyx_k_tetra, sizeof(__pyx_k_tetra), 0, 0, 1, 1},
  {&__pyx_kp_u_tetra_array_must_be_N, __pyx_k_tetra_array_must_be_N, sizeof(__pyx_k_tetra_array_must_be_N), 0, 1, 0, 0},
  {&__pyx_n_s_tocsr, __pyx_k_tocsr, sizeof(__pyx_k_tocsr), 0, 0, 1, 1},
  {&__pyx_n_s_triangle, __pyx_k_triangle, sizeof(__pyx_k_triangle), 0, 0, 1, 1},
  {&__pyx_kp_u_triangle_array_must_be_N_3, __pyx_k_triangle_array_must_be_N_3, sizeof(__pyx_k_triangle_array_must_be_N_3), 0, 1, 0, 0},
  {&__pyx_n_s_ubc_indArr, __pyx_k_ubc_indArr, sizeof(__pyx_k_ubc_indArr), 0, 0, 1, 1},
  {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0},
  {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_n_s_vstack, __pyx_k_vstack, sizeof(__pyx_k_vstack), 0, 0, 1, 1},
  {&__pyx_n_s_where, __pyx_k_where, sizeof(__pyx_k_where), 0, 0, 1, 1},
  {&__pyx_n_u_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 1, 0, 1},
  {&__pyx_n_s_x0, __pyx_k_x0, sizeof(__pyx_k_x0), 0, 0, 1, 1},
  {&__pyx_n_s_x0s, __pyx_k_x0s, sizeof(__pyx_k_x0s), 0, 0, 1, 1},
  {&__pyx_kp_u_x0s_and_x1s_must_have_the_same_l, __pyx_k_x0s_and_x1s_must_have_the_same_l, sizeof(__pyx_k_x0s_and_x1s_must_have_the_same_l), 0, 1, 0, 0},
  {&__pyx_kp_u_x0s_array_must_be_N, __pyx_k_x0s_array_must_be_N, sizeof(__pyx_k_x0s_array_must_be_N), 0, 1, 0, 0},
  {&__pyx_n_s_x1, __pyx_k_x1, sizeof(__pyx_k_x1), 0, 0, 1, 1},
  {&__pyx_n_s_x1s, __pyx_k_x1s, sizeof(__pyx_k_x1s), 0, 0, 1, 1},
  {&__pyx_kp_u_x1s_array_must_be_N, __pyx_k_x1s_array_must_be_N, sizeof(__pyx_k_x1s_array_must_be_N), 0, 1, 0, 0},
  {&__pyx_n_s_xEdge, __pyx_k_xEdge, sizeof(__pyx_k_xEdge), 0, 0, 1, 1},
  {&__pyx_n_s_xFace, __pyx_k_xFace, sizeof(__pyx_k_xFace), 0, 0, 1, 1},
  {&__pyx_n_u_xd, __pyx_k_xd, sizeof(__pyx_k_xd), 0, 1, 0, 1},
  {&__pyx_n_u_xu, __pyx_k_xu, sizeof(__pyx_k_xu), 0, 1, 0, 1},
  {&__pyx_n_u_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 1, 0, 1},
  {&__pyx_n_s_yEdge, __pyx_k_yEdge, sizeof(__pyx_k_yEdge), 0, 0, 1, 1},
  {&__pyx_n_s_yFace, __pyx_k_yFace, sizeof(__pyx_k_yFace), 0, 0, 1, 1},
  {&__pyx_n_u_yd, __pyx_k_yd, sizeof(__pyx_k_yd), 0, 1, 0, 1},
  {&__pyx_n_u_yu, __pyx_k_yu, sizeof(__pyx_k_yu), 0, 1, 0, 1},
  {&__pyx_n_u_z, __pyx_k_z, sizeof(__pyx_k_z), 0, 1, 0, 1},
  {&__pyx_n_s_zEdge, __pyx_k_zEdge, sizeof(__pyx_k_zEdge), 0, 0, 1, 1},
  {&__pyx_n_s_zFace, __pyx_k_zFace, sizeof(__pyx_k_zFace), 0, 0, 1, 1},
  {&__pyx_n_u_zd, __pyx_k_zd, sizeof(__pyx_k_zd), 0, 1, 0, 1},
  {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
  {&__pyx_n_s_zeros_outside, __pyx_k_zeros_outside, sizeof(__pyx_k_zeros_outside), 0, 0, 1, 1},
  {&__pyx_n_u_zu, __pyx_k_zu, sizeof(__pyx_k_zu), 0, 1, 0, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 240, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error)
  __pyx_builtin_super = __Pyx_GetBuiltinName(__pyx_n_s_super); if (!__pyx_builtin_super) __PYX_ERR(0, 343, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 348, __pyx_L1_error)
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 895, __pyx_L1_error)
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 6074, __pyx_L1_error)
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 944, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(1, 149, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(1, 152, __pyx_L1_error)
  __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(1, 406, __pyx_L1_error)
  __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(1, 615, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_self__cell_cannot_be_converted_t); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "(tree fragment)":4
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self._cell cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_self__cell_cannot_be_converted_t); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "discretize/_extensions/tree_ext.pyx":344
 *     def __init__(self, h, origin, bool diagonal_balance=False):
 *         super().__init__(h=h, origin=origin)
 *         def is_pow2(num):             # <<<<<<<<<<<<<<
 *             return ((num & (num - 1)) == 0) and num != 0
 *         for n in self.shape_cells:
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_num); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);
  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 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_discretize__extensions_tree_ext, __pyx_n_s_is_pow2, 344, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 344, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":348
 *         for n in self.shape_cells:
 *             if not is_pow2(n):
 *                 raise ValueError("length of cell width vectors must be a power of 2")             # <<<<<<<<<<<<<<
 *         h = self.h
 *         origin = self.origin
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_length_of_cell_width_vectors_mus); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "discretize/_extensions/tree_ext.pyx":358
 * 
 *         xs = np.empty(nx2 + 1, dtype=float)
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])             # <<<<<<<<<<<<<<
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2
 *         self._xs = xs
 */
  __pyx_slice__6 = PySlice_New(Py_None, Py_None, __pyx_int_2); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 358, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__6);
  __Pyx_GIVEREF(__pyx_slice__6);

  /* "discretize/_extensions/tree_ext.pyx":359
 *         xs = np.empty(nx2 + 1, dtype=float)
 *         xs[::2] = np.cumsum(np.r_[origin[0], h[0]])
 *         xs[1::2] = (xs[:-1:2] + xs[2::2])/2             # <<<<<<<<<<<<<<
 *         self._xs = xs
 *         self.ls[0] = int(np.log2(len(h[0])))
 */
  __pyx_slice__7 = PySlice_New(Py_None, __pyx_int_neg_1, __pyx_int_2); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__7);
  __Pyx_GIVEREF(__pyx_slice__7);
  __pyx_slice__8 = PySlice_New(__pyx_int_2, Py_None, __pyx_int_2); if (unlikely(!__pyx_slice__8)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__8);
  __Pyx_GIVEREF(__pyx_slice__8);
  __pyx_slice__9 = PySlice_New(__pyx_int_1, Py_None, __pyx_int_2); if (unlikely(!__pyx_slice__9)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__9);
  __Pyx_GIVEREF(__pyx_slice__9);

  /* "discretize/_extensions/tree_ext.pyx":378
 *             self.ls[2] = int(np.log2(len(h[2])))
 *         else:
 *             self._zs = np.zeros(1, dtype=float)             # <<<<<<<<<<<<<<
 *             self.ls[2] = 1
 * 
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "discretize/_extensions/tree_ext.pyx":575
 *         cdef double[:] rs = radii
 *         if points.shape[0] != rs.shape[0]:
 *             raise ValueError("radii length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 * 
 *         levels = np.require(np.atleast_1d(levels), dtype=np.int32,
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_u_radii_length_must_match_the_poin); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 575, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "discretize/_extensions/tree_ext.pyx":583
 *         cdef int[:] ls = levels
 *         if points.shape[0] != ls.shape[0]:
 *             raise ValueError("level length must match the points array's first dimension")             # <<<<<<<<<<<<<<
 * 
 *         if diagonal_balance is None:
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_u_level_length_must_match_the_poin); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "discretize/_extensions/tree_ext.pyx":660
 *             raise ValueError(f"x1s array must be (N, {self.dim})")
 *         if x1s.shape[0] != x0s.shape[0]:
 *             raise ValueError(f"x0s and x1s must have the same length")             # <<<<<<<<<<<<<<
 *         cdef double[:, :] x0 = x0s
 *         cdef double[:, :] x1 = x1s
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_u_x0s_and_x1s_must_have_the_same_l); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "discretize/_extensions/tree_ext.pyx":810
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:
 *             triangle = triangle[None, ...]             # <<<<<<<<<<<<<<
 *         if triangle.shape[-1] != self.dim or triangle.shape[-2] != 3:
 *             raise ValueError(f"triangle array must be (N, 3, {self.dim})")
 */
  __pyx_tuple__15 = PyTuple_Pack(2, Py_None, Py_Ellipsis); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "discretize/_extensions/tree_ext.pyx":895
 *         """
 *         if self.dim == 2:
 *             raise NotImplementedError("refine_vertical_trianglular_prism only implemented in 3D.")             # <<<<<<<<<<<<<<
 *         triangle = np.require(np.atleast_2d(triangle), dtype=np.float64, requirements="C")
 *         if triangle.ndim == 2:
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_refine_vertical_trianglular_pris); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 895, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "discretize/_extensions/tree_ext.pyx":916
 *             raise ValueError(f"inconsistent number of triangles {n_triangles} and heights {h.shape[0]}")
 *         if np.any(h < 0):
 *             raise ValueError("All heights must be positive.")             # <<<<<<<<<<<<<<
 * 
 *         cdef int[:] ls = levels
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_u_All_heights_must_be_positive); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 916, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "discretize/_extensions/tree_ext.pyx":1111
 *     def _set_origin(self, origin):
 *         if not isinstance(origin, (list, tuple, np.ndarray)):
 *             raise ValueError('origin must be a list, tuple or numpy array')             # <<<<<<<<<<<<<<
 *         self._origin = np.asarray(origin, dtype=np.float64)
 *         cdef int_t dim = self._origin.shape[0]
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_origin_must_be_a_list_tuple_or_n); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 1111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "discretize/_extensions/tree_ext.pyx":1718
 *         y0, yF = self._ys[0], self._ys[-1]
 *         is_boundary = (
 *             (nodes[:, 0] == x0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)
 */
  __pyx_slice__20 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__20)) __PYX_ERR(0, 1718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_slice__20, __pyx_int_0); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 1718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "discretize/_extensions/tree_ext.pyx":1720
 *             (nodes[:, 0] == x0)
 *             | (nodes[:, 0] == xF)
 *             | (nodes[:, 1] == y0)             # <<<<<<<<<<<<<<
 *             | (nodes[:, 1] == yF)
 *         )
 */
  __pyx_tuple__22 = PyTuple_Pack(2, __pyx_slice__20, __pyx_int_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 1720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "discretize/_extensions/tree_ext.pyx":1726
 *             z0, zF = self._zs[0], self._zs[-1]
 *             is_boundary |= (
 *                 (nodes[:, 2] == z0)             # <<<<<<<<<<<<<<
 *                 | (nodes[:, 2] == zF)
 *             )
 */
  __pyx_tuple__23 = PyTuple_Pack(2, __pyx_slice__20, __pyx_int_2); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 1726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "discretize/_extensions/tree_ext.pyx":2679
 *             cell_indexes.push_back(cur_cell.index)
 *             if cur_cell.index == -1:
 *                 raise Exception('Path not found')             # <<<<<<<<<<<<<<
 *         return cell_indexes
 * 
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_Path_not_found); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 2679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "discretize/_extensions/tree_ext.pyx":3037
 *     def nodal_laplacian(self):
 *         """Not implemented on the TreeMesh."""
 *         raise NotImplementedError('Nodal Laplacian has not been implemented for TreeMesh')             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_Nodal_Laplacian_has_not_been_imp); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 3037, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "discretize/_extensions/tree_ext.pyx":3802
 *             return self._average_edge_z_to_cell
 *         if self._dim == 2:
 *             raise Exception('There are no z-edges in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_u_There_are_no_z_edges_in_2D); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 3802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "discretize/_extensions/tree_ext.pyx":4161
 *             return self._average_face_z_to_cell
 *         if self._dim == 2:
 *             raise Exception('There are no z-faces in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I,J
 *         cdef np.float64_t[:] V
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_u_There_are_no_z_faces_in_2D); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 4161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "discretize/_extensions/tree_ext.pyx":4418
 *         """
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z-edges in 2D')             # <<<<<<<<<<<<<<
 *         if self._average_node_to_edge_z is not None:
 *             return self._average_node_to_edge_z
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_u_TreeMesh_has_no_z_edges_in_2D); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 4418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "discretize/_extensions/tree_ext.pyx":4578
 *         """
 *         if self._dim == 2:
 *             raise Exception('TreeMesh has no z faces in 2D')             # <<<<<<<<<<<<<<
 *         cdef np.int64_t[:] I, J
 *         cdef np.float64_t[:] V
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_u_TreeMesh_has_no_z_faces_in_2D); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 4578, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "discretize/_extensions/tree_ext.pyx":5001
 *         """
 *         if self.dim == 2:
 *             raise Exception('TreeMesh has no z-faces in 2D')             # <<<<<<<<<<<<<<
 *         if self._average_cell_to_face_z is not None:
 *             return self._average_cell_to_face_z
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_u_TreeMesh_has_no_z_faces_in_2D_2); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 5001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "discretize/_extensions/tree_ext.pyx":5276
 * 
 *     def _getFacePxx(self):
 *         def Pxx(xFace, yFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, None)
 *         return Pxx
 */
  __pyx_tuple__31 = PyTuple_Pack(2, __pyx_n_s_xFace, __pyx_n_s_yFace); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 5276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);
  __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_discretize__extensions_tree_ext, __pyx_n_s_Pxx, 5276, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 5276, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":5281
 * 
 *     def _getFacePxxx(self):
 *         def Pxxx(xFace, yFace, zFace):             # <<<<<<<<<<<<<<
 *             return self._getFaceP(xFace, yFace, zFace)
 *         return Pxxx
 */
  __pyx_tuple__33 = PyTuple_Pack(3, __pyx_n_s_xFace, __pyx_n_s_yFace, __pyx_n_s_zFace); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 5281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);
  __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__33, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_discretize__extensions_tree_ext, __pyx_n_s_Pxxx, 5281, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 5281, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":5306
 *                 edges[2] = int(zEdge[-1]) #0, 1, 2, 3
 *         except ValueError:
 *             raise Exception('Last character of edge string must be 0, 1, 2, or 3')             # <<<<<<<<<<<<<<
 * 
 *         offsets[0] = 0
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_u_Last_character_of_edge_string_mu); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 5306, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "discretize/_extensions/tree_ext.pyx":5332
 * 
 *     def _getEdgePxx(self):
 *         def Pxx(xEdge, yEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, None)
 *         return Pxx
 */
  __pyx_tuple__36 = PyTuple_Pack(2, __pyx_n_s_xEdge, __pyx_n_s_yEdge); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 5332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);
  __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_discretize__extensions_tree_ext, __pyx_n_s_Pxx, 5332, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 5332, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":5337
 * 
 *     def _getEdgePxxx(self):
 *         def Pxxx(xEdge, yEdge, zEdge):             # <<<<<<<<<<<<<<
 *             return self._getEdgeP(xEdge, yEdge, zEdge)
 *         return Pxxx
 */
  __pyx_tuple__38 = PyTuple_Pack(3, __pyx_n_s_xEdge, __pyx_n_s_yEdge, __pyx_n_s_zEdge); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 5337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);
  __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__38, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_discretize__extensions_tree_ext, __pyx_n_s_Pxxx, 5337, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 5337, __pyx_L1_error)

  /* "discretize/_extensions/tree_ext.pyx":5374
 *             offset = self.n_total_edges_x + self.n_total_edges_y
 *         else:
 *             raise ValueError('Invalid direction, must be x, y, or z')             # <<<<<<<<<<<<<<
 * 
 *         for i in range(n_loc):
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_u_Invalid_direction_must_be_x_y_or); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 5374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "discretize/_extensions/tree_ext.pyx":6081
 *             return pycell
 *         else:
 *             raise TypeError("Invalid argument type.")             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_u_Invalid_argument_type); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 6081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "discretize/_extensions/tree_ext.pyx":6094
 * 
 *         if self.dim == 2:
 *             indArr[:, -1] = (self._ys.shape[0]-1) - indArr[:, -1]             # <<<<<<<<<<<<<<
 *         else:
 *             indArr[:, -1] = (self._zs.shape[0]-1) - indArr[:, -1]
 */
  __pyx_tuple__42 = PyTuple_Pack(2, __pyx_slice__20, __pyx_int_neg_1); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 6094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "discretize/_extensions/tree_ext.pyx":6098
 *             indArr[:, -1] = (self._zs.shape[0]-1) - indArr[:, -1]
 * 
 *         indArr = (indArr - levels[:, None])//2             # <<<<<<<<<<<<<<
 *         indArr += 1
 * 
 */
  __pyx_tuple__43 = PyTuple_Pack(2, __pyx_slice__20, Py_None); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 6098, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "discretize/_extensions/tree_ext.pyx":6438
 * 
 *         if not build_mat:
 *             return output.reshape(-1, order='F')             # <<<<<<<<<<<<<<
 *         return sp.csr_matrix((all_weights, row_inds, indptr), shape=(out_tens_mesh.n_cells, self.n_cells))
 * 
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_int_neg_1); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 6438, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":944
 *         __pyx_import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(2, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":950
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(2, 950, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "View.MemoryView":134
 * 
 *         if not self.ndim:
 *             raise ValueError("Empty shape tuple for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if itemsize <= 0:
 */
  __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(1, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "View.MemoryView":137
 * 
 *         if itemsize <= 0:
 *             raise ValueError("itemsize <= 0 for cython.array")             # <<<<<<<<<<<<<<
 * 
 *         if not isinstance(format, bytes):
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(1, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "View.MemoryView":149
 * 
 *         if not self._shape:
 *             raise MemoryError("unable to allocate shape and strides.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(1, 149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "View.MemoryView":177
 *             self.data = <char *>malloc(self.len)
 *             if not self.data:
 *                 raise MemoryError("unable to allocate array data.")             # <<<<<<<<<<<<<<
 * 
 *             if self.dtype_is_object:
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(1, 177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "View.MemoryView":193
 *             bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
 *         if not (flags & bufmode):
 *             raise ValueError("Can only create a buffer that is contiguous in memory.")             # <<<<<<<<<<<<<<
 *         info.buf = self.data
 *         info.len = self.len
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(1, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "View.MemoryView":420
 *     def __setitem__(memoryview self, object index, object value):
 *         if self.view.readonly:
 *             raise TypeError("Cannot assign to read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         have_slices, index = _unellipsify(index, self.view.ndim)
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(1, 420, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "View.MemoryView":497
 *             result = struct.unpack(self.view.format, bytesitem)
 *         except struct.error:
 *             raise ValueError("Unable to convert item to object")             # <<<<<<<<<<<<<<
 *         else:
 *             if len(self.view.format) == 1:
 */
  __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(1, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);

  /* "View.MemoryView":522
 *     def __getbuffer__(self, Py_buffer *info, int flags):
 *         if flags & PyBUF_WRITABLE and self.view.readonly:
 *             raise ValueError("Cannot create writable memory view from read-only memoryview")             # <<<<<<<<<<<<<<
 * 
 *         if flags & PyBUF_ND:
 */
  __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(1, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "View.MemoryView":572
 *         if self.view.strides == NULL:
 * 
 *             raise ValueError("Buffer view does not expose strides")             # <<<<<<<<<<<<<<
 * 
 *         return tuple([stride for stride in self.view.strides[:self.view.ndim]])
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "View.MemoryView":705
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 *             raise ValueError("Indirect dimensions not supported")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 705, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);
  __pyx_tuple__66 = PyTuple_Pack(3, __pyx_int_184977713, __pyx_int_136983863, __pyx_int_112105877); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);

  /* "View.MemoryView":287
 *         return self.name
 * 
 * cdef generic = Enum("<strided and direct or indirect>")             # <<<<<<<<<<<<<<
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")
 */
  __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 287, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);

  /* "View.MemoryView":288
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default             # <<<<<<<<<<<<<<
 * cdef indirect = Enum("<strided and indirect>")
 * 
 */
  __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(1, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);

  /* "View.MemoryView":289
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(1, 289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__70);
  __Pyx_GIVEREF(__pyx_tuple__70);

  /* "View.MemoryView":292
 * 
 * 
 * cdef contiguous = Enum("<contiguous and direct>")             # <<<<<<<<<<<<<<
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")
 * 
 */
  __pyx_tuple__71 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(1, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);

  /* "View.MemoryView":293
 * 
 * cdef contiguous = Enum("<contiguous and direct>")
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(1, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__72);
  __Pyx_GIVEREF(__pyx_tuple__72);

  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_tuple__73 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);
  __pyx_codeobj__65 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__65)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_0 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_float_0_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1_0 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_float_1_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_0_25 = PyFloat_FromDouble(0.25); if (unlikely(!__pyx_float_0_25)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_112105877 = PyInt_FromLong(112105877L); if (unlikely(!__pyx_int_112105877)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_136983863 = PyInt_FromLong(136983863L); if (unlikely(!__pyx_int_136983863)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  generic = Py_None; Py_INCREF(Py_None);
  strided = Py_None; Py_INCREF(Py_None);
  indirect = Py_None; Py_INCREF(Py_None);
  contiguous = Py_None; Py_INCREF(Py_None);
  indirect_contiguous = Py_None; Py_INCREF(Py_None);
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __pyx_vtabptr_10discretize_11_extensions_8tree_ext_TreeCell = &__pyx_vtable_10discretize_11_extensions_8tree_ext_TreeCell;
  __pyx_vtable_10discretize_11_extensions_8tree_ext_TreeCell._set = (void (*)(struct __pyx_obj_10discretize_11_extensions_8tree_ext_TreeCell *, Cell *))__pyx_f_10discretize_11_extensions_8tree_ext_8TreeCell__set;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext_TreeCell.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext_TreeCell.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext_TreeCell.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell.tp_dict, __pyx_vtabptr_10discretize_11_extensions_8tree_ext_TreeCell) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_TreeCell, (PyObject *)&__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __pyx_ptype_10discretize_11_extensions_8tree_ext_TreeCell = &__pyx_type_10discretize_11_extensions_8tree_ext_TreeCell;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh) < 0) __PYX_ERR(0, 311, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #if CYTHON_UPDATE_DESCRIPTOR_DOC
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh, "__getitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 311, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__.doc = __pyx_doc_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_10discretize_11_extensions_8tree_ext_9_TreeMesh_92__getitem__;
    }
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_TreeMesh, (PyObject *)&__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh) < 0) __PYX_ERR(0, 311, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh) < 0) __PYX_ERR(0, 311, __pyx_L1_error)
  __pyx_ptype_10discretize_11_extensions_8tree_ext__TreeMesh = &__pyx_type_10discretize_11_extensions_8tree_ext__TreeMesh;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine) < 0) __PYX_ERR(0, 448, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine = &__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct__refine;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx) < 0) __PYX_ERR(0, 5275, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx = &__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_1__getFacePxx;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx) < 0) __PYX_ERR(0, 5280, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx = &__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_2__getFacePxxx;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx) < 0) __PYX_ERR(0, 5331, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx = &__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_3__getEdgePxx;
  if (PyType_Ready(&__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx) < 0) __PYX_ERR(0, 5336, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx.tp_dictoffset && __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx = &__pyx_type_10discretize_11_extensions_8tree_ext___pyx_scope_struct_4__getEdgePxxx;
  __pyx_vtabptr_array = &__pyx_vtable_array;
  __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview;
  if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 106, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_array.tp_print = 0;
  #endif
  if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(1, 106, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 106, __pyx_L1_error)
  __pyx_array_type = &__pyx_type___pyx_array;
  if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 280, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_MemviewEnum.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 280, __pyx_L1_error)
  __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum;
  __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview;
  __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer;
  __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice;
  __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment;
  __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar;
  __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed;
  __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object;
  __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object;
  if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 331, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_memoryview.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(1, 331, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 331, __pyx_L1_error)
  __pyx_memoryview_type = &__pyx_type___pyx_memoryview;
  __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice;
  __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview;
  __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object;
  __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object;
  __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type;
  if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 967, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type___pyx_memoryviewslice.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(1, 967, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 967, __pyx_L1_error)
  __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType_0_29_35(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyHeapTypeObject),
  #endif
  __Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("numpy"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 199, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "dtype", sizeof(PyArray_Descr), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyArray_Descr),__Pyx_ImportType_CheckSize_Ignore_0_29_35); if (!__pyx_ptype_5numpy_dtype) __PYX_ERR(2, 199, __pyx_L1_error)
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "flatiter", sizeof(PyArrayIterObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyArrayIterObject),__Pyx_ImportType_CheckSize_Ignore_0_29_35); if (!__pyx_ptype_5numpy_flatiter) __PYX_ERR(2, 222, __pyx_L1_error)
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "broadcast", sizeof(PyArrayMultiIterObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyArrayMultiIterObject),__Pyx_ImportType_CheckSize_Ignore_0_29_35); if (!__pyx_ptype_5numpy_broadcast) __PYX_ERR(2, 226, __pyx_L1_error)
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "ndarray", sizeof(PyArrayObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyArrayObject),__Pyx_ImportType_CheckSize_Ignore_0_29_35); if (!__pyx_ptype_5numpy_ndarray) __PYX_ERR(2, 238, __pyx_L1_error)
  __pyx_ptype_5numpy_generic = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "generic", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_generic) __PYX_ERR(2, 770, __pyx_L1_error)
  __pyx_ptype_5numpy_number = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "number", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_number) __PYX_ERR(2, 772, __pyx_L1_error)
  __pyx_ptype_5numpy_integer = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "integer", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_integer) __PYX_ERR(2, 774, __pyx_L1_error)
  __pyx_ptype_5numpy_signedinteger = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "signedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_signedinteger) __PYX_ERR(2, 776, __pyx_L1_error)
  __pyx_ptype_5numpy_unsignedinteger = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "unsignedinteger", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_unsignedinteger) __PYX_ERR(2, 778, __pyx_L1_error)
  __pyx_ptype_5numpy_inexact = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "inexact", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_inexact) __PYX_ERR(2, 780, __pyx_L1_error)
  __pyx_ptype_5numpy_floating = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "floating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_floating) __PYX_ERR(2, 782, __pyx_L1_error)
  __pyx_ptype_5numpy_complexfloating = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "complexfloating", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_complexfloating) __PYX_ERR(2, 784, __pyx_L1_error)
  __pyx_ptype_5numpy_flexible = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "flexible", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_flexible) __PYX_ERR(2, 786, __pyx_L1_error)
  __pyx_ptype_5numpy_character = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "character", sizeof(PyObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyObject),__Pyx_ImportType_CheckSize_Warn_0_29_35); if (!__pyx_ptype_5numpy_character) __PYX_ERR(2, 788, __pyx_L1_error)
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType_0_29_35(__pyx_t_1, "numpy", "ufunc", sizeof(PyUFuncObject), __PYX_GET_STRUCT_ALIGNMENT_0_29_35(PyUFuncObject),__Pyx_ImportType_CheckSize_Ignore_0_29_35); if (!__pyx_ptype_5numpy_ufunc) __PYX_ERR(2, 826, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("discretize._extensions.interputils_cython"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction_0_29_35(__pyx_t_1, "_bisect_left", (void (**)(void))&__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_left, "__pyx_t_5numpy_int64_t (__Pyx_memviewslice, __pyx_t_5numpy_float64_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_0_29_35(__pyx_t_1, "_bisect_right", (void (**)(void))&__pyx_f_10discretize_11_extensions_18interputils_cython__bisect_right, "__pyx_t_5numpy_int64_t (__Pyx_memviewslice, __pyx_t_5numpy_float64_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC inittree_ext(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC inittree_ext(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_tree_ext(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_tree_ext(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_tree_ext(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  __Pyx_TraceDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  static PyThread_type_lock __pyx_t_3[8];
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'tree_ext' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_tree_ext(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("tree_ext", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_discretize___extensions__tree_ext) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "discretize._extensions.tree_ext")) {
      if (unlikely(PyDict_SetItemString(modules, "discretize._extensions.tree_ext", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_variable_import_code();
  if (unlikely(__Pyx_modinit_function_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_tree_ext(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error));

  /* "discretize/_extensions/tree_ext.pyx":13
 * from .tree cimport int_t, Tree as c_Tree, PyWrapper, Node, Edge, Face, Cell as c_Cell
 * 
 * import scipy.sparse as sp             # <<<<<<<<<<<<<<
 * import numpy as np
 * from .interputils_cython cimport _bisect_left, _bisect_right
 */
  __Pyx_TraceLine(13,0,__PYX_ERR(0, 13, __pyx_L1_error))
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s__67);
  __Pyx_GIVEREF(__pyx_n_s__67);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s__67);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_sparse, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sp, __pyx_t_2) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":14
 * 
 * import scipy.sparse as sp
 * import numpy as np             # <<<<<<<<<<<<<<
 * from .interputils_cython cimport _bisect_left, _bisect_right
 * 
 */
  __Pyx_TraceLine(14,0,__PYX_ERR(0, 14, __pyx_L1_error))
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discretize/_extensions/tree_ext.pyx":54
 *     cdef int_t _dim
 *     cdef c_Cell* _cell
 *     cdef void _set(self, c_Cell* cell):             # <<<<<<<<<<<<<<
 *         self._cell = cell
 *         self._dim = cell.n_dim
 */
  __Pyx_TraceLine(54,0,__PYX_ERR(0, 54, __pyx_L1_error))


  /* "discretize/_extensions/tree_ext.pyx":303
 *         return self._cell.level
 * 
 * cdef int _evaluate_func(void* function, c_Cell* cell) with gil:             # <<<<<<<<<<<<<<
 *     # Wraps a function to be called in C++
 *     func = <object> function
 */
  __Pyx_TraceLine(303,0,__PYX_ERR(0, 303, __pyx_L1_error))


  /* "discretize/_extensions/tree_ext.pyx":6649
 * 
 * 
 * cdef inline double _clip01(double x) nogil:             # <<<<<<<<<<<<<<
 *     return min(1, max(x, 0))
 */
  __Pyx_TraceLine(6649,0,__PYX_ERR(0, 6649, __pyx_L1_error))


  /* "discretize/_extensions/tree_ext.pyx":1
 * # distutils: language=c++             # <<<<<<<<<<<<<<
 * # cython: embedsignature=True, language_level=3
 * # cython: linetrace=True
 */
  __Pyx_TraceLine(1,0,__PYX_ERR(0, 1, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyDict_NewPresized(10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_line_448, __pyx_kp_u_Refine_class_discretize_TreeMesh) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_ball_line_512, __pyx_kp_u_Refine_class_discretize_TreeMesh_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_box_line_601, __pyx_kp_u_Refine_the_class_discretize_Tree) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_line_line_686, __pyx_kp_u_Refine_the_class_discretize_Tree_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_triangle_line_7, __pyx_kp_u_Refine_the_class_discretize_Tree_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_vertical_triang, __pyx_kp_u_Refine_the_class_discretize_Tree_4) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_refine_tetrahedron_lin, __pyx_kp_u_Refine_the_class_discretize_Tree_5) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_insert_cells_line_1020, __pyx_kp_u_Insert_cells_into_the_class_disc) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_cell_boundary_indices, __pyx_kp_u_Returns_the_indices_of_the_x_y_a) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_kp_u_TreeMesh_face_boundary_indices, __pyx_kp_u_Returns_the_indices_of_the_x_y_a_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":734
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */
  __Pyx_TraceLine(734,0,__PYX_ERR(2, 734, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":737
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */
  __Pyx_TraceLine(737,0,__PYX_ERR(2, 737, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":740
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */
  __Pyx_TraceLine(740,0,__PYX_ERR(2, 740, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":743
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */
  __Pyx_TraceLine(743,0,__PYX_ERR(2, 743, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":746
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */
  __Pyx_TraceLine(746,0,__PYX_ERR(2, 746, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":749
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */
  __Pyx_TraceLine(749,0,__PYX_ERR(2, 749, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":928
 *     int _import_umath() except -1
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *     Py_INCREF(base) # important to do this before stealing the reference below!
 *     PyArray_SetBaseObject(arr, base)
 */
  __Pyx_TraceLine(928,0,__PYX_ERR(2, 928, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":932
 *     PyArray_SetBaseObject(arr, base)
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     base = PyArray_BASE(arr)
 *     if base is NULL:
 */
  __Pyx_TraceLine(932,0,__PYX_ERR(2, 932, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":940
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         __pyx_import_array()
 */
  __Pyx_TraceLine(940,0,__PYX_ERR(2, 940, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":946
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */
  __Pyx_TraceLine(946,0,__PYX_ERR(2, 946, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":952
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */
  __Pyx_TraceLine(952,0,__PYX_ERR(2, 952, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline bint is_timedelta64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.timedelta64)`
 */
  __Pyx_TraceLine(966,0,__PYX_ERR(2, 966, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":981
 * 
 * 
 * cdef inline bint is_datetime64_object(object obj):             # <<<<<<<<<<<<<<
 *     """
 *     Cython equivalent of `isinstance(obj, np.datetime64)`
 */
  __Pyx_TraceLine(981,0,__PYX_ERR(2, 981, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":996
 * 
 * 
 * cdef inline npy_datetime get_datetime64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy datetime64 object
 */
  __Pyx_TraceLine(996,0,__PYX_ERR(2, 996, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1006
 * 
 * 
 * cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the int64 value underlying scalar numpy timedelta64 object
 */
  __Pyx_TraceLine(1006,0,__PYX_ERR(2, 1006, __pyx_L1_error))


  /* "../../../conda/envs/discretize-test/lib/python3.10/site-packages/numpy/__init__.pxd":1013
 * 
 * 
 * cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     returns the unit part of the dtype for a numpy datetime64 object.
 */
  __Pyx_TraceLine(1013,0,__PYX_ERR(2, 1013, __pyx_L1_error))


  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_PY_LONG_LONG")
 * cdef object __pyx_convert_vector_to_py_PY_LONG_LONG(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */
  __Pyx_TraceLine(60,0,__PYX_ERR(1, 60, __pyx_L1_error))


  /* "vector.to_py":54
 * 
 * 
 * cdef extern from *:             # <<<<<<<<<<<<<<
 *     cdef cppclass vector "const std::vector" [T]:
 *         size_t size()
 */
  __Pyx_TraceLine(54,0,__PYX_ERR(1, 54, __pyx_L1_error))


  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_double")
 * cdef object __pyx_convert_vector_to_py_double(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */
  __Pyx_TraceLine(60,0,__PYX_ERR(1, 60, __pyx_L1_error))


  /* "View.MemoryView":210
 *         info.obj = self
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(array self):
 */
  __Pyx_TraceLine(210,0,__PYX_ERR(1, 210, __pyx_L1_error))
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(1, 210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_array_type);

  /* "View.MemoryView":227
 * 
 *     @cname('get_memview')
 *     cdef get_memview(self):             # <<<<<<<<<<<<<<
 *         flags =  PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
 *         return  memoryview(self, flags, self.dtype_is_object)
 */
  __Pyx_TraceLine(227,0,__PYX_ERR(1, 227, __pyx_L1_error))


  /* "View.MemoryView":245
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,             # <<<<<<<<<<<<<<
 *                           char *mode, char *buf):
 *     cdef array result
 */
  __Pyx_TraceLine(245,0,__PYX_ERR(1, 245, __pyx_L1_error))


  /* "View.MemoryView":287
 *         return self.name
 * 
 * cdef generic = Enum("<strided and direct or indirect>")             # <<<<<<<<<<<<<<
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")
 */
  __Pyx_TraceLine(287,0,__PYX_ERR(1, 287, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 287, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(generic);
  __Pyx_DECREF_SET(generic, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":288
 * 
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default             # <<<<<<<<<<<<<<
 * cdef indirect = Enum("<strided and indirect>")
 * 
 */
  __Pyx_TraceLine(288,0,__PYX_ERR(1, 288, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(strided);
  __Pyx_DECREF_SET(strided, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":289
 * cdef generic = Enum("<strided and direct or indirect>")
 * cdef strided = Enum("<strided and direct>") # default
 * cdef indirect = Enum("<strided and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(289,0,__PYX_ERR(1, 289, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(indirect);
  __Pyx_DECREF_SET(indirect, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":292
 * 
 * 
 * cdef contiguous = Enum("<contiguous and direct>")             # <<<<<<<<<<<<<<
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")
 * 
 */
  __Pyx_TraceLine(292,0,__PYX_ERR(1, 292, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 292, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(contiguous);
  __Pyx_DECREF_SET(contiguous, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":293
 * 
 * cdef contiguous = Enum("<contiguous and direct>")
 * cdef indirect_contiguous = Enum("<contiguous and indirect>")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(293,0,__PYX_ERR(1, 293, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XGOTREF(indirect_contiguous);
  __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "View.MemoryView":299
 * 
 * @cname('__pyx_align_pointer')
 * cdef void *align_pointer(void *memory, size_t alignment) nogil:             # <<<<<<<<<<<<<<
 *     "Align pointer memory on a given boundary"
 *     cdef Py_intptr_t aligned_p = <Py_intptr_t> memory
 */
  __Pyx_TraceLine(299,0,__PYX_ERR(1, 299, __pyx_L1_error))


  /* "View.MemoryView":317
 * 
 * DEF THREAD_LOCKS_PREALLOCATED = 8
 * cdef int __pyx_memoryview_thread_locks_used = 0             # <<<<<<<<<<<<<<
 * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [
 *     PyThread_allocate_lock(),
 */
  __Pyx_TraceLine(317,0,__PYX_ERR(1, 317, __pyx_L1_error))
  __pyx_memoryview_thread_locks_used = 0;

  /* "View.MemoryView":318
 * DEF THREAD_LOCKS_PREALLOCATED = 8
 * cdef int __pyx_memoryview_thread_locks_used = 0
 * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [             # <<<<<<<<<<<<<<
 *     PyThread_allocate_lock(),
 *     PyThread_allocate_lock(),
 */
  __Pyx_TraceLine(318,0,__PYX_ERR(1, 318, __pyx_L1_error))
  __pyx_t_3[0] = PyThread_allocate_lock();
  __pyx_t_3[1] = PyThread_allocate_lock();
  __pyx_t_3[2] = PyThread_allocate_lock();
  __pyx_t_3[3] = PyThread_allocate_lock();
  __pyx_t_3[4] = PyThread_allocate_lock();
  __pyx_t_3[5] = PyThread_allocate_lock();
  __pyx_t_3[6] = PyThread_allocate_lock();
  __pyx_t_3[7] = PyThread_allocate_lock();
  memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_3, sizeof(__pyx_memoryview_thread_locks[0]) * (8));

  /* "View.MemoryView":395
 *                 PyThread_free_lock(self.lock)
 * 
 *     cdef char *get_item_pointer(memoryview self, object index) except NULL:             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t dim
 *         cdef char *itemp = <char *> self.view.buf
 */
  __Pyx_TraceLine(395,0,__PYX_ERR(1, 395, __pyx_L1_error))


  /* "View.MemoryView":433
 *             self.setitem_indexed(index, value)
 * 
 *     cdef is_slice(self, obj):             # <<<<<<<<<<<<<<
 *         if not isinstance(obj, memoryview):
 *             try:
 */
  __Pyx_TraceLine(433,0,__PYX_ERR(1, 433, __pyx_L1_error))


  /* "View.MemoryView":443
 *         return obj
 * 
 *     cdef setitem_slice_assignment(self, dst, src):             # <<<<<<<<<<<<<<
 *         cdef __Pyx_memviewslice dst_slice
 *         cdef __Pyx_memviewslice src_slice
 */
  __Pyx_TraceLine(443,0,__PYX_ERR(1, 443, __pyx_L1_error))


  /* "View.MemoryView":451
 *                                  src.ndim, dst.ndim, self.dtype_is_object)
 * 
 *     cdef setitem_slice_assign_scalar(self, memoryview dst, value):             # <<<<<<<<<<<<<<
 *         cdef int array[128]
 *         cdef void *tmp = NULL
 */
  __Pyx_TraceLine(451,0,__PYX_ERR(1, 451, __pyx_L1_error))


  /* "View.MemoryView":483
 *             PyMem_Free(tmp)
 * 
 *     cdef setitem_indexed(self, index, value):             # <<<<<<<<<<<<<<
 *         cdef char *itemp = self.get_item_pointer(index)
 *         self.assign_item_from_object(itemp, value)
 */
  __Pyx_TraceLine(483,0,__PYX_ERR(1, 483, __pyx_L1_error))


  /* "View.MemoryView":487
 *         self.assign_item_from_object(itemp, value)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */
  __Pyx_TraceLine(487,0,__PYX_ERR(1, 487, __pyx_L1_error))


  /* "View.MemoryView":503
 *             return result
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         """Only used if instantiated manually by the user, or if Cython doesn't
 *         know how to convert the type"""
 */
  __Pyx_TraceLine(503,0,__PYX_ERR(1, 503, __pyx_L1_error))


  /* "View.MemoryView":551
 *         info.obj = self
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(551,0,__PYX_ERR(1, 551, __pyx_L1_error))
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(1, 551, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_memoryview_type);

  /* "View.MemoryView":659
 * 
 * @cname('__pyx_memoryview_new')
 * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):             # <<<<<<<<<<<<<<
 *     cdef memoryview result = memoryview(o, flags, dtype_is_object)
 *     result.typeinfo = typeinfo
 */
  __Pyx_TraceLine(659,0,__PYX_ERR(1, 659, __pyx_L1_error))


  /* "View.MemoryView":665
 * 
 * @cname('__pyx_memoryview_check')
 * cdef inline bint memoryview_check(object o):             # <<<<<<<<<<<<<<
 *     return isinstance(o, memoryview)
 * 
 */
  __Pyx_TraceLine(665,0,__PYX_ERR(1, 665, __pyx_L1_error))


  /* "View.MemoryView":668
 *     return isinstance(o, memoryview)
 * 
 * cdef tuple _unellipsify(object index, int ndim):             # <<<<<<<<<<<<<<
 *     """
 *     Replace all ellipses with full slices and fill incomplete indices with
 */
  __Pyx_TraceLine(668,0,__PYX_ERR(1, 668, __pyx_L1_error))


  /* "View.MemoryView":702
 *     return have_slices or nslices, tuple(result)
 * 
 * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):             # <<<<<<<<<<<<<<
 *     for suboffset in suboffsets[:ndim]:
 *         if suboffset >= 0:
 */
  __Pyx_TraceLine(702,0,__PYX_ERR(1, 702, __pyx_L1_error))


  /* "View.MemoryView":712
 * 
 * @cname('__pyx_memview_slice')
 * cdef memoryview memview_slice(memoryview memview, object indices):             # <<<<<<<<<<<<<<
 *     cdef int new_ndim = 0, suboffset_dim = -1, dim
 *     cdef bint negative_step
 */
  __Pyx_TraceLine(712,0,__PYX_ERR(1, 712, __pyx_L1_error))


  /* "View.MemoryView":809
 * 
 * @cname('__pyx_memoryview_slice_memviewslice')
 * cdef int slice_memviewslice(             # <<<<<<<<<<<<<<
 *         __Pyx_memviewslice *dst,
 *         Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
 */
  __Pyx_TraceLine(809,0,__PYX_ERR(1, 809, __pyx_L1_error))


  /* "View.MemoryView":912
 * 
 * @cname('__pyx_pybuffer_index')
 * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,             # <<<<<<<<<<<<<<
 *                           Py_ssize_t dim) except NULL:
 *     cdef Py_ssize_t shape, stride, suboffset = -1
 */
  __Pyx_TraceLine(912,0,__PYX_ERR(1, 912, __pyx_L1_error))


  /* "View.MemoryView":945
 * 
 * @cname('__pyx_memslice_transpose')
 * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:             # <<<<<<<<<<<<<<
 *     cdef int ndim = memslice.memview.view.ndim
 * 
 */
  __Pyx_TraceLine(945,0,__PYX_ERR(1, 945, __pyx_L1_error))


  /* "View.MemoryView":981
 *         __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
 * 
 *     cdef convert_item_to_object(self, char *itemp):             # <<<<<<<<<<<<<<
 *         if self.to_object_func != NULL:
 *             return self.to_object_func(itemp)
 */
  __Pyx_TraceLine(981,0,__PYX_ERR(1, 981, __pyx_L1_error))


  /* "View.MemoryView":987
 *             return memoryview.convert_item_to_object(self, itemp)
 * 
 *     cdef assign_item_from_object(self, char *itemp, object value):             # <<<<<<<<<<<<<<
 *         if self.to_dtype_func != NULL:
 *             self.to_dtype_func(itemp, value)
 */
  __Pyx_TraceLine(987,0,__PYX_ERR(1, 987, __pyx_L1_error))


  /* "View.MemoryView":997
 *         return self.from_object
 * 
 *     __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(997,0,__PYX_ERR(1, 997, __pyx_L1_error))
  __pyx_t_2 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 997, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_2) < 0) __PYX_ERR(1, 997, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_memoryviewslice_type);

  /* "View.MemoryView":1001
 * 
 * @cname('__pyx_memoryview_fromslice')
 * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice,             # <<<<<<<<<<<<<<
 *                           int ndim,
 *                           object (*to_object_func)(char *),
 */
  __Pyx_TraceLine(1001,0,__PYX_ERR(1, 1001, __pyx_L1_error))


  /* "View.MemoryView":1054
 * 
 * @cname('__pyx_memoryview_get_slice_from_memoryview')
 * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview,             # <<<<<<<<<<<<<<
 *                                                    __Pyx_memviewslice *mslice) except NULL:
 *     cdef _memoryviewslice obj
 */
  __Pyx_TraceLine(1054,0,__PYX_ERR(1, 1054, __pyx_L1_error))


  /* "View.MemoryView":1065
 * 
 * @cname('__pyx_memoryview_slice_copy')
 * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst):             # <<<<<<<<<<<<<<
 *     cdef int dim
 *     cdef (Py_ssize_t*) shape, strides, suboffsets
 */
  __Pyx_TraceLine(1065,0,__PYX_ERR(1, 1065, __pyx_L1_error))


  /* "View.MemoryView":1082
 * 
 * @cname('__pyx_memoryview_copy_object')
 * cdef memoryview_copy(memoryview memview):             # <<<<<<<<<<<<<<
 *     "Create a new memoryview object"
 *     cdef __Pyx_memviewslice memviewslice
 */
  __Pyx_TraceLine(1082,0,__PYX_ERR(1, 1082, __pyx_L1_error))


  /* "View.MemoryView":1089
 * 
 * @cname('__pyx_memoryview_copy_object_from_slice')
 * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice):             # <<<<<<<<<<<<<<
 *     """
 *     Create a new memoryview object from a given memoryview object and slice.
 */
  __Pyx_TraceLine(1089,0,__PYX_ERR(1, 1089, __pyx_L1_error))


  /* "View.MemoryView":1111
 * 
 * 
 * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil:             # <<<<<<<<<<<<<<
 *     if arg < 0:
 *         return -arg
 */
  __Pyx_TraceLine(1111,0,__PYX_ERR(1, 1111, __pyx_L1_error))


  /* "View.MemoryView":1118
 * 
 * @cname('__pyx_get_best_slice_order')
 * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     """
 *     Figure out the best memory access order for a given slice.
 */
  __Pyx_TraceLine(1118,0,__PYX_ERR(1, 1118, __pyx_L1_error))


  /* "View.MemoryView":1172
 *             dst_data += dst_stride
 * 
 * cdef void copy_strided_to_strided(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice *dst,
 *                                   int ndim, size_t itemsize) nogil:
 */
  __Pyx_TraceLine(1172,0,__PYX_ERR(1, 1172, __pyx_L1_error))


  /* "View.MemoryView":1179
 * 
 * @cname('__pyx_memoryview_slice_get_size')
 * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil:             # <<<<<<<<<<<<<<
 *     "Return the size of the memory occupied by the slice in number of bytes"
 *     cdef Py_ssize_t shape, size = src.memview.view.itemsize
 */
  __Pyx_TraceLine(1179,0,__PYX_ERR(1, 1179, __pyx_L1_error))


  /* "View.MemoryView":1189
 * 
 * @cname('__pyx_fill_contig_strides_array')
 * cdef Py_ssize_t fill_contig_strides_array(             # <<<<<<<<<<<<<<
 *                 Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride,
 *                 int ndim, char order) nogil:
 */
  __Pyx_TraceLine(1189,0,__PYX_ERR(1, 1189, __pyx_L1_error))


  /* "View.MemoryView":1210
 * 
 * @cname('__pyx_memoryview_copy_data_to_temp')
 * cdef void *copy_data_to_temp(__Pyx_memviewslice *src,             # <<<<<<<<<<<<<<
 *                              __Pyx_memviewslice *tmpslice,
 *                              char order,
 */
  __Pyx_TraceLine(1210,0,__PYX_ERR(1, 1210, __pyx_L1_error))


  /* "View.MemoryView":1253
 * 
 * @cname('__pyx_memoryview_err_extents')
 * cdef int _err_extents(int i, Py_ssize_t extent1,             # <<<<<<<<<<<<<<
 *                              Py_ssize_t extent2) except -1 with gil:
 *     raise ValueError("got differing extents in dimension %d (got %d and %d)" %
 */
  __Pyx_TraceLine(1253,0,__PYX_ERR(1, 1253, __pyx_L1_error))


  /* "View.MemoryView":1259
 * 
 * @cname('__pyx_memoryview_err_dim')
 * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil:             # <<<<<<<<<<<<<<
 *     raise error(msg.decode('ascii') % dim)
 * 
 */
  __Pyx_TraceLine(1259,0,__PYX_ERR(1, 1259, __pyx_L1_error))


  /* "View.MemoryView":1263
 * 
 * @cname('__pyx_memoryview_err')
 * cdef int _err(object error, char *msg) except -1 with gil:             # <<<<<<<<<<<<<<
 *     if msg != NULL:
 *         raise error(msg.decode('ascii'))
 */
  __Pyx_TraceLine(1263,0,__PYX_ERR(1, 1263, __pyx_L1_error))


  /* "View.MemoryView":1270
 * 
 * @cname('__pyx_memoryview_copy_contents')
 * cdef int memoryview_copy_contents(__Pyx_memviewslice src,             # <<<<<<<<<<<<<<
 *                                   __Pyx_memviewslice dst,
 *                                   int src_ndim, int dst_ndim,
 */
  __Pyx_TraceLine(1270,0,__PYX_ERR(1, 1270, __pyx_L1_error))


  /* "View.MemoryView":1342
 * 
 * @cname('__pyx_memoryview_broadcast_leading')
 * cdef void broadcast_leading(__Pyx_memviewslice *mslice,             # <<<<<<<<<<<<<<
 *                             int ndim,
 *                             int ndim_other) nogil:
 */
  __Pyx_TraceLine(1342,0,__PYX_ERR(1, 1342, __pyx_L1_error))


  /* "View.MemoryView":1364
 * 
 * @cname('__pyx_memoryview_refcount_copying')
 * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object,             # <<<<<<<<<<<<<<
 *                            int ndim, bint inc) nogil:
 * 
 */
  __Pyx_TraceLine(1364,0,__PYX_ERR(1, 1364, __pyx_L1_error))


  /* "View.MemoryView":1373
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil')
 * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                              Py_ssize_t *strides, int ndim,
 *                                              bint inc) with gil:
 */
  __Pyx_TraceLine(1373,0,__PYX_ERR(1, 1373, __pyx_L1_error))


  /* "View.MemoryView":1379
 * 
 * @cname('__pyx_memoryview_refcount_objects_in_slice')
 * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                                     Py_ssize_t *strides, int ndim, bint inc):
 *     cdef Py_ssize_t i
 */
  __Pyx_TraceLine(1379,0,__PYX_ERR(1, 1379, __pyx_L1_error))


  /* "View.MemoryView":1399
 * 
 * @cname('__pyx_memoryview_slice_assign_scalar')
 * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim,             # <<<<<<<<<<<<<<
 *                               size_t itemsize, void *item,
 *                               bint dtype_is_object) nogil:
 */
  __Pyx_TraceLine(1399,0,__PYX_ERR(1, 1399, __pyx_L1_error))


  /* "View.MemoryView":1409
 * 
 * @cname('__pyx_memoryview__slice_assign_scalar')
 * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape,             # <<<<<<<<<<<<<<
 *                               Py_ssize_t *strides, int ndim,
 *                               size_t itemsize, void *item) nogil:
 */
  __Pyx_TraceLine(1409,0,__PYX_ERR(1, 1409, __pyx_L1_error))


  /* "(tree fragment)":1
 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __Pyx_TraceLine(1,0,__PYX_ERR(1, 1, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":11
 *         __pyx_unpickle_Enum__set_state(<Enum> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result.name = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */
  __Pyx_TraceLine(11,0,__PYX_ERR(1, 11, __pyx_L1_error))

  __Pyx_TraceReturn(Py_None, 0);

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init discretize._extensions.tree_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init discretize._extensions.tree_ext");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* Profile */
#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   PyThreadState* tstate,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    PyObject *type, *value, *traceback;
    int retval;
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            tstate,                          /*PyThreadState *tstate*/
            *code,                           /*PyCodeObject *code*/
            __pyx_d,                  /*PyObject *globals*/
            0                                /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
        if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
            Py_INCREF(Py_None);
            (*frame)->f_trace = Py_None;
        }
#if PY_VERSION_HEX < 0x030400B1
    } else {
        (*frame)->f_tstate = tstate;
#endif
    }
    __Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
    retval = 1;
    __Pyx_EnterTracing(tstate);
    __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
    #if CYTHON_TRACE
    if (tstate->c_tracefunc)
        retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
    if (retval && tstate->c_profilefunc)
    #endif
        retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
    __Pyx_LeaveTracing(tstate);
    if (retval) {
        __Pyx_ErrRestoreInState(tstate, type, value, traceback);
        return __Pyx_IsTracing(tstate, 0, 0) && retval;
    } else {
        Py_XDECREF(type);
        Py_XDECREF(value);
        Py_XDECREF(traceback);
        return -1;
    }
}
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyCodeObject *py_code = 0;
#if PY_MAJOR_VERSION >= 3
    py_code = PyCode_NewEmpty(srcfile, funcname, firstlineno);
    if (likely(py_code)) {
        py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS;
    }
#else
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    py_funcname = PyString_FromString(funcname);
    if (unlikely(!py_funcname)) goto bad;
    py_srcfile = PyString_FromString(srcfile);
    if (unlikely(!py_srcfile)) goto bad;
    py_code = PyCode_New(
        0,
        0,
        0,
        CO_OPTIMIZED | CO_NEWLOCALS,
        __pyx_empty_bytes,     /*PyObject *code,*/
        __pyx_empty_tuple,     /*PyObject *consts,*/
        __pyx_empty_tuple,     /*PyObject *names,*/
        __pyx_empty_tuple,     /*PyObject *varnames,*/
        __pyx_empty_tuple,     /*PyObject *freevars,*/
        __pyx_empty_tuple,     /*PyObject *cellvars,*/
        py_srcfile,       /*PyObject *filename,*/
        py_funcname,      /*PyObject *name,*/
        firstlineno,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
#endif
    return py_code;
}
#endif

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
    else state = (PyGILState_STATE)0;
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (__Pyx_PyFastCFunction_Check(func)) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* SetItemInt */
static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return -1;
                    PyErr_Clear();
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o)))
#else
    if (is_list || PySequence_Check(o))
#endif
    {
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_FAST_THREAD_STATE
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#else
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG)
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* KeywordStringCheck */
static int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_FALSE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_FALSE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_FALSE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a != b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_TRUE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_TRUE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a != (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* FetchCommonType */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

/* CythonFunctionShared */
#include <structmember.h>
static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp = op->func_doc;
    if (value == NULL) {
        value = Py_None;
    }
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
    PyObject *self;
    self = m->func_closure;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    int result = 0;
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    #else
    op->defaults_tuple = PySequence_ITEM(res, 0);
    if (unlikely(!op->defaults_tuple)) result = -1;
    else {
        op->defaults_kwdict = PySequence_ITEM(res, 1);
        if (unlikely(!op->defaults_kwdict)) result = -1;
    }
    #endif
    Py_DECREF(res);
    return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_CyFunction_members[] = {
    {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0},
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
    Py_INCREF(m->func_qualname);
    return m->func_qualname;
#else
    return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname,
                                       PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    if (unlikely(op == NULL))
        return NULL;
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = NULL;
    op->func.m_ml = ml;
    op->func.m_self = (PyObject *) op;
    Py_XINCREF(closure);
    op->func_closure = closure;
    Py_XINCREF(module);
    op->func.m_module = module;
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults_size = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
    Py_CLEAR(m->func.m_module);
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyObject_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    if (__Pyx_CyFunction_weakreflist(m) != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    PyObject_GC_Del(m);
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    __Pyx__CyFunction_dealloc(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
    Py_VISIT(m->func.m_module);
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
#if PY_MAJOR_VERSION < 3
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
        Py_INCREF(func);
        return func;
    }
    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
        if (type == NULL)
            type = (PyObject *)(Py_TYPE(obj));
        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
#endif
    return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = f->m_ml->ml_meth;
    Py_ssize_t size;
    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
    case METH_VARARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0))
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 0))
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 1)) {
                PyObject *result, *arg0;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                arg0 = PyTuple_GET_ITEM(arg, 0);
                #else
                arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL;
                #endif
                result = (*meth)(self, arg0);
                #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
                Py_DECREF(arg0);
                #endif
                return result;
            }
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
                        "longer supported!");
        return NULL;
    }
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
    return NULL;
}
static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
}
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
    PyObject *result;
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
        Py_ssize_t argc;
        PyObject *new_args;
        PyObject *self;
        argc = PyTuple_GET_SIZE(args);
        new_args = PyTuple_GetSlice(args, 1, argc);
        if (unlikely(!new_args))
            return NULL;
        self = PyTuple_GetItem(args, 0);
        if (unlikely(!self)) {
            Py_DECREF(new_args);
#if PY_MAJOR_VERSION > 2
            PyErr_Format(PyExc_TypeError,
                         "unbound method %.200S() needs an argument",
                         cyfunc->func_qualname);
#else
            PyErr_SetString(PyExc_TypeError,
                            "unbound method needs an argument");
#endif
            return NULL;
        }
        result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
        Py_DECREF(new_args);
    } else {
        result = __Pyx_CyFunction_Call(func, args, kw);
    }
    return result;
}
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_CallAsMethod,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_CyFunction_descr_get,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
    0,
#endif
#if PY_VERSION_HEX >= 0x030C0000
    0,
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
    0,
#endif
};
static int __pyx_CyFunction_init(void) {
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (unlikely(__pyx_CyFunctionType == NULL)) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyObject_Malloc(size);
    if (unlikely(!m->defaults))
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    m->defaults_size = size;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

/* CythonFunction */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    PyObject *op = __Pyx_CyFunction_Init(
        PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType),
        ml, flags, qualname, closure, module, globals, code
    );
    if (likely(op)) {
        PyObject_GC_Track(op);
    }
    return op;
}

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* MemviewSliceInit */
static int
__Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview,
                        int ndim,
                        __Pyx_memviewslice *memviewslice,
                        int memview_is_new_reference)
{
    __Pyx_RefNannyDeclarations
    int i, retval=-1;
    Py_buffer *buf = &memview->view;
    __Pyx_RefNannySetupContext("init_memviewslice", 0);
    if (unlikely(memviewslice->memview || memviewslice->data)) {
        PyErr_SetString(PyExc_ValueError,
            "memviewslice is already initialized!");
        goto fail;
    }
    if (buf->strides) {
        for (i = 0; i < ndim; i++) {
            memviewslice->strides[i] = buf->strides[i];
        }
    } else {
        Py_ssize_t stride = buf->itemsize;
        for (i = ndim - 1; i >= 0; i--) {
            memviewslice->strides[i] = stride;
            stride *= buf->shape[i];
        }
    }
    for (i = 0; i < ndim; i++) {
        memviewslice->shape[i]   = buf->shape[i];
        if (buf->suboffsets) {
            memviewslice->suboffsets[i] = buf->suboffsets[i];
        } else {
            memviewslice->suboffsets[i] = -1;
        }
    }
    memviewslice->memview = memview;
    memviewslice->data = (char *)buf->buf;
    if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) {
        Py_INCREF(memview);
    }
    retval = 0;
    goto no_fail;
fail:
    memviewslice->memview = 0;
    memviewslice->data = 0;
    retval = -1;
no_fail:
    __Pyx_RefNannyFinishContext();
    return retval;
}
#ifndef Py_NO_RETURN
#define Py_NO_RETURN
#endif
static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN {
    va_list vargs;
    char msg[200];
#if PY_VERSION_HEX >= 0x030A0000 || defined(HAVE_STDARG_PROTOTYPES)
    va_start(vargs, fmt);
#else
    va_start(vargs);
#endif
    vsnprintf(msg, 200, fmt, vargs);
    va_end(vargs);
    Py_FatalError(msg);
}
static CYTHON_INLINE int
__pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
                                   PyThread_type_lock lock)
{
    int result;
    PyThread_acquire_lock(lock, 1);
    result = (*acquisition_count)++;
    PyThread_release_lock(lock);
    return result;
}
static CYTHON_INLINE int
__pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
                                   PyThread_type_lock lock)
{
    int result;
    PyThread_acquire_lock(lock, 1);
    result = (*acquisition_count)--;
    PyThread_release_lock(lock);
    return result;
}
static CYTHON_INLINE void
__Pyx_INC_MEMVIEW(__Pyx_memviewslice *memslice, int have_gil, int lineno)
{
    int first_time;
    struct __pyx_memoryview_obj *memview = memslice->memview;
    if (unlikely(!memview || (PyObject *) memview == Py_None))
        return;
    if (unlikely(__pyx_get_slice_count(memview) < 0))
        __pyx_fatalerror("Acquisition count is %d (line %d)",
                         __pyx_get_slice_count(memview), lineno);
    first_time = __pyx_add_acquisition_count(memview) == 0;
    if (unlikely(first_time)) {
        if (have_gil) {
            Py_INCREF((PyObject *) memview);
        } else {
            PyGILState_STATE _gilstate = PyGILState_Ensure();
            Py_INCREF((PyObject *) memview);
            PyGILState_Release(_gilstate);
        }
    }
}
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice,
                                             int have_gil, int lineno) {
    int last_time;
    struct __pyx_memoryview_obj *memview = memslice->memview;
    if (unlikely(!memview || (PyObject *) memview == Py_None)) {
        memslice->memview = NULL;
        return;
    }
    if (unlikely(__pyx_get_slice_count(memview) <= 0))
        __pyx_fatalerror("Acquisition count is %d (line %d)",
                         __pyx_get_slice_count(memview), lineno);
    last_time = __pyx_sub_acquisition_count(memview) == 1;
    memslice->data = NULL;
    if (unlikely(last_time)) {
        if (have_gil) {
            Py_CLEAR(memslice->memview);
        } else {
            PyGILState_STATE _gilstate = PyGILState_Ensure();
            Py_CLEAR(memslice->memview);
            PyGILState_Release(_gilstate);
        }
    } else {
        memslice->memview = NULL;
    }
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr = NULL;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
#define __Pyx_PyInt_TrueDivideObjC_ZeroDivisionError(operand)\
    if (unlikely(zerodivision_check && ((operand) == 0))) {\
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division by zero");\
        return NULL;\
    }
#endif
static PyObject* __Pyx_PyInt_TrueDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
            __Pyx_PyInt_TrueDivideObjC_ZeroDivisionError(b)
            if (8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53))) {
                return PyFloat_FromDouble((double)a / (double)b);
            }
            return PyInt_Type.tp_as_number->nb_true_divide(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT && 1 * PyLong_SHIFT < 53) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT && 2 * PyLong_SHIFT < 53) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT && 3 * PyLong_SHIFT < 53) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_true_divide(op1, op2);
            }
        }
                __Pyx_PyInt_TrueDivideObjC_ZeroDivisionError(b)
                if ((8 * sizeof(long) <= 53 || likely(labs(a) <= ((PY_LONG_LONG)1 << 53)))
                        || __Pyx_sst_abs(size) <= 52 / PyLong_SHIFT) {
                    return PyFloat_FromDouble((double)a / (double)b);
                }
                return PyLong_Type.tp_as_number->nb_true_divide(op1, op2);
            return PyLong_FromLong(x);
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            if (unlikely(zerodivision_check && b == 0)) {
                PyErr_SetString(PyExc_ZeroDivisionError, "float division by zero");
                return NULL;
            }
            PyFPE_START_PROTECT("divide", return NULL)
            result = ((double)a) / (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceTrueDivide : PyNumber_TrueDivide)(op1, op2);
}
#endif

/* BufferIndexError */
static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

/* PyObjectSetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#endif

/* None */
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      CYTHON_UNUSED Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind;
    Py_ssize_t i, char_pos;
    void *result_udata;
#if CYTHON_PEP393_ENABLED
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    result_udata = PyUnicode_DATA(result_uval);
#else
    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = sizeof(Py_UNICODE);
    result_udata = PyUnicode_AS_UNICODE(result_uval);
#endif
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
        if (unlikely(__Pyx_PyUnicode_READY(uval)))
            goto bad;
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        if (unlikely(!ulength))
            continue;
        if (unlikely(char_pos + ulength < 0))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
        } else {
            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    result_ulength++;
    value_count++;
    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
#endif
}

/* CIntToDigits */
static const char DIGIT_PAIRS_10[2*10*10+1] = {
    "00010203040506070809"
    "10111213141516171819"
    "20212223242526272829"
    "30313233343536373839"
    "40414243444546474849"
    "50515253545556575859"
    "60616263646566676869"
    "70717273747576777879"
    "80818283848586878889"
    "90919293949596979899"
};
static const char DIGIT_PAIRS_8[2*8*8+1] = {
    "0001020304050607"
    "1011121314151617"
    "2021222324252627"
    "3031323334353637"
    "4041424344454647"
    "5051525354555657"
    "6061626364656667"
    "7071727374757677"
};
static const char DIGITS_HEX[2*16+1] = {
    "0123456789abcdef"
    "0123456789ABCDEF"
};

/* BuildPyUnicode */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char) {
    PyObject *uval;
    Py_ssize_t uoffset = ulength - clength;
#if CYTHON_USE_UNICODE_INTERNALS
    Py_ssize_t i;
#if CYTHON_PEP393_ENABLED
    void *udata;
    uval = PyUnicode_New(ulength, 127);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_DATA(uval);
#else
    Py_UNICODE *udata;
    uval = PyUnicode_FromUnicode(NULL, ulength);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_AS_UNICODE(uval);
#endif
    if (uoffset > 0) {
        i = 0;
        if (prepend_sign) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
            i++;
        }
        for (; i < uoffset; i++) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
        }
    }
    for (i=0; i < clength; i++) {
        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
    }
#else
    {
        PyObject *sign = NULL, *padding = NULL;
        uval = NULL;
        if (uoffset > 0) {
            prepend_sign = !!prepend_sign;
            if (uoffset > prepend_sign) {
                padding = PyUnicode_FromOrdinal(padding_char);
                if (likely(padding) && uoffset > prepend_sign + 1) {
                    PyObject *tmp;
                    PyObject *repeat = PyInt_FromSsize_t(uoffset - prepend_sign);
                    if (unlikely(!repeat)) goto done_or_error;
                    tmp = PyNumber_Multiply(padding, repeat);
                    Py_DECREF(repeat);
                    Py_DECREF(padding);
                    padding = tmp;
                }
                if (unlikely(!padding)) goto done_or_error;
            }
            if (prepend_sign) {
                sign = PyUnicode_FromOrdinal('-');
                if (unlikely(!sign)) goto done_or_error;
            }
        }
        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
        if (likely(uval) && padding) {
            PyObject *tmp = PyNumber_Add(padding, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
        if (likely(uval) && sign) {
            PyObject *tmp = PyNumber_Add(sign, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
done_or_error:
        Py_XDECREF(padding);
        Py_XDECREF(sign);
    }
#endif
    return uval;
}

/* CIntToPyUnicode */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(int)*3+2];
    char *dpos, *end = digits + sizeof(int)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    int remaining;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (int) (remaining / (8*8));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (int) (remaining / (10*10));
            dpos -= 2;
            memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2);
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (int) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    if (last_one_off) {
        assert(*dpos == '0');
        dpos++;
    }
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* DivInt[Py_ssize_t] */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t q = a / b;
    Py_ssize_t r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* pyobject_as_double */
static double __Pyx__PyObject_AsDouble(PyObject* obj) {
    PyObject* float_value;
#if !CYTHON_USE_TYPE_SLOTS
    float_value = PyNumber_Float(obj);  if ((0)) goto bad;
#else
    PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
    if (likely(nb) && likely(nb->nb_float)) {
        float_value = nb->nb_float(obj);
        if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
            PyErr_Format(PyExc_TypeError,
                "__float__ returned non-float (type %.200s)",
                Py_TYPE(float_value)->tp_name);
            Py_DECREF(float_value);
            goto bad;
        }
    } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
#if PY_MAJOR_VERSION >= 3
        float_value = PyFloat_FromString(obj);
#else
        float_value = PyFloat_FromString(obj, 0);
#endif
    } else {
        PyObject* args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        PyTuple_SET_ITEM(args, 0, obj);
        float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0);
        PyTuple_SET_ITEM(args, 0, 0);
        Py_DECREF(args);
    }
#endif
    if (likely(float_value)) {
        double value = PyFloat_AS_DOUBLE(float_value);
        Py_DECREF(float_value);
        return value;
    }
bad:
    return (double)-1;
}

/* SliceObject */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* None */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    }
    return __Pyx_IterFinish();
}

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RshiftObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
            return PyInt_FromLong(a >> b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_rshift(op1, op2);
            }
        }
                x = a >> b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla >> llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceRshift : PyNumber_Rshift)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
#define __Pyx_PyInt_RemainderObjC_ZeroDivisionError(operand)\
    if (unlikely(zerodivision_check && ((operand) == 0))) {\
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");\
        return NULL;\
    }
#endif
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            __Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
            x = a % b;
            x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_remainder(op1, op2);
            }
        }
                __Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
                x = a % b;
                x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla % llb;
                llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceRemainder : PyNumber_Remainder)(op1, op2);
}
#endif

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* GetAttr3 */
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    Py_INCREF(d);
    return d;
}
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = __Pyx_GetAttr(o, n);
    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
}

/* MatrixMultiply */
#if PY_VERSION_HEX < 0x03050000
static PyObject* __Pyx_PyObject_CallMatrixMethod(PyObject* method, PyObject* arg) {
    PyObject *result = NULL;
#if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyCFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            args = PyTuple_New(2);
            if (unlikely(!args)) goto done;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
done:
    Py_DECREF(method);
    return result;
}
#define __Pyx_TryMatrixMethod(x, y, py_method_name) {\
    PyObject *func = __Pyx_PyObject_GetAttrStr(x, py_method_name);\
    if (func) {\
        PyObject *result = __Pyx_PyObject_CallMatrixMethod(func, y);\
        if (result != Py_NotImplemented)\
            return result;\
        Py_DECREF(result);\
    } else {\
        if (!PyErr_ExceptionMatches(PyExc_AttributeError))\
            return NULL;\
        PyErr_Clear();\
    }\
}
static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name) {
    int right_is_subtype = PyObject_IsSubclass((PyObject*)Py_TYPE(y), (PyObject*)Py_TYPE(x));
    if (unlikely(right_is_subtype == -1))
        return NULL;
    if (right_is_subtype) {
        __Pyx_TryMatrixMethod(y, x, __pyx_n_s_rmatmul)
    }
    __Pyx_TryMatrixMethod(x, y, __pyx_n_s_matmul)
    if (!right_is_subtype) {
        __Pyx_TryMatrixMethod(y, x, __pyx_n_s_rmatmul)
    }
    PyErr_Format(PyExc_TypeError,
                 "unsupported operand type(s) for %.2s: '%.100s' and '%.100s'",
                 op_name,
                 Py_TYPE(x)->tp_name,
                 Py_TYPE(y)->tp_name);
    return NULL;
}
static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y) {
    __Pyx_TryMatrixMethod(x, y, __pyx_n_s_imatmul)
    return __Pyx__PyNumber_MatrixMultiply(x, y, "@=");
}
#undef __Pyx_TryMatrixMethod
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
    }
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* SliceObject */
static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_ass_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_ass_slice(obj, cstart, cstop, value);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_ass_subscript))
#endif
    {
        int result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_ass_subscript(obj, py_slice, value);
#else
        result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object does not support slice %.10s",
        Py_TYPE(obj)->tp_name, value ? "assignment" : "deletion");
bad:
    return -1;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        const long a = intval;
        long x;
        long b = PyInt_AS_LONG(op2);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op2))) {
        const long a = intval;
        long b, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG lla = intval;
        PY_LONG_LONG llb, llx;
#endif
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            b = likely(size) ? digits[0] : 0;
            if (size == -1) b = -b;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op2)) {
        const long a = intval;
        double b = PyFloat_AS_DOUBLE(op2);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
#define __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(operand)\
    if (unlikely(zerodivision_check && ((operand) == 0))) {\
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division by zero");\
        return NULL;\
    }
#endif
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(b)
            if (unlikely(b == -1 && ((unsigned long)a) == 0-(unsigned long)a))
                return PyInt_Type.tp_as_number->nb_floor_divide(op1, op2);
            else {
                long q, r;
                q = a / b;
                r = a - q*b;
                q -= ((r != 0) & ((r ^ b) < 0));
                x = q;
            }
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_floor_divide(op1, op2);
            }
        }
                __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(b)
                {
                    long q, r;
                    q = a / b;
                    r = a - q*b;
                    q -= ((r != 0) & ((r ^ b) < 0));
                    x = q;
                }
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                {
                    PY_LONG_LONG q, r;
                    q = lla / llb;
                    r = lla - q*llb;
                    q -= ((r != 0) & ((r ^ llb) < 0));
                    llx = q;
                }
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceFloorDivide : PyNumber_FloorDivide)(op1, op2);
}
#endif

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* decode_c_string */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        size_t slen = strlen(cstring);
        if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
            PyErr_SetString(PyExc_OverflowError,
                            "c-string too long to convert to Python");
            return NULL;
        }
        length = (Py_ssize_t) slen;
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    if (unlikely(stop <= start))
        return __Pyx_NewRef(__pyx_empty_unicode);
    length = stop - start;
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

/* RaiseNoneIterError */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* ExtTypeTest */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* SwapException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = *type;
    exc_info->exc_value = *value;
    exc_info->exc_traceback = *tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
    #endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* DivInt[long] */
static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* PyObject_GenericGetAttrNoDict */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetVTable */
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* PyObjectGetAttrStrNoError */
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
}

/* SetupReduce */
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_getstate = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
    PyObject *getstate = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate);
#else
    getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate);
    if (!getstate && PyErr_Occurred()) {
        goto __PYX_BAD;
    }
#endif
    if (getstate) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate);
#else
        object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate);
        if (!object_getstate && PyErr_Occurred()) {
            goto __PYX_BAD;
        }
#endif
        if (object_getstate != getstate) {
            goto __PYX_GOOD;
        }
    }
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
            if (likely(reduce_cython)) {
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
            } else if (reduce == object_reduce || PyErr_Occurred()) {
                goto __PYX_BAD;
            }
            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
                if (likely(setstate_cython)) {
                    ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                    ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                } else if (!setstate || PyErr_Occurred()) {
                    goto __PYX_BAD;
                }
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto __PYX_GOOD;
__PYX_BAD:
    if (!PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
    ret = -1;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
    Py_XDECREF(object_getstate);
    Py_XDECREF(getstate);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType_0_29_35
#define __PYX_HAVE_RT_ImportType_0_29_35
static PyTypeObject *__Pyx_ImportType_0_29_35(PyObject *module, const char *module_name, const char *class_name,
    size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_0_29_35 check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
    Py_ssize_t itemsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
    PyObject *py_itemsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
    itemsize = ((PyTypeObject *)result)->tp_itemsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
    py_itemsize = PyObject_GetAttrString(result, "__itemsize__");
    if (!py_itemsize)
        goto bad;
    itemsize = PyLong_AsSsize_t(py_itemsize);
    Py_DECREF(py_itemsize);
    py_itemsize = 0;
    if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (itemsize) {
        if (size % alignment) {
            alignment = size % alignment;
        }
        if (itemsize < (Py_ssize_t)alignment)
            itemsize = (Py_ssize_t)alignment;
    }
    if ((size_t)(basicsize + itemsize) < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error_0_29_35 && (size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn_0_29_35 && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject *ptype, *pvalue, *ptraceback;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) {
            /* If the code object creation fails, then we should clear the
               fetched exception references and propagate the new exception */
            Py_XDECREF(ptype);
            Py_XDECREF(pvalue);
            Py_XDECREF(ptraceback);
            goto bad;
        }
        __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_array_type)) return __pyx_array_getbuffer(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_memoryview_type)) return __pyx_memoryview_getbuffer(obj, view, flags);
    PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
    if ((0)) {}
    view->obj = NULL;
    Py_DECREF(obj);
}
#endif


/* MemviewSliceIsContig */
static int
__pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim)
{
    int i, index, step, start;
    Py_ssize_t itemsize = mvs.memview->view.itemsize;
    if (order == 'F') {
        step = 1;
        start = 0;
    } else {
        step = -1;
        start = ndim - 1;
    }
    for (i = 0; i < ndim; i++) {
        index = start + step * i;
        if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize)
            return 0;
        itemsize *= mvs.shape[index];
    }
    return 1;
}

/* OverlappingSlices */
static void
__pyx_get_array_memory_extents(__Pyx_memviewslice *slice,
                               void **out_start, void **out_end,
                               int ndim, size_t itemsize)
{
    char *start, *end;
    int i;
    start = end = slice->data;
    for (i = 0; i < ndim; i++) {
        Py_ssize_t stride = slice->strides[i];
        Py_ssize_t extent = slice->shape[i];
        if (extent == 0) {
            *out_start = *out_end = start;
            return;
        } else {
            if (stride > 0)
                end += stride * (extent - 1);
            else
                start += stride * (extent - 1);
        }
    }
    *out_start = start;
    *out_end = end + itemsize;
}
static int
__pyx_slices_overlap(__Pyx_memviewslice *slice1,
                     __Pyx_memviewslice *slice2,
                     int ndim, size_t itemsize)
{
    void *start1, *end1, *start2, *end2;
    __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize);
    __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize);
    return (start1 < end2) && (start2 < end1);
}

/* Capsule */
static CYTHON_INLINE PyObject *
__pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig)
{
    PyObject *cobj;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(p, sig, NULL);
#else
    cobj = PyCObject_FromVoidPtr(p, NULL);
#endif
    return cobj;
}

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* IsLittleEndian */
static CYTHON_INLINE int __Pyx_Is_Little_Endian(void)
{
  union {
    uint32_t u32;
    uint8_t u8[4];
  } S;
  S.u32 = 0x01020304;
  return S.u8[0] == 4;
}

/* BufferFormatCheck */
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t <= '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1)
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case '?': return "'bool'";
    case 'c': return "'char'";
    case 'b': return "'signed char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c':
        return 'H';
    case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case '?': case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
      } else {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
      }
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count;
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break;
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue;
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number, ndim;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    ndim = ctx->head->field->type->ndim;
    while (*ts && *ts != ')') {
        switch (*ts) {
            case ' ': case '\f': case '\r': case '\n': case '\t': case '\v':  continue;
            default:  break;
        }
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        return ts;
      case ' ':
      case '\r':
      case '\n':
        ++ts;
        break;
      case '<':
        if (!__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T':
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}':
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }
        CYTHON_FALLTHROUGH;
      case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 'p':
        if ((ctx->enc_type == *ts) && (got_Z == ctx->is_complex) &&
            (ctx->enc_packmode == ctx->new_packmode) && (!ctx->is_valid_array)) {
          ctx->enc_count += ctx->new_count;
          ctx->new_count = 1;
          got_Z = 0;
          ++ts;
          break;
        }
        CYTHON_FALLTHROUGH;
      case 's':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->enc_count = ctx->new_count;
        ctx->enc_packmode = ctx->new_packmode;
        ctx->enc_type = *ts;
        ctx->is_complex = got_Z;
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}

/* TypeInfoCompare */
  static int
__pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b)
{
    int i;
    if (!a || !b)
        return 0;
    if (a == b)
        return 1;
    if (a->size != b->size || a->typegroup != b->typegroup ||
            a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) {
        if (a->typegroup == 'H' || b->typegroup == 'H') {
            return a->size == b->size;
        } else {
            return 0;
        }
    }
    if (a->ndim) {
        for (i = 0; i < a->ndim; i++)
            if (a->arraysize[i] != b->arraysize[i])
                return 0;
    }
    if (a->typegroup == 'S') {
        if (a->flags != b->flags)
            return 0;
        if (a->fields || b->fields) {
            if (!(a->fields && b->fields))
                return 0;
            for (i = 0; a->fields[i].type && b->fields[i].type; i++) {
                __Pyx_StructField *field_a = a->fields + i;
                __Pyx_StructField *field_b = b->fields + i;
                if (field_a->offset != field_b->offset ||
                    !__pyx_typeinfo_cmp(field_a->type, field_b->type))
                    return 0;
            }
            return !a->fields[i].type && !b->fields[i].type;
        }
    }
    return 1;
}

/* MemviewSliceValidateAndInit */
  static int
__pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec)
{
    if (buf->shape[dim] <= 1)
        return 1;
    if (buf->strides) {
        if (spec & __Pyx_MEMVIEW_CONTIG) {
            if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) {
                if (unlikely(buf->strides[dim] != sizeof(void *))) {
                    PyErr_Format(PyExc_ValueError,
                                 "Buffer is not indirectly contiguous "
                                 "in dimension %d.", dim);
                    goto fail;
                }
            } else if (unlikely(buf->strides[dim] != buf->itemsize)) {
                PyErr_SetString(PyExc_ValueError,
                                "Buffer and memoryview are not contiguous "
                                "in the same dimension.");
                goto fail;
            }
        }
        if (spec & __Pyx_MEMVIEW_FOLLOW) {
            Py_ssize_t stride = buf->strides[dim];
            if (stride < 0)
                stride = -stride;
            if (unlikely(stride < buf->itemsize)) {
                PyErr_SetString(PyExc_ValueError,
                                "Buffer and memoryview are not contiguous "
                                "in the same dimension.");
                goto fail;
            }
        }
    } else {
        if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) {
            PyErr_Format(PyExc_ValueError,
                         "C-contiguous buffer is not contiguous in "
                         "dimension %d", dim);
            goto fail;
        } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) {
            PyErr_Format(PyExc_ValueError,
                         "C-contiguous buffer is not indirect in "
                         "dimension %d", dim);
            goto fail;
        } else if (unlikely(buf->suboffsets)) {
            PyErr_SetString(PyExc_ValueError,
                            "Buffer exposes suboffsets but no strides");
            goto fail;
        }
    }
    return 1;
fail:
    return 0;
}
static int
__pyx_check_suboffsets(Py_buffer *buf, int dim, CYTHON_UNUSED int ndim, int spec)
{
    if (spec & __Pyx_MEMVIEW_DIRECT) {
        if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) {
            PyErr_Format(PyExc_ValueError,
                         "Buffer not compatible with direct access "
                         "in dimension %d.", dim);
            goto fail;
        }
    }
    if (spec & __Pyx_MEMVIEW_PTR) {
        if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) {
            PyErr_Format(PyExc_ValueError,
                         "Buffer is not indirectly accessible "
                         "in dimension %d.", dim);
            goto fail;
        }
    }
    return 1;
fail:
    return 0;
}
static int
__pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag)
{
    int i;
    if (c_or_f_flag & __Pyx_IS_F_CONTIG) {
        Py_ssize_t stride = 1;
        for (i = 0; i < ndim; i++) {
            if (unlikely(stride * buf->itemsize != buf->strides[i]  &&  buf->shape[i] > 1)) {
                PyErr_SetString(PyExc_ValueError,
                    "Buffer not fortran contiguous.");
                goto fail;
            }
            stride = stride * buf->shape[i];
        }
    } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) {
        Py_ssize_t stride = 1;
        for (i = ndim - 1; i >- 1; i--) {
            if (unlikely(stride * buf->itemsize != buf->strides[i]  &&  buf->shape[i] > 1)) {
                PyErr_SetString(PyExc_ValueError,
                    "Buffer not C contiguous.");
                goto fail;
            }
            stride = stride * buf->shape[i];
        }
    }
    return 1;
fail:
    return 0;
}
static int __Pyx_ValidateAndInit_memviewslice(
                int *axes_specs,
                int c_or_f_flag,
                int buf_flags,
                int ndim,
                __Pyx_TypeInfo *dtype,
                __Pyx_BufFmt_StackElem stack[],
                __Pyx_memviewslice *memviewslice,
                PyObject *original_obj)
{
    struct __pyx_memoryview_obj *memview, *new_memview;
    __Pyx_RefNannyDeclarations
    Py_buffer *buf;
    int i, spec = 0, retval = -1;
    __Pyx_BufFmt_Context ctx;
    int from_memoryview = __pyx_memoryview_check(original_obj);
    __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0);
    if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *)
                                                            original_obj)->typeinfo)) {
        memview = (struct __pyx_memoryview_obj *) original_obj;
        new_memview = NULL;
    } else {
        memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
                                            original_obj, buf_flags, 0, dtype);
        new_memview = memview;
        if (unlikely(!memview))
            goto fail;
    }
    buf = &memview->view;
    if (unlikely(buf->ndim != ndim)) {
        PyErr_Format(PyExc_ValueError,
                "Buffer has wrong number of dimensions (expected %d, got %d)",
                ndim, buf->ndim);
        goto fail;
    }
    if (new_memview) {
        __Pyx_BufFmt_Init(&ctx, stack, dtype);
        if (unlikely(!__Pyx_BufFmt_CheckString(&ctx, buf->format))) goto fail;
    }
    if (unlikely((unsigned) buf->itemsize != dtype->size)) {
        PyErr_Format(PyExc_ValueError,
                     "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
                     "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
                     buf->itemsize,
                     (buf->itemsize > 1) ? "s" : "",
                     dtype->name,
                     dtype->size,
                     (dtype->size > 1) ? "s" : "");
        goto fail;
    }
    if (buf->len > 0) {
        for (i = 0; i < ndim; i++) {
            spec = axes_specs[i];
            if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
                goto fail;
            if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
                goto fail;
        }
        if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
            goto fail;
    }
    if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
                                         new_memview != NULL) == -1)) {
        goto fail;
    }
    retval = 0;
    goto no_fail;
fail:
    Py_XDECREF(new_memview);
    retval = -1;
no_fail:
    __Pyx_RefNannyFinishContext();
    return retval;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_double(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_double, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_double(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 2,
                                                 &__Pyx_TypeInfo_double, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_int(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_int, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 3,
                                                 &__Pyx_TypeInfo_double, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_float64_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 2,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* MemviewDtypeToObject */
  static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_int64_t(const char *itemp) {
    return (PyObject *) __Pyx_PyInt_From_npy_int64(*(__pyx_t_5numpy_int64_t *) itemp);
}
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_int64_t(const char *itemp, PyObject *obj) {
    __pyx_t_5numpy_int64_t value = __Pyx_PyInt_As_npy_int64(obj);
    if ((value == ((npy_int64)-1)) && PyErr_Occurred())
        return 0;
    *(__pyx_t_5numpy_int64_t *) itemp = value;
    return 1;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int8_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* MemviewDtypeToObject */
  static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_int8_t(const char *itemp) {
    return (PyObject *) __Pyx_PyInt_From_npy_int8(*(__pyx_t_5numpy_int8_t *) itemp);
}
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_int8_t(const char *itemp, PyObject *obj) {
    __pyx_t_5numpy_int8_t value = __Pyx_PyInt_As_npy_int8(obj);
    if ((value == ((npy_int8)-1)) && PyErr_Occurred())
        return 0;
    *(__pyx_t_5numpy_int8_t *) itemp = value;
    return 1;
}

/* MemviewDtypeToObject */
  static CYTHON_INLINE PyObject *__pyx_memview_get_nn___pyx_t_5numpy_float64_t(const char *itemp) {
    return (PyObject *) PyFloat_FromDouble(*(__pyx_t_5numpy_float64_t *) itemp);
}
static CYTHON_INLINE int __pyx_memview_set_nn___pyx_t_5numpy_float64_t(const char *itemp, PyObject *obj) {
    __pyx_t_5numpy_float64_t value = __pyx_PyFloat_AsDouble(obj);
    if ((value == ((npy_float64)-1)) && PyErr_Occurred())
        return 0;
    *(__pyx_t_5numpy_float64_t *) itemp = value;
    return 1;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_5numpy_int64_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 2,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int32_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, 0,
                                                 PyBUF_RECORDS_RO | writable_flag, 1,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* MemviewDtypeToObject */
  static CYTHON_INLINE PyObject *__pyx_memview_get_double(const char *itemp) {
    return (PyObject *) PyFloat_FromDouble(*(double *) itemp);
}
static CYTHON_INLINE int __pyx_memview_set_double(const char *itemp, PyObject *obj) {
    double value = __pyx_PyFloat_AsDouble(obj);
    if ((value == (double)-1) && PyErr_Occurred())
        return 0;
    *(double *) itemp = value;
    return 1;
}

/* ObjectToMemviewSlice */
  static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dcd_d__nn___pyx_t_5numpy_float64_t(PyObject *obj, int writable_flag) {
    __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } };
    __Pyx_BufFmt_StackElem stack[1];
    int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_CONTIG), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW), (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_FOLLOW) };
    int retcode;
    if (obj == Py_None) {
        result.memview = (struct __pyx_memoryview_obj *) Py_None;
        return result;
    }
    retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, __Pyx_IS_F_CONTIG,
                                                 (PyBUF_F_CONTIGUOUS | PyBUF_FORMAT) | writable_flag, 3,
                                                 &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, stack,
                                                 &result, obj);
    if (unlikely(retcode == -1))
        goto __pyx_fail;
    return result;
__pyx_fail:
    result.memview = NULL;
    result.data = NULL;
    return result;
}

/* Declarations */
  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabsf(b.real) >= fabsf(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                float r = b.imag / b.real;
                float s = (float)(1.0) / (b.real + b.imag * r);
                return __pyx_t_float_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            float r = b.real / b.imag;
            float s = (float)(1.0) / (b.imag + b.real * r);
            return __pyx_t_float_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            float denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_float_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        return __Pyx_c_prod_float(a, a);
                    case 3:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, a);
                    case 4:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if ((b.imag == 0) && (a.real >= 0)) {
                    z.real = powf(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2f(0.0, -1.0);
                }
            } else {
                r = __Pyx_c_abs_float(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

/* Declarations */
  #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
  #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabs(b.real) >= fabs(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                double r = b.imag / b.real;
                double s = (double)(1.0) / (b.real + b.imag * r);
                return __pyx_t_double_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            double r = b.real / b.imag;
            double s = (double)(1.0) / (b.imag + b.real * r);
            return __pyx_t_double_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            double denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_double_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        return __Pyx_c_prod_double(a, a);
                    case 3:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, a);
                    case 4:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if ((b.imag == 0) && (a.real >= 0)) {
                    z.real = pow(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2(0.0, -1.0);
                }
            } else {
                r = __Pyx_c_abs_double(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

/* MemviewSliceCopyTemplate */
  static __Pyx_memviewslice
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
                                 const char *mode, int ndim,
                                 size_t sizeof_dtype, int contig_flag,
                                 int dtype_is_object)
{
    __Pyx_RefNannyDeclarations
    int i;
    __Pyx_memviewslice new_mvs = { 0, 0, { 0 }, { 0 }, { 0 } };
    struct __pyx_memoryview_obj *from_memview = from_mvs->memview;
    Py_buffer *buf = &from_memview->view;
    PyObject *shape_tuple = NULL;
    PyObject *temp_int = NULL;
    struct __pyx_array_obj *array_obj = NULL;
    struct __pyx_memoryview_obj *memview_obj = NULL;
    __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0);
    for (i = 0; i < ndim; i++) {
        if (unlikely(from_mvs->suboffsets[i] >= 0)) {
            PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with "
                                           "indirect dimensions (axis %d)", i);
            goto fail;
        }
    }
    shape_tuple = PyTuple_New(ndim);
    if (unlikely(!shape_tuple)) {
        goto fail;
    }
    __Pyx_GOTREF(shape_tuple);
    for(i = 0; i < ndim; i++) {
        temp_int = PyInt_FromSsize_t(from_mvs->shape[i]);
        if(unlikely(!temp_int)) {
            goto fail;
        } else {
            PyTuple_SET_ITEM(shape_tuple, i, temp_int);
            temp_int = NULL;
        }
    }
    array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL);
    if (unlikely(!array_obj)) {
        goto fail;
    }
    __Pyx_GOTREF(array_obj);
    memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
                                    (PyObject *) array_obj, contig_flag,
                                    dtype_is_object,
                                    from_mvs->memview->typeinfo);
    if (unlikely(!memview_obj))
        goto fail;
    if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0))
        goto fail;
    if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim,
                                                dtype_is_object) < 0))
        goto fail;
    goto no_fail;
fail:
    __Pyx_XDECREF(new_mvs.memview);
    new_mvs.memview = NULL;
    new_mvs.data = NULL;
no_fail:
    __Pyx_XDECREF(shape_tuple);
    __Pyx_XDECREF(temp_int);
    __Pyx_XDECREF(array_obj);
    __Pyx_RefNannyFinishContext();
    return new_mvs;
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int_t(int_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int_t neg_one = (int_t) -1, const_zero = (int_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int_t),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
  static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntFromPy */
  static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
  static CYTHON_INLINE int_t __Pyx_PyInt_As_int_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int_t neg_one = (int_t) -1, const_zero = (int_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(int_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) >= 2 * PyLong_SHIFT) {
                            return (int_t) (((((int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) >= 3 * PyLong_SHIFT) {
                            return (int_t) (((((((int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) >= 4 * PyLong_SHIFT) {
                            return (int_t) (((((((((int_t)digits[3]) << PyLong_SHIFT) | (int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int_t) (((int_t)-1)*(((((int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int_t) ((((((int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int_t) (((int_t)-1)*(((((((int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int_t) ((((((((int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int_t) (((int_t)-1)*(((((((((int_t)digits[3]) << PyLong_SHIFT) | (int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int_t) ((((((((((int_t)digits[3]) << PyLong_SHIFT) | (int_t)digits[2]) << PyLong_SHIFT) | (int_t)digits[1]) << PyLong_SHIFT) | (int_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int_t val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int_t) -1;
        }
    } else {
        int_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int_t) -1;
        val = __Pyx_PyInt_As_int_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int_t");
    return (int_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int_t");
    return (int_t) -1;
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int64(npy_int64 value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const npy_int64 neg_one = (npy_int64) -1, const_zero = (npy_int64) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(npy_int64) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(npy_int64) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int64) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(npy_int64) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int64) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(npy_int64),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
  static CYTHON_INLINE npy_int64 __Pyx_PyInt_As_npy_int64(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const npy_int64 neg_one = (npy_int64) -1, const_zero = (npy_int64) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(npy_int64) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(npy_int64, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (npy_int64) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_int64) 0;
                case  1: __PYX_VERIFY_RETURN_INT(npy_int64, digit, digits[0])
                case 2:
                    if (8 * sizeof(npy_int64) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) >= 2 * PyLong_SHIFT) {
                            return (npy_int64) (((((npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_int64) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) >= 3 * PyLong_SHIFT) {
                            return (npy_int64) (((((((npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_int64) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) >= 4 * PyLong_SHIFT) {
                            return (npy_int64) (((((((((npy_int64)digits[3]) << PyLong_SHIFT) | (npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (npy_int64) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(npy_int64) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int64, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_int64) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int64, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_int64) 0;
                case -1: __PYX_VERIFY_RETURN_INT(npy_int64, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(npy_int64,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(npy_int64) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_int64) (((npy_int64)-1)*(((((npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(npy_int64) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_int64) ((((((npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(npy_int64) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_int64) (((npy_int64)-1)*(((((((npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_int64) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_int64) ((((((((npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(npy_int64) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_int64) (((npy_int64)-1)*(((((((((npy_int64)digits[3]) << PyLong_SHIFT) | (npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_int64) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int64, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int64) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_int64) ((((((((((npy_int64)digits[3]) << PyLong_SHIFT) | (npy_int64)digits[2]) << PyLong_SHIFT) | (npy_int64)digits[1]) << PyLong_SHIFT) | (npy_int64)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(npy_int64) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int64, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_int64) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int64, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            npy_int64 val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (npy_int64) -1;
        }
    } else {
        npy_int64 val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (npy_int64) -1;
        val = __Pyx_PyInt_As_npy_int64(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to npy_int64");
    return (npy_int64) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to npy_int64");
    return (npy_int64) -1;
}

/* CIntFromPy */
  static CYTHON_INLINE npy_int8 __Pyx_PyInt_As_npy_int8(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const npy_int8 neg_one = (npy_int8) -1, const_zero = (npy_int8) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(npy_int8) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(npy_int8, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (npy_int8) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_int8) 0;
                case  1: __PYX_VERIFY_RETURN_INT(npy_int8, digit, digits[0])
                case 2:
                    if (8 * sizeof(npy_int8) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) >= 2 * PyLong_SHIFT) {
                            return (npy_int8) (((((npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_int8) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) >= 3 * PyLong_SHIFT) {
                            return (npy_int8) (((((((npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_int8) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) >= 4 * PyLong_SHIFT) {
                            return (npy_int8) (((((((((npy_int8)digits[3]) << PyLong_SHIFT) | (npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (npy_int8) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(npy_int8) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int8, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_int8) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int8, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (npy_int8) 0;
                case -1: __PYX_VERIFY_RETURN_INT(npy_int8, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(npy_int8,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(npy_int8) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_int8) (((npy_int8)-1)*(((((npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(npy_int8) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 2 * PyLong_SHIFT) {
                            return (npy_int8) ((((((npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(npy_int8) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_int8) (((npy_int8)-1)*(((((((npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(npy_int8) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 3 * PyLong_SHIFT) {
                            return (npy_int8) ((((((((npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(npy_int8) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_int8) (((npy_int8)-1)*(((((((((npy_int8)digits[3]) << PyLong_SHIFT) | (npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(npy_int8) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(npy_int8, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(npy_int8) - 1 > 4 * PyLong_SHIFT) {
                            return (npy_int8) ((((((((((npy_int8)digits[3]) << PyLong_SHIFT) | (npy_int8)digits[2]) << PyLong_SHIFT) | (npy_int8)digits[1]) << PyLong_SHIFT) | (npy_int8)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(npy_int8) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int8, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(npy_int8) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(npy_int8, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            npy_int8 val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (npy_int8) -1;
        }
    } else {
        npy_int8 val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (npy_int8) -1;
        val = __Pyx_PyInt_As_npy_int8(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to npy_int8");
    return (npy_int8) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to npy_int8");
    return (npy_int8) -1;
}

/* CIntToPy */
  static CYTHON_INLINE PyObject* __Pyx_PyInt_From_npy_int8(npy_int8 value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const npy_int8 neg_one = (npy_int8) -1, const_zero = (npy_int8) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(npy_int8) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(npy_int8) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int8) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(npy_int8) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(npy_int8) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(npy_int8),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
  static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

/* CIntFromPy */
  static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(char) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (char) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(char) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(char) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            char val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (char) -1;
        }
    } else {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* CheckBinaryVersion */
  static int __Pyx_check_binary_version(void) {
    char ctversion[5];
    int same=1, i, found_dot;
    const char* rt_from_call = Py_GetVersion();
    PyOS_snprintf(ctversion, 5, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    found_dot = 0;
    for (i = 0; i < 4; i++) {
        if (!ctversion[i]) {
            same = (rt_from_call[i] < '0' || rt_from_call[i] > '9');
            break;
        }
        if (rt_from_call[i] != ctversion[i]) {
            same = 0;
            break;
        }
    }
    if (!same) {
        char rtversion[5] = {'\0'};
        char message[200];
        for (i=0; i<4; ++i) {
            if (rt_from_call[i] == '.') {
                if (found_dot) break;
                found_dot = 1;
            } else if (rt_from_call[i] < '0' || rt_from_call[i] > '9') {
                break;
            }
            rtversion[i] = rt_from_call[i];
        }
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* FunctionImport */
  #ifndef __PYX_HAVE_RT_ImportFunction_0_29_35
#define __PYX_HAVE_RT_ImportFunction_0_29_35
static int __Pyx_ImportFunction_0_29_35(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
  static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
