/* Generated by Cython 0.28.4 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "/usr/lib/python3/dist-packages/numpy/core/include/numpy/arrayobject.h",
            "/usr/lib/python3/dist-packages/numpy/core/include/numpy/ufuncobject.h",
            "build.conf",
            "kwant/linalg/f_lapack.pxd"
        ],
        "include_dirs": [
            "/usr/lib/python3/dist-packages/numpy/core/include"
        ],
        "libraries": [
            "blas",
            "lapack"
        ],
        "name": "kwant.linalg.lapack",
        "sources": [
            "kwant/linalg/lapack.pyx"
        ],
        "undef_macros": [
            "NDEBUG"
        ]
    },
    "module_name": "kwant.linalg.lapack"
}
END: Cython Metadata */

#define 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_28_4"
#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
  #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
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 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
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #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 1
  #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
    #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
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#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 CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#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_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 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
#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)))))
#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_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; // PyThread_create_key reports success always
}
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 // TSS (Thread Specific Storage) API
#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
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #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)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#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)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? 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
  #define PyObject_Unicode             PyObject_Str
#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 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   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), 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(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#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_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; 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__kwant__linalg__lapack
#define __PYX_HAVE_API__kwant__linalg__lapack
/* Early includes */
#include <string.h>
#include <stdio.h>
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.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_DEFAULT 0
#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)))  )
#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 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);
#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));
    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[] = {
  "kwant/linalg/lapack.pyx",
  "__init__.pxd",
  "type.pxd",
};
/* 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;


/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":730
 * # 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":731
 * 
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":732
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":733
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":737
 * #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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":738
 * 
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":739
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":740
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":744
 * #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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":745
 * 
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":754
 * # 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":755
 * # 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":756
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":758
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":759
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":760
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":762
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":763
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":765
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":766
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":767
 * 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;

/* "f_lapack.pxd":9
 * # http://kwant-project.org/authors.
 * 
 * ctypedef int l_int             # <<<<<<<<<<<<<<
 * ctypedef int l_logical
 * 
 */
typedef int __pyx_t_5kwant_6linalg_8f_lapack_l_int;

/* "f_lapack.pxd":10
 * 
 * ctypedef int l_int
 * ctypedef int l_logical             # <<<<<<<<<<<<<<
 * 
 * cdef extern:
 */
typedef int __pyx_t_5kwant_6linalg_8f_lapack_l_logical;
/* 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 ---*/

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":769
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":770
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":771
 * 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;

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":773
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;

/* --- 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);

/* 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);

/* 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 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;
  #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 (unlikely(tstate->use_tracing) && !tstate->tracing &&\
                  (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
              __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 (unlikely(tstate->use_tracing) && !tstate->tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          __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 (unlikely(tstate->use_tracing) && !tstate->tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          __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 (tstate->use_tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          tstate->tracing++;\
          tstate->use_tracing = 0;\
          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);\
          }\
          tstate->use_tracing = 1;\
          tstate->tracing--;\
      }\
  }
  static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      tstate->tracing++;
      tstate->use_tracing = 0;
      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);
      tstate->use_tracing = 1;
      tstate->tracing--;
      __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 (tstate->use_tracing) {\
                  __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
              }\
              PyGILState_Release(state);\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (tstate->use_tracing) {\
              __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 (tstate->use_tracing) {\
          __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);
      tstate->tracing++;
      tstate->use_tracing = 0;
      ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
      tstate->use_tracing = 1;
      tstate->tracing--;
      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 (unlikely(tstate->use_tracing && 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 (unlikely(tstate->use_tracing && 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 (unlikely(tstate->use_tracing && 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

/* 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

/* 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);

/* 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);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

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

/* 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);

/* 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

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

/* 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);

/* 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);

/* BufferGetAndValidate.proto */
#define __Pyx_GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack)\
    ((obj == Py_None || obj == NULL) ?\
    (__Pyx_ZeroBuffer(buf), 0) :\
    __Pyx__GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack))
static int  __Pyx__GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static void __Pyx_ZeroBuffer(Py_buffer* buf);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static Py_ssize_t __Pyx_minusones[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
static Py_ssize_t __Pyx_zeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

/* 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, int nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#endif

/* 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);

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

/* BufferFallbackError.proto */
static void __Pyx_RaiseBufferFallbackError(void);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
    PyObject_RichCompare(op1, op2, Py_EQ)
    #endif

/* 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

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (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_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

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

/* 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);

/* 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);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

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

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

/* 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

/* 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

/* 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

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

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

/* CalculateMetaclass.proto */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);

/* Py3ClassCreate.proto */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
                                           PyObject *mkw, PyObject *modname, PyObject *doc);
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);

/* 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);

/* 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

/* 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;

#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


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

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value);

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

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

/* 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)

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

/* PyIdentifierFromString.proto */
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

/* ModuleImport.proto */
static PyObject *__Pyx_ImportModule(const char *name);

/* TypeImport.proto */
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

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


/* 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_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

/* Module declarations from 'kwant.linalg' */

/* Module declarations from 'kwant.linalg.f_lapack' */
__PYX_EXTERN_C DL_IMPORT(void) sgetrf_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dgetrf_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cgetrf_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zgetrf_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) sgetrs_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dgetrs_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cgetrs_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zgetrs_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) sgecon_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dgecon_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cgecon_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, __pyx_t_float_complex *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zgecon_(char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, __pyx_t_double_complex *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) sggev_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dggev_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cggev_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zggev_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) sgees_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(float *, float *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dgees_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(double *, double *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cgees_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(__pyx_t_float_complex *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zgees_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(__pyx_t_double_complex *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) strsen_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dtrsen_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ctrsen_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ztrsen_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) strevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dtrevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ctrevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ztrevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) sgges_(char *, char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(float *, float *, float *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dgges_(char *, char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(double *, double *, double *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) cgges_(char *, char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(__pyx_t_float_complex *, __pyx_t_float_complex *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) zgges_(char *, char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical (*)(__pyx_t_double_complex *, __pyx_t_double_complex *), __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) stgsen_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dtgsen_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ctgsen_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, float *, float *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ztgsen_(__pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, double *, double *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) stgevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) dtgevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ctgevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_float_complex *, float *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(void) ztgevc_(char *, char *, __pyx_t_5kwant_6linalg_8f_lapack_l_logical *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *, __pyx_t_double_complex *, double *, __pyx_t_5kwant_6linalg_8f_lapack_l_int *); /*proto*/

/* Module declarations from 'kwant.linalg.lapack' */
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t = { "float32_t", NULL, sizeof(__pyx_t_5numpy_float32_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int = { "l_int", NULL, sizeof(__pyx_t_5kwant_6linalg_8f_lapack_l_int), { 0 }, 0, IS_UNSIGNED(__pyx_t_5kwant_6linalg_8f_lapack_l_int) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5kwant_6linalg_8f_lapack_l_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___pyx_t_float_complex = { "float complex", NULL, sizeof(__pyx_t_float_complex), { 0 }, 0, 'C', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo___pyx_t_double_complex = { "double complex", NULL, sizeof(__pyx_t_double_complex), { 0 }, 0, 'C', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical = { "l_logical", NULL, sizeof(__pyx_t_5kwant_6linalg_8f_lapack_l_logical), { 0 }, 0, IS_UNSIGNED(__pyx_t_5kwant_6linalg_8f_lapack_l_logical) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5kwant_6linalg_8f_lapack_l_logical), 0 };
#define __Pyx_MODULE_NAME "kwant.linalg.lapack"
extern int __pyx_module_is_main_kwant__linalg__lapack;
int __pyx_module_is_main_kwant__linalg__lapack = 0;

/* Implementation of 'kwant.linalg.lapack' */
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_AssertionError;
static PyObject *__pyx_builtin_ImportError;
static const char __pyx_k_A[] = "A";
static const char __pyx_k_B[] = "B";
static const char __pyx_k_F[] = "F";
static const char __pyx_k_M[] = "M";
static const char __pyx_k_N[] = "N";
static const char __pyx_k_Q[] = "Q";
static const char __pyx_k_S[] = "S";
static const char __pyx_k_T[] = "T";
static const char __pyx_k_Z[] = "Z";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_d[] = "d";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_k[] = "k";
static const char __pyx_k_m[] = "m";
static const char __pyx_k_s[] = "s";
static const char __pyx_k_v[] = "v";
static const char __pyx_k_w[] = "w";
static const char __pyx_k_z[] = "z";
static const char __pyx_k_LU[] = "LU";
static const char __pyx_k_MM[] = "MM";
static const char __pyx_k_np[] = "np";
static const char __pyx_k_vl[] = "vl";
static const char __pyx_k_vr[] = "vr";
static const char __pyx_k_vs[] = "vs";
static const char __pyx_k_wi[] = "wi";
static const char __pyx_k_wr[] = "wr";
static const char __pyx_k_all[] = "__all__";
static const char __pyx_k_arg[] = "arg";
static const char __pyx_k_arr[] = "arr";
static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_dot[] = "dot";
static const char __pyx_k_mat[] = "mat";
static const char __pyx_k_ret[] = "ret";
static const char __pyx_k_sel[] = "sel";
static const char __pyx_k_vsl[] = "vsl";
static const char __pyx_k_vsr[] = "vsr";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_IPIV[] = "IPIV";
static const char __pyx_k_NRHS[] = "NRHS";
static const char __pyx_k__106[] = "";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_beta[] = "beta";
static const char __pyx_k_conj[] = "conj";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_ijob[] = "ijob";
static const char __pyx_k_imag[] = "imag";
static const char __pyx_k_indx[] = "indx";
static const char __pyx_k_info[] = "info";
static const char __pyx_k_ipiv[] = "ipiv";
static const char __pyx_k_left[] = "left";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mats[] = "mats";
static const char __pyx_k_ndim[] = "ndim";
static const char __pyx_k_norm[] = "norm";
static const char __pyx_k_ones[] = "ones";
static const char __pyx_k_sdim[] = "sdim";
static const char __pyx_k_side[] = "side";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_vl_r[] = "vl_r";
static const char __pyx_k_vr_r[] = "vr_r";
static const char __pyx_k_work[] = "work";
static const char __pyx_k_alpha[] = "alpha";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_cgees[] = "cgees";
static const char __pyx_k_cgges[] = "cgges";
static const char __pyx_k_cggev[] = "cggev";
static const char __pyx_k_compq[] = "compq";
static const char __pyx_k_dgees[] = "dgees";
static const char __pyx_k_dgges[] = "dgges";
static const char __pyx_k_dggev[] = "dggev";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_flags[] = "flags";
static const char __pyx_k_iwork[] = "iwork";
static const char __pyx_k_jobvl[] = "jobvl";
static const char __pyx_k_jobvr[] = "jobvr";
static const char __pyx_k_jobvs[] = "jobvs";
static const char __pyx_k_lwork[] = "lwork";
static const char __pyx_k_normA[] = "normA";
static const char __pyx_k_npmat[] = "npmat";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_order[] = "order";
static const char __pyx_k_ovwrt[] = "ovwrt";
static const char __pyx_k_q_ptr[] = "q_ptr";
static const char __pyx_k_qwork[] = "qwork";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_rcond[] = "rcond";
static const char __pyx_k_right[] = "right";
static const char __pyx_k_rwork[] = "rwork";
static const char __pyx_k_sgees[] = "sgees";
static const char __pyx_k_sgges[] = "sgges";
static const char __pyx_k_sggev[] = "sggev";
static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_vreal[] = "vreal";
static const char __pyx_k_wantq[] = "wantq";
static const char __pyx_k_wantz[] = "wantz";
static const char __pyx_k_z_ptr[] = "z_ptr";
static const char __pyx_k_zgees[] = "zgees";
static const char __pyx_k_zgges[] = "zgges";
static const char __pyx_k_zggev[] = "zggev";
static const char __pyx_k_alphai[] = "alphai";
static const char __pyx_k_alphar[] = "alphar";
static const char __pyx_k_astype[] = "astype";
static const char __pyx_k_backtr[] = "backtr";
static const char __pyx_k_calc_q[] = "calc_q";
static const char __pyx_k_calc_z[] = "calc_z";
static const char __pyx_k_cgecon[] = "cgecon";
static const char __pyx_k_cgetrf[] = "cgetrf";
static const char __pyx_k_cgetrs[] = "cgetrs";
static const char __pyx_k_ctgevc[] = "ctgevc";
static const char __pyx_k_ctgsen[] = "ctgsen";
static const char __pyx_k_ctrevc[] = "ctrevc";
static const char __pyx_k_ctrsen[] = "ctrsen";
static const char __pyx_k_dgecon[] = "dgecon";
static const char __pyx_k_dgetrf[] = "dgetrf";
static const char __pyx_k_dgetrs[] = "dgetrs";
static const char __pyx_k_dtgevc[] = "dtgevc";
static const char __pyx_k_dtgsen[] = "dtgsen";
static const char __pyx_k_dtrevc[] = "dtrevc";
static const char __pyx_k_dtrsen[] = "dtrsen";
static const char __pyx_k_howmny[] = "howmny";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_jobvsl[] = "jobvsl";
static const char __pyx_k_jobvsr[] = "jobvsr";
static const char __pyx_k_liwork[] = "liwork";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_number[] = "number";
static const char __pyx_k_qiwork[] = "qiwork";
static const char __pyx_k_select[] = "select";
static const char __pyx_k_sgecon[] = "sgecon";
static const char __pyx_k_sgetrf[] = "sgetrf";
static const char __pyx_k_sgetrs[] = "sgetrs";
static const char __pyx_k_stgevc[] = "stgevc";
static const char __pyx_k_stgsen[] = "stgsen";
static const char __pyx_k_strevc[] = "strevc";
static const char __pyx_k_strsen[] = "strsen";
static const char __pyx_k_vl_ptr[] = "vl_ptr";
static const char __pyx_k_vr_ptr[] = "vr_ptr";
static const char __pyx_k_vs_ptr[] = "vs_ptr";
static const char __pyx_k_zgecon[] = "zgecon";
static const char __pyx_k_zgetrf[] = "zgetrf";
static const char __pyx_k_zgetrs[] = "zgetrs";
static const char __pyx_k_ztgevc[] = "ztgevc";
static const char __pyx_k_ztgsen[] = "ztgsen";
static const char __pyx_k_ztrevc[] = "ztrevc";
static const char __pyx_k_ztrsen[] = "ztrsen";
static const char __pyx_k_calc_ev[] = "calc_ev";
static const char __pyx_k_float32[] = "float32";
static const char __pyx_k_float64[] = "float64";
static const char __pyx_k_nonzero[] = "nonzero";
static const char __pyx_k_prepare[] = "__prepare__";
static const char __pyx_k_selindx[] = "selindx";
static const char __pyx_k_vsl_ptr[] = "vsl_ptr";
static const char __pyx_k_vsr_ptr[] = "vsr_ptr";
static const char __pyx_k_diagonal[] = "diagonal";
static const char __pyx_k_f_lapack[] = "f_lapack";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_vl_r_ptr[] = "vl_r_ptr";
static const char __pyx_k_vr_r_ptr[] = "vr_r_ptr";
static const char __pyx_k_cmplxindx[] = "cmplxindx";
static const char __pyx_k_complex64[] = "complex64";
static const char __pyx_k_int_dtype[] = "int_dtype";
static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_overwrite[] = "overwrite";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_asanyarray[] = "asanyarray";
static const char __pyx_k_complex128[] = "complex128";
static const char __pyx_k_issubdtype[] = "issubdtype";
static const char __pyx_k_lapacktype[] = "lapacktype";
static const char __pyx_k_select_cpy[] = "select_cpy";
static const char __pyx_k_select_ptr[] = "select_ptr";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_LinAlgError[] = "LinAlgError";
static const char __pyx_k_common_type[] = "common_type";
static const char __pyx_k_filter_args[] = "filter_args";
static const char __pyx_k_l_int_dtype[] = "l_int_dtype";
static const char __pyx_k_C_CONTIGUOUS[] = "C_CONTIGUOUS";
static const char __pyx_k_F_CONTIGUOUS[] = "F_CONTIGUOUS";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_logical_dtype[] = "logical_dtype";
static const char __pyx_k_AssertionError[] = "AssertionError";
static const char __pyx_k_asfortranarray[] = "asfortranarray";
static const char __pyx_k_l_logical_dtype[] = "l_logical_dtype";
static const char __pyx_k_ggev_postprocess[] = "ggev_postprocess";
static const char __pyx_k_ascontiguousarray[] = "ascontiguousarray";
static const char __pyx_k_txevc_postprocess[] = "txevc_postprocess";
static const char __pyx_k_assert_fortran_mat[] = "assert_fortran_mat";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_prepare_for_lapack[] = "prepare_for_lapack";
static const char __pyx_k_kwant_linalg_lapack[] = "kwant.linalg.lapack";
static const char __pyx_k_Argument_error_in_cgees[] = "Argument error in cgees";
static const char __pyx_k_Argument_error_in_cggev[] = "Argument error in cggev";
static const char __pyx_k_Argument_error_in_dgees[] = "Argument error in dgees";
static const char __pyx_k_Argument_error_in_dggev[] = "Argument error in dggev";
static const char __pyx_k_Argument_error_in_sgees[] = "Argument error in sgees";
static const char __pyx_k_Argument_error_in_sggev[] = "Argument error in sggev";
static const char __pyx_k_Argument_error_in_zgees[] = "Argument error in zgees";
static const char __pyx_k_Argument_error_in_zggev[] = "Argument error in zggev";
static const char __pyx_k_kwant_linalg_lapack_pyx[] = "kwant/linalg/lapack.pyx";
static const char __pyx_k_Argument_error_in_cgecon[] = "Argument error in cgecon";
static const char __pyx_k_Argument_error_in_cgetrf[] = "Argument error in cgetrf";
static const char __pyx_k_Argument_error_in_cgetrs[] = "Argument error in cgetrs";
static const char __pyx_k_Argument_error_in_ctgevc[] = "Argument error in ctgevc";
static const char __pyx_k_Argument_error_in_ctgsen[] = "Argument error in ctgsen";
static const char __pyx_k_Argument_error_in_ctrevc[] = "Argument error in ctrevc";
static const char __pyx_k_Argument_error_in_ctrsen[] = "Argument error in ctrsen";
static const char __pyx_k_Argument_error_in_dgecon[] = "Argument error in dgecon";
static const char __pyx_k_Argument_error_in_dgetrf[] = "Argument error in dgetrf";
static const char __pyx_k_Argument_error_in_dgetrs[] = "Argument error in dgetrs";
static const char __pyx_k_Argument_error_in_dtgevc[] = "Argument error in dtgevc";
static const char __pyx_k_Argument_error_in_dtgsen[] = "Argument error in dtgsen";
static const char __pyx_k_Argument_error_in_dtrevc[] = "Argument error in dtrevc";
static const char __pyx_k_Argument_error_in_dtrsen[] = "Argument error in dtrsen";
static const char __pyx_k_Argument_error_in_sgecon[] = "Argument error in sgecon";
static const char __pyx_k_Argument_error_in_sgetrf[] = "Argument error in sgetrf";
static const char __pyx_k_Argument_error_in_sgetrs[] = "Argument error in sgetrs";
static const char __pyx_k_Argument_error_in_stgevc[] = "Argument error in stgevc";
static const char __pyx_k_Argument_error_in_stgsen[] = "Argument error in stgsen";
static const char __pyx_k_Argument_error_in_strevc[] = "Argument error in strevc";
static const char __pyx_k_Argument_error_in_strsen[] = "Argument error in strsen";
static const char __pyx_k_Argument_error_in_zgecon[] = "Argument error in zgecon";
static const char __pyx_k_Argument_error_in_zgetrf[] = "Argument error in zgetrf";
static const char __pyx_k_Argument_error_in_zgetrs[] = "Argument error in zgetrs";
static const char __pyx_k_Argument_error_in_ztgevc[] = "Argument error in ztgevc";
static const char __pyx_k_Argument_error_in_ztgsen[] = "Argument error in ztgsen";
static const char __pyx_k_Argument_error_in_ztrevc[] = "Argument error in ztrevc";
static const char __pyx_k_Argument_error_in_ztrsen[] = "Argument error in ztrsen";
static const char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static const char __pyx_k_In_cgetrs_B_must_be_a_vector_or[] = "In cgetrs: B must be a vector or matrix";
static const char __pyx_k_In_dgetrs_B_must_be_a_vector_or[] = "In dgetrs: B must be a vector or matrix";
static const char __pyx_k_In_sgetrs_B_must_be_a_vector_or[] = "In sgetrs: B must be a vector or matrix";
static const char __pyx_k_In_zgetrs_B_must_be_a_vector_or[] = "In zgetrs: B must be a vector or matrix";
static const char __pyx_k_QR_iteration_failed_to_converge[] = "QR iteration failed to converge in sgees";
static const char __pyx_k_QZ_iteration_failed_to_converge[] = "QZ iteration failed to converge in sggev";
static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import";
static const char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static const char __pyx_k_Argument_cannot_be_interpreted_a[] = "Argument cannot be interpreted as a numeric array";
static const char __pyx_k_Dimensionality_of_array_is_not_1[] = "Dimensionality of array is not 1 or 2";
static const char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static const char __pyx_k_In_dgetrs_B_must_be_a_Fortran_or[] = "In dgetrs: B must be a Fortran ordered NumPy array";
static const char __pyx_k_Input_matrix_must_be_Fortran_con[] = "Input matrix must be Fortran contiguous";
static const char __pyx_k_Low_level_access_to_LAPACK_funct[] = "Low-level access to LAPACK functions. ";
static const char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported";
static const char __pyx_k_Reordering_failed_problem_is_ver[] = "Reordering failed; problem is very ill-conditioned";
static const char __pyx_k_Unexpected_data_type_from_common[] = "Unexpected data type from common_type";
static const char __pyx_k_Unexpected_number_of_eigenvector[] = "Unexpected number of eigenvectors returned in strevc";
static const char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous";
static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import";
static const char __pyx_k_QR_iteration_failed_to_converge_2[] = "QR iteration failed to converge in dgees";
static const char __pyx_k_QR_iteration_failed_to_converge_3[] = "QR iteration failed to converge in cgees";
static const char __pyx_k_QR_iteration_failed_to_converge_4[] = "QR iteration failed to converge in zgees";
static const char __pyx_k_QZ_iteration_failed_to_converge_2[] = "QZ iteration failed to converge in dggev";
static const char __pyx_k_QZ_iteration_failed_to_converge_3[] = "QZ iteration failed to converge in cggev";
static const char __pyx_k_QZ_iteration_failed_to_converge_4[] = "QZ iteration failed to converge in zggev";
static const char __pyx_k_QZ_iteration_failed_to_converge_5[] = "QZ iteration failed to converge in sgges";
static const char __pyx_k_QZ_iteration_failed_to_converge_6[] = "QZ iteration failed to converge in dgges";
static const char __pyx_k_QZ_iteration_failed_to_converge_7[] = "QZ iteration failed to converge in cgges";
static const char __pyx_k_QZ_iteration_failed_to_converge_8[] = "QZ iteration failed to converge in zgges";
static const char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short.";
static const char __pyx_k_Unexpected_number_of_eigenvector_2[] = "Unexpected number of eigenvectors returned in dtrevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_3[] = "Unexpected number of eigenvectors returned in ctrevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_4[] = "Unexpected number of eigenvectors returned in ztrevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_5[] = "Unexpected number of eigenvectors returned in stgevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_6[] = "Unexpected number of eigenvectors returned in dtgevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_7[] = "Unexpected number of eigenvectors returned in ctgevc";
static const char __pyx_k_Unexpected_number_of_eigenvector_8[] = "Unexpected number of eigenvectors returned in ztgevc";
static PyObject *__pyx_n_s_A;
static PyObject *__pyx_kp_u_Argument_cannot_be_interpreted_a;
static PyObject *__pyx_kp_u_Argument_error_in_cgecon;
static PyObject *__pyx_kp_u_Argument_error_in_cgees;
static PyObject *__pyx_kp_u_Argument_error_in_cgetrf;
static PyObject *__pyx_kp_u_Argument_error_in_cgetrs;
static PyObject *__pyx_kp_u_Argument_error_in_cggev;
static PyObject *__pyx_kp_u_Argument_error_in_ctgevc;
static PyObject *__pyx_kp_u_Argument_error_in_ctgsen;
static PyObject *__pyx_kp_u_Argument_error_in_ctrevc;
static PyObject *__pyx_kp_u_Argument_error_in_ctrsen;
static PyObject *__pyx_kp_u_Argument_error_in_dgecon;
static PyObject *__pyx_kp_u_Argument_error_in_dgees;
static PyObject *__pyx_kp_u_Argument_error_in_dgetrf;
static PyObject *__pyx_kp_u_Argument_error_in_dgetrs;
static PyObject *__pyx_kp_u_Argument_error_in_dggev;
static PyObject *__pyx_kp_u_Argument_error_in_dtgevc;
static PyObject *__pyx_kp_u_Argument_error_in_dtgsen;
static PyObject *__pyx_kp_u_Argument_error_in_dtrevc;
static PyObject *__pyx_kp_u_Argument_error_in_dtrsen;
static PyObject *__pyx_kp_u_Argument_error_in_sgecon;
static PyObject *__pyx_kp_u_Argument_error_in_sgees;
static PyObject *__pyx_kp_u_Argument_error_in_sgetrf;
static PyObject *__pyx_kp_u_Argument_error_in_sgetrs;
static PyObject *__pyx_kp_u_Argument_error_in_sggev;
static PyObject *__pyx_kp_u_Argument_error_in_stgevc;
static PyObject *__pyx_kp_u_Argument_error_in_stgsen;
static PyObject *__pyx_kp_u_Argument_error_in_strevc;
static PyObject *__pyx_kp_u_Argument_error_in_strsen;
static PyObject *__pyx_kp_u_Argument_error_in_zgecon;
static PyObject *__pyx_kp_u_Argument_error_in_zgees;
static PyObject *__pyx_kp_u_Argument_error_in_zgetrf;
static PyObject *__pyx_kp_u_Argument_error_in_zgetrs;
static PyObject *__pyx_kp_u_Argument_error_in_zggev;
static PyObject *__pyx_kp_u_Argument_error_in_ztgevc;
static PyObject *__pyx_kp_u_Argument_error_in_ztgsen;
static PyObject *__pyx_kp_u_Argument_error_in_ztrevc;
static PyObject *__pyx_kp_u_Argument_error_in_ztrsen;
static PyObject *__pyx_n_s_AssertionError;
static PyObject *__pyx_n_s_B;
static PyObject *__pyx_n_u_C_CONTIGUOUS;
static PyObject *__pyx_kp_u_Dimensionality_of_array_is_not_1;
static PyObject *__pyx_n_u_F;
static PyObject *__pyx_n_u_F_CONTIGUOUS;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2;
static PyObject *__pyx_n_s_IPIV;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_kp_u_In_cgetrs_B_must_be_a_vector_or;
static PyObject *__pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or;
static PyObject *__pyx_kp_u_In_dgetrs_B_must_be_a_vector_or;
static PyObject *__pyx_kp_u_In_sgetrs_B_must_be_a_vector_or;
static PyObject *__pyx_kp_u_In_zgetrs_B_must_be_a_vector_or;
static PyObject *__pyx_kp_u_Input_matrix_must_be_Fortran_con;
static PyObject *__pyx_n_s_LU;
static PyObject *__pyx_n_s_LinAlgError;
static PyObject *__pyx_n_s_M;
static PyObject *__pyx_n_s_MM;
static PyObject *__pyx_n_s_N;
static PyObject *__pyx_n_s_NRHS;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_Q;
static PyObject *__pyx_kp_u_QR_iteration_failed_to_converge;
static PyObject *__pyx_kp_u_QR_iteration_failed_to_converge_2;
static PyObject *__pyx_kp_u_QR_iteration_failed_to_converge_3;
static PyObject *__pyx_kp_u_QR_iteration_failed_to_converge_4;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_2;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_3;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_4;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_5;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_6;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_7;
static PyObject *__pyx_kp_u_QZ_iteration_failed_to_converge_8;
static PyObject *__pyx_kp_u_Reordering_failed_problem_is_ver;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_s_S;
static PyObject *__pyx_n_s_T;
static PyObject *__pyx_kp_u_Unexpected_data_type_from_common;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_2;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_3;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_4;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_5;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_6;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_7;
static PyObject *__pyx_kp_u_Unexpected_number_of_eigenvector_8;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_Z;
static PyObject *__pyx_n_s__106;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_alpha;
static PyObject *__pyx_n_s_alphai;
static PyObject *__pyx_n_s_alphar;
static PyObject *__pyx_n_s_arg;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_arr;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_asanyarray;
static PyObject *__pyx_n_s_ascontiguousarray;
static PyObject *__pyx_n_s_asfortranarray;
static PyObject *__pyx_n_s_assert_fortran_mat;
static PyObject *__pyx_n_s_astype;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_backtr;
static PyObject *__pyx_n_s_beta;
static PyObject *__pyx_n_u_c;
static PyObject *__pyx_n_s_calc_ev;
static PyObject *__pyx_n_s_calc_q;
static PyObject *__pyx_n_s_calc_z;
static PyObject *__pyx_n_s_cgecon;
static PyObject *__pyx_n_u_cgecon;
static PyObject *__pyx_n_s_cgees;
static PyObject *__pyx_n_u_cgees;
static PyObject *__pyx_n_s_cgetrf;
static PyObject *__pyx_n_u_cgetrf;
static PyObject *__pyx_n_s_cgetrs;
static PyObject *__pyx_n_u_cgetrs;
static PyObject *__pyx_n_s_cgges;
static PyObject *__pyx_n_u_cgges;
static PyObject *__pyx_n_s_cggev;
static PyObject *__pyx_n_u_cggev;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_cmplxindx;
static PyObject *__pyx_n_s_common_type;
static PyObject *__pyx_n_s_complex128;
static PyObject *__pyx_n_s_complex64;
static PyObject *__pyx_n_s_compq;
static PyObject *__pyx_n_s_conj;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_ctgevc;
static PyObject *__pyx_n_u_ctgevc;
static PyObject *__pyx_n_s_ctgsen;
static PyObject *__pyx_n_u_ctgsen;
static PyObject *__pyx_n_s_ctrevc;
static PyObject *__pyx_n_u_ctrevc;
static PyObject *__pyx_n_s_ctrsen;
static PyObject *__pyx_n_u_ctrsen;
static PyObject *__pyx_n_u_d;
static PyObject *__pyx_n_s_dgecon;
static PyObject *__pyx_n_u_dgecon;
static PyObject *__pyx_n_s_dgees;
static PyObject *__pyx_n_u_dgees;
static PyObject *__pyx_n_s_dgetrf;
static PyObject *__pyx_n_u_dgetrf;
static PyObject *__pyx_n_s_dgetrs;
static PyObject *__pyx_n_u_dgetrs;
static PyObject *__pyx_n_s_dgges;
static PyObject *__pyx_n_u_dgges;
static PyObject *__pyx_n_s_dggev;
static PyObject *__pyx_n_u_dggev;
static PyObject *__pyx_n_s_diagonal;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_s_dot;
static PyObject *__pyx_n_s_dtgevc;
static PyObject *__pyx_n_u_dtgevc;
static PyObject *__pyx_n_s_dtgsen;
static PyObject *__pyx_n_u_dtgsen;
static PyObject *__pyx_n_s_dtrevc;
static PyObject *__pyx_n_u_dtrevc;
static PyObject *__pyx_n_s_dtrsen;
static PyObject *__pyx_n_u_dtrsen;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_f_lapack;
static PyObject *__pyx_n_s_filter_args;
static PyObject *__pyx_n_s_flags;
static PyObject *__pyx_n_s_float32;
static PyObject *__pyx_n_s_float64;
static PyObject *__pyx_n_s_ggev_postprocess;
static PyObject *__pyx_n_s_howmny;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_ijob;
static PyObject *__pyx_n_s_imag;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indx;
static PyObject *__pyx_n_s_info;
static PyObject *__pyx_n_s_int_dtype;
static PyObject *__pyx_n_s_ipiv;
static PyObject *__pyx_n_s_issubdtype;
static PyObject *__pyx_n_s_iwork;
static PyObject *__pyx_n_s_jobvl;
static PyObject *__pyx_n_s_jobvr;
static PyObject *__pyx_n_s_jobvs;
static PyObject *__pyx_n_s_jobvsl;
static PyObject *__pyx_n_s_jobvsr;
static PyObject *__pyx_n_s_k;
static PyObject *__pyx_n_s_kwant_linalg_lapack;
static PyObject *__pyx_kp_s_kwant_linalg_lapack_pyx;
static PyObject *__pyx_n_s_l_int_dtype;
static PyObject *__pyx_n_s_l_logical_dtype;
static PyObject *__pyx_n_s_lapacktype;
static PyObject *__pyx_n_s_left;
static PyObject *__pyx_n_s_liwork;
static PyObject *__pyx_n_s_logical_dtype;
static PyObject *__pyx_n_s_lwork;
static PyObject *__pyx_n_s_m;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_mat;
static PyObject *__pyx_n_s_mats;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous;
static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou;
static PyObject *__pyx_n_s_ndim;
static PyObject *__pyx_n_s_nonzero;
static PyObject *__pyx_n_s_norm;
static PyObject *__pyx_n_s_normA;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_npmat;
static PyObject *__pyx_n_s_number;
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_ones;
static PyObject *__pyx_n_s_order;
static PyObject *__pyx_n_s_overwrite;
static PyObject *__pyx_n_s_ovwrt;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_prepare_for_lapack;
static PyObject *__pyx_n_u_prepare_for_lapack;
static PyObject *__pyx_n_s_q_ptr;
static PyObject *__pyx_n_s_qiwork;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_qwork;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rcond;
static PyObject *__pyx_n_s_ret;
static PyObject *__pyx_n_s_right;
static PyObject *__pyx_n_s_rwork;
static PyObject *__pyx_n_u_s;
static PyObject *__pyx_n_s_sdim;
static PyObject *__pyx_n_s_sel;
static PyObject *__pyx_n_s_select;
static PyObject *__pyx_n_s_select_cpy;
static PyObject *__pyx_n_s_select_ptr;
static PyObject *__pyx_n_s_selindx;
static PyObject *__pyx_n_s_sgecon;
static PyObject *__pyx_n_u_sgecon;
static PyObject *__pyx_n_s_sgees;
static PyObject *__pyx_n_u_sgees;
static PyObject *__pyx_n_s_sgetrf;
static PyObject *__pyx_n_u_sgetrf;
static PyObject *__pyx_n_s_sgetrs;
static PyObject *__pyx_n_u_sgetrs;
static PyObject *__pyx_n_s_sgges;
static PyObject *__pyx_n_u_sgges;
static PyObject *__pyx_n_s_sggev;
static PyObject *__pyx_n_u_sggev;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_side;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_stgevc;
static PyObject *__pyx_n_u_stgevc;
static PyObject *__pyx_n_s_stgsen;
static PyObject *__pyx_n_u_stgsen;
static PyObject *__pyx_n_s_strevc;
static PyObject *__pyx_n_u_strevc;
static PyObject *__pyx_n_s_strsen;
static PyObject *__pyx_n_u_strsen;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_txevc_postprocess;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_v;
static PyObject *__pyx_n_s_vl;
static PyObject *__pyx_n_s_vl_ptr;
static PyObject *__pyx_n_s_vl_r;
static PyObject *__pyx_n_s_vl_r_ptr;
static PyObject *__pyx_n_s_vr;
static PyObject *__pyx_n_s_vr_ptr;
static PyObject *__pyx_n_s_vr_r;
static PyObject *__pyx_n_s_vr_r_ptr;
static PyObject *__pyx_n_s_vreal;
static PyObject *__pyx_n_s_vs;
static PyObject *__pyx_n_s_vs_ptr;
static PyObject *__pyx_n_s_vsl;
static PyObject *__pyx_n_s_vsl_ptr;
static PyObject *__pyx_n_s_vsr;
static PyObject *__pyx_n_s_vsr_ptr;
static PyObject *__pyx_n_s_w;
static PyObject *__pyx_n_s_wantq;
static PyObject *__pyx_n_s_wantz;
static PyObject *__pyx_n_s_wi;
static PyObject *__pyx_n_s_work;
static PyObject *__pyx_n_s_wr;
static PyObject *__pyx_n_u_z;
static PyObject *__pyx_n_s_z_ptr;
static PyObject *__pyx_n_s_zgecon;
static PyObject *__pyx_n_u_zgecon;
static PyObject *__pyx_n_s_zgees;
static PyObject *__pyx_n_u_zgees;
static PyObject *__pyx_n_s_zgetrf;
static PyObject *__pyx_n_u_zgetrf;
static PyObject *__pyx_n_s_zgetrs;
static PyObject *__pyx_n_u_zgetrs;
static PyObject *__pyx_n_s_zgges;
static PyObject *__pyx_n_u_zgges;
static PyObject *__pyx_n_s_zggev;
static PyObject *__pyx_n_u_zggev;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_n_s_ztgevc;
static PyObject *__pyx_n_u_ztgevc;
static PyObject *__pyx_n_s_ztgsen;
static PyObject *__pyx_n_u_ztgsen;
static PyObject *__pyx_n_s_ztrevc;
static PyObject *__pyx_n_u_ztrevc;
static PyObject *__pyx_n_s_ztrsen;
static PyObject *__pyx_n_u_ztrsen;
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_filter_args(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_select, PyObject *__pyx_v_args); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_2assert_fortran_mat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mats); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_4sgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_6dgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_8cgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_10zgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_12sgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_14dgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_16cgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_18zgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_20sgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, float __pyx_v_normA, char *__pyx_v_norm); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_22dgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, double __pyx_v_normA, char *__pyx_v_norm); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_24cgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, float __pyx_v_normA, char *__pyx_v_norm); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_26zgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, double __pyx_v_normA, char *__pyx_v_norm); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_28ggev_postprocess(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtype, PyObject *__pyx_v_alphar, PyObject *__pyx_v_alphai, PyObject *__pyx_v_vl_r, PyObject *__pyx_v_vr_r); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_30sggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_32dggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_34cggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_36zggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_38sgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_40dgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_42cgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_44zgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_46strsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_48dtrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_50ctrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_52ztrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_54txevc_postprocess(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtype, PyObject *__pyx_v_T, PyObject *__pyx_v_vreal, PyArrayObject *__pyx_v_select); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_56strevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_58dtrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_60ctrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_62ztrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_64sgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_66dgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_68cgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_70zgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_72stgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_74dtgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_76ctgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_78ztgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_80stgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_82dtgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_84ctgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_86ztgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right); /* proto */
static PyObject *__pyx_pf_5kwant_6linalg_6lapack_88prepare_for_lapack(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_overwrite, PyObject *__pyx_v_args); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_float_0_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_codeobj_;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__25;
static PyObject *__pyx_slice__26;
static PyObject *__pyx_slice__27;
static PyObject *__pyx_slice__28;
static PyObject *__pyx_slice__29;
static PyObject *__pyx_slice__30;
static PyObject *__pyx_slice__31;
static PyObject *__pyx_slice__32;
static PyObject *__pyx_slice__60;
static PyObject *__pyx_slice__61;
static PyObject *__pyx_slice__62;
static PyObject *__pyx_slice__63;
static PyObject *__pyx_slice__64;
static PyObject *__pyx_slice__65;
static PyObject *__pyx_slice__66;
static PyObject *__pyx_slice__67;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_tuple__83;
static PyObject *__pyx_tuple__85;
static PyObject *__pyx_tuple__87;
static PyObject *__pyx_tuple__93;
static PyObject *__pyx_tuple__94;
static PyObject *__pyx_tuple__95;
static PyObject *__pyx_tuple__96;
static PyObject *__pyx_tuple__97;
static PyObject *__pyx_tuple__98;
static PyObject *__pyx_tuple__99;
static PyObject *__pyx_codeobj__2;
static PyObject *__pyx_codeobj__4;
static PyObject *__pyx_codeobj__5;
static PyObject *__pyx_codeobj__6;
static PyObject *__pyx_codeobj__7;
static PyObject *__pyx_codeobj__8;
static PyObject *__pyx_tuple__100;
static PyObject *__pyx_tuple__101;
static PyObject *__pyx_tuple__102;
static PyObject *__pyx_tuple__103;
static PyObject *__pyx_tuple__104;
static PyObject *__pyx_tuple__105;
static PyObject *__pyx_tuple__107;
static PyObject *__pyx_tuple__108;
static PyObject *__pyx_tuple__109;
static PyObject *__pyx_tuple__110;
static PyObject *__pyx_tuple__111;
static PyObject *__pyx_tuple__112;
static PyObject *__pyx_tuple__113;
static PyObject *__pyx_tuple__114;
static PyObject *__pyx_tuple__115;
static PyObject *__pyx_tuple__116;
static PyObject *__pyx_tuple__117;
static PyObject *__pyx_tuple__118;
static PyObject *__pyx_tuple__119;
static PyObject *__pyx_tuple__120;
static PyObject *__pyx_tuple__121;
static PyObject *__pyx_tuple__122;
static PyObject *__pyx_tuple__123;
static PyObject *__pyx_tuple__124;
static PyObject *__pyx_tuple__125;
static PyObject *__pyx_tuple__126;
static PyObject *__pyx_tuple__127;
static PyObject *__pyx_tuple__128;
static PyObject *__pyx_tuple__129;
static PyObject *__pyx_tuple__130;
static PyObject *__pyx_tuple__131;
static PyObject *__pyx_tuple__132;
static PyObject *__pyx_tuple__133;
static PyObject *__pyx_tuple__134;
static PyObject *__pyx_tuple__135;
static PyObject *__pyx_tuple__136;
static PyObject *__pyx_tuple__137;
static PyObject *__pyx_tuple__138;
static PyObject *__pyx_tuple__139;
static PyObject *__pyx_tuple__140;
static PyObject *__pyx_tuple__141;
static PyObject *__pyx_tuple__142;
static PyObject *__pyx_tuple__143;
static PyObject *__pyx_tuple__144;
static PyObject *__pyx_tuple__145;
static PyObject *__pyx_tuple__146;
static PyObject *__pyx_tuple__147;
static PyObject *__pyx_tuple__148;
static PyObject *__pyx_tuple__149;
static PyObject *__pyx_tuple__150;
static PyObject *__pyx_tuple__151;
static PyObject *__pyx_tuple__152;
static PyObject *__pyx_codeobj__11;
static PyObject *__pyx_codeobj__14;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__20;
static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__22;
static PyObject *__pyx_codeobj__23;
static PyObject *__pyx_codeobj__24;
static PyObject *__pyx_codeobj__33;
static PyObject *__pyx_codeobj__35;
static PyObject *__pyx_codeobj__37;
static PyObject *__pyx_codeobj__40;
static PyObject *__pyx_codeobj__43;
static PyObject *__pyx_codeobj__45;
static PyObject *__pyx_codeobj__47;
static PyObject *__pyx_codeobj__49;
static PyObject *__pyx_codeobj__51;
static PyObject *__pyx_codeobj__53;
static PyObject *__pyx_codeobj__55;
static PyObject *__pyx_codeobj__57;
static PyObject *__pyx_codeobj__59;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__69;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__71;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__76;
static PyObject *__pyx_codeobj__78;
static PyObject *__pyx_codeobj__80;
static PyObject *__pyx_codeobj__82;
static PyObject *__pyx_codeobj__84;
static PyObject *__pyx_codeobj__86;
static PyObject *__pyx_codeobj__88;
static PyObject *__pyx_codeobj__89;
static PyObject *__pyx_codeobj__90;
static PyObject *__pyx_codeobj__91;
static PyObject *__pyx_codeobj__92;
/* Late includes */

/* "kwant/linalg/lapack.pyx":42
 * 
 * # some helper functions
 * def filter_args(select, args):             # <<<<<<<<<<<<<<
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_1filter_args(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_1filter_args = {"filter_args", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_1filter_args, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_1filter_args(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_select = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("filter_args (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_args,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_select)) != 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_args)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("filter_args", 1, 2, 2, 1); __PYX_ERR(0, 42, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "filter_args") < 0)) __PYX_ERR(0, 42, __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_select = values[0];
    __pyx_v_args = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("filter_args", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 42, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.filter_args", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_filter_args(__pyx_self, __pyx_v_select, __pyx_v_args);

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

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_filter_args(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_select, PyObject *__pyx_v_args) {
  PyObject *__pyx_7genexpr__pyx_v_sel = NULL;
  PyObject *__pyx_7genexpr__pyx_v_arg = NULL;
  PyObject *__pyx_r = NULL;
  __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 *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  __Pyx_TraceFrameInit(__pyx_codeobj_)
  __Pyx_RefNannySetupContext("filter_args", 0);
  __Pyx_TraceCall("filter_args", __pyx_f[0], 42, 0, __PYX_ERR(0, 42, __pyx_L1_error));

  /* "kwant/linalg/lapack.pyx":43
 * # some helper functions
 * def filter_args(select, args):
 *     return tuple([arg for sel, arg in zip(select, args) if sel])             # <<<<<<<<<<<<<<
 * 
 * def assert_fortran_mat(*mats):
 */
  __Pyx_TraceLine(43,0,__PYX_ERR(0, 43, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  { /* enter inner scope */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_select);
    __Pyx_GIVEREF(__pyx_v_select);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_select);
    __Pyx_INCREF(__pyx_v_args);
    __Pyx_GIVEREF(__pyx_v_args);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_args);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    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, 43, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L5_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, 43, __pyx_L5_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L5_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, 43, __pyx_L5_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L5_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, 43, __pyx_L5_error)
          }
          break;
        }
        __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, 43, __pyx_L5_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 43, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 43, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 43, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 43, __pyx_L5_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 43, __pyx_L5_error)
        __pyx_L9_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_sel, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_arg, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_7genexpr__pyx_v_sel); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 43, __pyx_L5_error)
      if (__pyx_t_10) {
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_7genexpr__pyx_v_arg))) __PYX_ERR(0, 43, __pyx_L5_error)
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_arg); __pyx_7genexpr__pyx_v_arg = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_sel); __pyx_7genexpr__pyx_v_sel = 0;
    goto __pyx_L11_exit_scope;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_arg); __pyx_7genexpr__pyx_v_arg = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_sel); __pyx_7genexpr__pyx_v_sel = 0;
    goto __pyx_L1_error;
    __pyx_L11_exit_scope:;
  } /* exit inner scope */
  __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __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;

  /* "kwant/linalg/lapack.pyx":42
 * 
 * # some helper functions
 * def filter_args(select, args):             # <<<<<<<<<<<<<<
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("kwant.linalg.lapack.filter_args", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_sel);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_arg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":45
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 * def assert_fortran_mat(*mats):             # <<<<<<<<<<<<<<
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_3assert_fortran_mat(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_3assert_fortran_mat = {"assert_fortran_mat", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_3assert_fortran_mat, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_3assert_fortran_mat(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_mats = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("assert_fortran_mat (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "assert_fortran_mat", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_mats = __pyx_args;
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_2assert_fortran_mat(__pyx_self, __pyx_v_mats);

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

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_2assert_fortran_mat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mats) {
  PyObject *__pyx_v_mat = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__2)
  __Pyx_RefNannySetupContext("assert_fortran_mat", 0);
  __Pyx_TraceCall("assert_fortran_mat", __pyx_f[0], 45, 0, __PYX_ERR(0, 45, __pyx_L1_error));

  /* "kwant/linalg/lapack.pyx":48
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 *     for mat in mats:             # <<<<<<<<<<<<<<
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and
 *             not mat.flags["F_CONTIGUOUS"]):
 */
  __Pyx_TraceLine(48,0,__PYX_ERR(0, 48, __pyx_L1_error))
  __pyx_t_1 = __pyx_v_mats; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 48, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_mat, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":49
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 *     for mat in mats:
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *             not mat.flags["F_CONTIGUOUS"]):
 *             raise ValueError("Input matrix must be Fortran contiguous")
 */
    __Pyx_TraceLine(49,0,__PYX_ERR(0, 49, __pyx_L1_error))
    __pyx_t_5 = (__pyx_v_mat != Py_None);
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!__pyx_t_6) {
    } else {
      goto __pyx_L8_next_and;
    }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_3, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 49, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_L8_next_and:;

    /* "kwant/linalg/lapack.pyx":50
 *     for mat in mats:
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and
 *             not mat.flags["F_CONTIGUOUS"]):             # <<<<<<<<<<<<<<
 *             raise ValueError("Input matrix must be Fortran contiguous")
 * 
 */
    __Pyx_TraceLine(50,0,__PYX_ERR(0, 50, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s_flags); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_t_3, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 50, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_5 = ((!__pyx_t_6) != 0);
    __pyx_t_4 = __pyx_t_5;
    __pyx_L6_bool_binop_done:;

    /* "kwant/linalg/lapack.pyx":49
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 *     for mat in mats:
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *             not mat.flags["F_CONTIGUOUS"]):
 *             raise ValueError("Input matrix must be Fortran contiguous")
 */
    __Pyx_TraceLine(49,0,__PYX_ERR(0, 49, __pyx_L1_error))
    if (unlikely(__pyx_t_4)) {

      /* "kwant/linalg/lapack.pyx":51
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and
 *             not mat.flags["F_CONTIGUOUS"]):
 *             raise ValueError("Input matrix must be Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_TraceLine(51,0,__PYX_ERR(0, 51, __pyx_L1_error))
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 51, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 51, __pyx_L1_error)

      /* "kwant/linalg/lapack.pyx":49
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 *     for mat in mats:
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *             not mat.flags["F_CONTIGUOUS"]):
 *             raise ValueError("Input matrix must be Fortran contiguous")
 */
    }

    /* "kwant/linalg/lapack.pyx":48
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 *     for mat in mats:             # <<<<<<<<<<<<<<
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and
 *             not mat.flags["F_CONTIGUOUS"]):
 */
    __Pyx_TraceLine(48,0,__PYX_ERR(0, 48, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":45
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 * def assert_fortran_mat(*mats):             # <<<<<<<<<<<<<<
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 */

  /* 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_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("kwant.linalg.lapack.assert_fortran_mat", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mat);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":55
 * 
 * # Wrappers for xGETRF
 * def sgetrf(np.ndarray[np.float32_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_5sgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_5sgetrf = {"sgetrf", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_5sgetrf, METH_O, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_5sgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sgetrf (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 55, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_4sgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_4sgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_ipiv = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ipiv;
  __Pyx_Buffer __pyx_pybuffer_ipiv;
  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;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  __Pyx_TraceFrameInit(__pyx_codeobj__4)
  __Pyx_RefNannySetupContext("sgetrf", 0);
  __Pyx_TraceCall("sgetrf", __pyx_f[0], 55, 0, __PYX_ERR(0, 55, __pyx_L1_error));
  __pyx_pybuffer_ipiv.pybuffer.buf = NULL;
  __pyx_pybuffer_ipiv.refcount = 0;
  __pyx_pybuffernd_ipiv.data = NULL;
  __pyx_pybuffernd_ipiv.rcbuffer = &__pyx_pybuffer_ipiv;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 55, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":59
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     M = A.shape[0]
 */
  __Pyx_TraceLine(59,0,__PYX_ERR(0, 59, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":61
 *     assert_fortran_mat(A)
 * 
 *     M = A.shape[0]             # <<<<<<<<<<<<<<
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(61,0,__PYX_ERR(0, 61, __pyx_L1_error))
  __pyx_v_M = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":62
 * 
 *     M = A.shape[0]
 *     N = A.shape[1]             # <<<<<<<<<<<<<<
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(62,0,__PYX_ERR(0, 62, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[1]);

  /* "kwant/linalg/lapack.pyx":63
 *     M = A.shape[0]
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.sgetrf_(&M, &N, <float *>A.data, &M,
 */
  __Pyx_TraceLine(63,0,__PYX_ERR(0, 63, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __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, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __pyx_v_N;
  __pyx_t_6 = __pyx_v_M;
  if (((__pyx_t_5 < __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __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;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 63, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
    __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_10 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_v_ipiv, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      }
      __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
    }
    __pyx_pybuffernd_ipiv.diminfo[0].strides = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ipiv.diminfo[0].shape = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 63, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":65
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.sgetrf_(&M, &N, <float *>A.data, &M,             # <<<<<<<<<<<<<<
 *                      <l_int *>ipiv.data, &info)
 * 
 */
  __Pyx_TraceLine(65,0,__PYX_ERR(0, 65, __pyx_L1_error))
  sgetrf_((&__pyx_v_M), (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_M), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_ipiv->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":68
 *                      <l_int *>ipiv.data, &info)
 * 
 *     assert info >= 0, "Argument error in sgetrf"             # <<<<<<<<<<<<<<
 * 
 *     return (A, ipiv, info > 0 or M != N)
 */
  __Pyx_TraceLine(68,0,__PYX_ERR(0, 68, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info >= 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sgetrf);
      __PYX_ERR(0, 68, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":70
 *     assert info >= 0, "Argument error in sgetrf"
 * 
 *     return (A, ipiv, info > 0 or M != N)             # <<<<<<<<<<<<<<
 * 
 * def dgetrf(np.ndarray[np.float64_t, ndim=2] A):
 */
  __Pyx_TraceLine(70,0,__PYX_ERR(0, 70, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_14 = (__pyx_v_M != __pyx_v_N);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":55
 * 
 * # Wrappers for xGETRF
 * def sgetrf(np.ndarray[np.float32_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

  /* 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_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sgetrf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ipiv);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":72
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def dgetrf(np.ndarray[np.float64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_7dgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_7dgetrf = {"dgetrf", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_7dgetrf, METH_O, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_7dgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dgetrf (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 72, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_6dgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_6dgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_ipiv = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ipiv;
  __Pyx_Buffer __pyx_pybuffer_ipiv;
  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;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  __Pyx_TraceFrameInit(__pyx_codeobj__5)
  __Pyx_RefNannySetupContext("dgetrf", 0);
  __Pyx_TraceCall("dgetrf", __pyx_f[0], 72, 0, __PYX_ERR(0, 72, __pyx_L1_error));
  __pyx_pybuffer_ipiv.pybuffer.buf = NULL;
  __pyx_pybuffer_ipiv.refcount = 0;
  __pyx_pybuffernd_ipiv.data = NULL;
  __pyx_pybuffernd_ipiv.rcbuffer = &__pyx_pybuffer_ipiv;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 72, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":76
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     M = A.shape[0]
 */
  __Pyx_TraceLine(76,0,__PYX_ERR(0, 76, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 76, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":78
 *     assert_fortran_mat(A)
 * 
 *     M = A.shape[0]             # <<<<<<<<<<<<<<
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(78,0,__PYX_ERR(0, 78, __pyx_L1_error))
  __pyx_v_M = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":79
 * 
 *     M = A.shape[0]
 *     N = A.shape[1]             # <<<<<<<<<<<<<<
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(79,0,__PYX_ERR(0, 79, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[1]);

  /* "kwant/linalg/lapack.pyx":80
 *     M = A.shape[0]
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dgetrf_(&M, &N, <double *>A.data, &M,
 */
  __Pyx_TraceLine(80,0,__PYX_ERR(0, 80, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __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, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __pyx_v_N;
  __pyx_t_6 = __pyx_v_M;
  if (((__pyx_t_5 < __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 80, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __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;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 80, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
    __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_10 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_v_ipiv, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      }
      __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
    }
    __pyx_pybuffernd_ipiv.diminfo[0].strides = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ipiv.diminfo[0].shape = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 80, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":82
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.dgetrf_(&M, &N, <double *>A.data, &M,             # <<<<<<<<<<<<<<
 *                      <l_int *>ipiv.data, &info)
 * 
 */
  __Pyx_TraceLine(82,0,__PYX_ERR(0, 82, __pyx_L1_error))
  dgetrf_((&__pyx_v_M), (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_M), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_ipiv->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":85
 *                      <l_int *>ipiv.data, &info)
 * 
 *     assert info >= 0, "Argument error in dgetrf"             # <<<<<<<<<<<<<<
 * 
 *     return (A, ipiv, info > 0 or M != N)
 */
  __Pyx_TraceLine(85,0,__PYX_ERR(0, 85, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info >= 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dgetrf);
      __PYX_ERR(0, 85, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":87
 *     assert info >= 0, "Argument error in dgetrf"
 * 
 *     return (A, ipiv, info > 0 or M != N)             # <<<<<<<<<<<<<<
 * 
 * def cgetrf(np.ndarray[np.complex64_t, ndim=2] A):
 */
  __Pyx_TraceLine(87,0,__PYX_ERR(0, 87, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_14 = (__pyx_v_M != __pyx_v_N);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":72
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def dgetrf(np.ndarray[np.float64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

  /* 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_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dgetrf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ipiv);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":89
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def cgetrf(np.ndarray[np.complex64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_9cgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_9cgetrf = {"cgetrf", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_9cgetrf, METH_O, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_9cgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cgetrf (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 89, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_8cgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_8cgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_ipiv = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ipiv;
  __Pyx_Buffer __pyx_pybuffer_ipiv;
  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;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  __Pyx_TraceFrameInit(__pyx_codeobj__6)
  __Pyx_RefNannySetupContext("cgetrf", 0);
  __Pyx_TraceCall("cgetrf", __pyx_f[0], 89, 0, __PYX_ERR(0, 89, __pyx_L1_error));
  __pyx_pybuffer_ipiv.pybuffer.buf = NULL;
  __pyx_pybuffer_ipiv.refcount = 0;
  __pyx_pybuffernd_ipiv.data = NULL;
  __pyx_pybuffernd_ipiv.rcbuffer = &__pyx_pybuffer_ipiv;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 89, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":93
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     M = A.shape[0]
 */
  __Pyx_TraceLine(93,0,__PYX_ERR(0, 93, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 93, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":95
 *     assert_fortran_mat(A)
 * 
 *     M = A.shape[0]             # <<<<<<<<<<<<<<
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(95,0,__PYX_ERR(0, 95, __pyx_L1_error))
  __pyx_v_M = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":96
 * 
 *     M = A.shape[0]
 *     N = A.shape[1]             # <<<<<<<<<<<<<<
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(96,0,__PYX_ERR(0, 96, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[1]);

  /* "kwant/linalg/lapack.pyx":97
 *     M = A.shape[0]
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cgetrf_(&M, &N, <float complex *>A.data, &M,
 */
  __Pyx_TraceLine(97,0,__PYX_ERR(0, 97, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __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, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __pyx_v_N;
  __pyx_t_6 = __pyx_v_M;
  if (((__pyx_t_5 < __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 97, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 97, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __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;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 97, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
    __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_10 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_v_ipiv, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      }
      __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
    }
    __pyx_pybuffernd_ipiv.diminfo[0].strides = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ipiv.diminfo[0].shape = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 97, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":99
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.cgetrf_(&M, &N, <float complex *>A.data, &M,             # <<<<<<<<<<<<<<
 *                      <l_int *>ipiv.data, &info)
 * 
 */
  __Pyx_TraceLine(99,0,__PYX_ERR(0, 99, __pyx_L1_error))
  cgetrf_((&__pyx_v_M), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_M), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_ipiv->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":102
 *                      <l_int *>ipiv.data, &info)
 * 
 *     assert info >= 0, "Argument error in cgetrf"             # <<<<<<<<<<<<<<
 * 
 *     return (A, ipiv, info > 0 or M != N)
 */
  __Pyx_TraceLine(102,0,__PYX_ERR(0, 102, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info >= 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cgetrf);
      __PYX_ERR(0, 102, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":104
 *     assert info >= 0, "Argument error in cgetrf"
 * 
 *     return (A, ipiv, info > 0 or M != N)             # <<<<<<<<<<<<<<
 * 
 * def zgetrf(np.ndarray[np.complex128_t, ndim=2] A):
 */
  __Pyx_TraceLine(104,0,__PYX_ERR(0, 104, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_14 = (__pyx_v_M != __pyx_v_N);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":89
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def cgetrf(np.ndarray[np.complex64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

  /* 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_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cgetrf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ipiv);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":106
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def zgetrf(np.ndarray[np.complex128_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_11zgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_11zgetrf = {"zgetrf", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_11zgetrf, METH_O, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_11zgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zgetrf (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 106, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_10zgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_10zgetrf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_ipiv = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ipiv;
  __Pyx_Buffer __pyx_pybuffer_ipiv;
  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;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  __Pyx_TraceFrameInit(__pyx_codeobj__7)
  __Pyx_RefNannySetupContext("zgetrf", 0);
  __Pyx_TraceCall("zgetrf", __pyx_f[0], 106, 0, __PYX_ERR(0, 106, __pyx_L1_error));
  __pyx_pybuffer_ipiv.pybuffer.buf = NULL;
  __pyx_pybuffer_ipiv.refcount = 0;
  __pyx_pybuffernd_ipiv.data = NULL;
  __pyx_pybuffernd_ipiv.rcbuffer = &__pyx_pybuffer_ipiv;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 106, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":110
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     M = A.shape[0]
 */
  __Pyx_TraceLine(110,0,__PYX_ERR(0, 110, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":112
 *     assert_fortran_mat(A)
 * 
 *     M = A.shape[0]             # <<<<<<<<<<<<<<
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(112,0,__PYX_ERR(0, 112, __pyx_L1_error))
  __pyx_v_M = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":113
 * 
 *     M = A.shape[0]
 *     N = A.shape[1]             # <<<<<<<<<<<<<<
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(113,0,__PYX_ERR(0, 113, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[1]);

  /* "kwant/linalg/lapack.pyx":114
 *     M = A.shape[0]
 *     N = A.shape[1]
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zgetrf_(&M, &N, <double complex *>A.data, &M,
 */
  __Pyx_TraceLine(114,0,__PYX_ERR(0, 114, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __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, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __pyx_v_N;
  __pyx_t_6 = __pyx_v_M;
  if (((__pyx_t_5 < __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __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;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 114, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
    __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_10 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer, (PyObject*)__pyx_v_ipiv, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      }
      __pyx_t_11 = __pyx_t_12 = __pyx_t_13 = 0;
    }
    __pyx_pybuffernd_ipiv.diminfo[0].strides = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ipiv.diminfo[0].shape = __pyx_pybuffernd_ipiv.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 114, __pyx_L1_error)
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":116
 *     ipiv = np.empty(min(M,N), dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.zgetrf_(&M, &N, <double complex *>A.data, &M,             # <<<<<<<<<<<<<<
 *                      <l_int *>ipiv.data, &info)
 * 
 */
  __Pyx_TraceLine(116,0,__PYX_ERR(0, 116, __pyx_L1_error))
  zgetrf_((&__pyx_v_M), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_M), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_ipiv->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":119
 *                      <l_int *>ipiv.data, &info)
 * 
 *     assert info >= 0, "Argument error in zgetrf"             # <<<<<<<<<<<<<<
 * 
 *     return (A, ipiv, info > 0 or M != N)
 */
  __Pyx_TraceLine(119,0,__PYX_ERR(0, 119, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info >= 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgetrf);
      __PYX_ERR(0, 119, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":121
 *     assert info >= 0, "Argument error in zgetrf"
 * 
 *     return (A, ipiv, info > 0 or M != N)             # <<<<<<<<<<<<<<
 * 
 * # Wrappers for xGETRS
 */
  __Pyx_TraceLine(121,0,__PYX_ERR(0, 121, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
  } else {
    __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_14 = (__pyx_v_M != __pyx_v_N);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":106
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def zgetrf(np.ndarray[np.complex128_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */

  /* 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_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zgetrf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ipiv.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ipiv);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":125
 * # Wrappers for xGETRS
 * 
 * def sgetrs(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_13sgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_13sgetrs = {"sgetrs", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_13sgetrs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_13sgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  PyArrayObject *__pyx_v_IPIV = 0;
  PyObject *__pyx_v_B = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sgetrs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_IPIV,&__pyx_n_s_B,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_LU)) != 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_IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgetrs", 1, 3, 3, 1); __PYX_ERR(0, 125, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgetrs", 1, 3, 3, 2); __PYX_ERR(0, 125, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sgetrs") < 0)) __PYX_ERR(0, 125, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_IPIV = ((PyArrayObject *)values[1]);
    __pyx_v_B = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sgetrs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 125, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.sgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 125, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) __PYX_ERR(0, 126, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_12sgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_12sgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_NRHS;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_b = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_IPIV;
  __Pyx_Buffer __pyx_pybuffer_IPIV;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  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;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_8;
  __Pyx_TraceFrameInit(__pyx_codeobj__8)
  __Pyx_RefNannySetupContext("sgetrs", 0);
  __Pyx_TraceCall("sgetrs", __pyx_f[0], 125, 0, __PYX_ERR(0, 125, __pyx_L1_error));
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  __pyx_pybuffer_IPIV.pybuffer.buf = NULL;
  __pyx_pybuffer_IPIV.refcount = 0;
  __pyx_pybuffernd_IPIV.data = NULL;
  __pyx_pybuffernd_IPIV.rcbuffer = &__pyx_pybuffer_IPIV;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 125, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer, (PyObject*)__pyx_v_IPIV, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 125, __pyx_L1_error)
  }
  __pyx_pybuffernd_IPIV.diminfo[0].strides = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_IPIV.diminfo[0].shape = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":130
 *     cdef np.ndarray b
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 */
  __Pyx_TraceLine(130,0,__PYX_ERR(0, 130, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":133
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(133,0,__PYX_ERR(0, 133, __pyx_L1_error))
  __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_B, __pyx_ptype_5numpy_ndarray); 
  __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }

  /* "kwant/linalg/lapack.pyx":134
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 */
  __Pyx_TraceLine(134,0,__PYX_ERR(0, 134, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __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, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __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, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_7) {
  } else {
    goto __pyx_L7_next_and;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_L7_next_and:;

  /* "kwant/linalg/lapack.pyx":135
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):             # <<<<<<<<<<<<<<
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 */
  __Pyx_TraceLine(135,0,__PYX_ERR(0, 135, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_flags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_7) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;

  /* "kwant/linalg/lapack.pyx":133
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(133,0,__PYX_ERR(0, 133, __pyx_L1_error))
  if (unlikely(__pyx_t_5)) {

    /* "kwant/linalg/lapack.pyx":136
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
    __Pyx_TraceLine(136,0,__PYX_ERR(0, 136, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __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, 136, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":133
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  }

  /* "kwant/linalg/lapack.pyx":138
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 *     b = B             # <<<<<<<<<<<<<<
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 */
  __Pyx_TraceLine(138,0,__PYX_ERR(0, 138, __pyx_L1_error))
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 138, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_B;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_b = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":139
 * 
 *     b = B
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     if b.ndim == 1:
 *         NRHS = 1
 */
  __Pyx_TraceLine(139,0,__PYX_ERR(0, 139, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":140
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
  __Pyx_TraceLine(140,0,__PYX_ERR(0, 140, __pyx_L1_error))
  switch (__pyx_v_b->nd) {
    case 1:

    /* "kwant/linalg/lapack.pyx":141
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 *         NRHS = 1             # <<<<<<<<<<<<<<
 *     elif b.ndim == 2:
 *         NRHS = B.shape[1]
 */
    __Pyx_TraceLine(141,0,__PYX_ERR(0, 141, __pyx_L1_error))
    __pyx_v_NRHS = 1;

    /* "kwant/linalg/lapack.pyx":140
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    break;

    /* "kwant/linalg/lapack.pyx":142
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = B.shape[1]
 *     else:
 */
    __Pyx_TraceLine(142,0,__PYX_ERR(0, 142, __pyx_L1_error))
    case 2:

    /* "kwant/linalg/lapack.pyx":143
 *         NRHS = 1
 *     elif b.ndim == 2:
 *         NRHS = B.shape[1]             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("In sgetrs: B must be a vector or matrix")
 */
    __Pyx_TraceLine(143,0,__PYX_ERR(0, 143, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 143, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_NRHS = __pyx_t_8;

    /* "kwant/linalg/lapack.pyx":142
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = B.shape[1]
 *     else:
 */
    break;
    default:

    /* "kwant/linalg/lapack.pyx":145
 *         NRHS = B.shape[1]
 *     else:
 *         raise ValueError("In sgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.sgetrs_("N", &N, &NRHS, <float *>LU.data, &N,
 */
    __Pyx_TraceLine(145,0,__PYX_ERR(0, 145, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __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, 145, __pyx_L1_error)
    break;
  }

  /* "kwant/linalg/lapack.pyx":147
 *         raise ValueError("In sgetrs: B must be a vector or matrix")
 * 
 *     f_lapack.sgetrs_("N", &N, &NRHS, <float *>LU.data, &N,             # <<<<<<<<<<<<<<
 *                      <l_int *>IPIV.data, <float *>b.data, &N,
 *                      &info)
 */
  __Pyx_TraceLine(147,0,__PYX_ERR(0, 147, __pyx_L1_error))
  sgetrs_(((char *)"N"), (&__pyx_v_N), (&__pyx_v_NRHS), ((float *)__pyx_v_LU->data), (&__pyx_v_N), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_IPIV->data), ((float *)__pyx_v_b->data), (&__pyx_v_N), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":151
 *                      &info)
 * 
 *     assert info == 0, "Argument error in sgetrs"             # <<<<<<<<<<<<<<
 * 
 *     return b
 */
  __Pyx_TraceLine(151,0,__PYX_ERR(0, 151, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sgetrs);
      __PYX_ERR(0, 151, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":153
 *     assert info == 0, "Argument error in sgetrs"
 * 
 *     return b             # <<<<<<<<<<<<<<
 * 
 * def dgetrs(np.ndarray[np.float64_t, ndim=2] LU,
 */
  __Pyx_TraceLine(153,0,__PYX_ERR(0, 153, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":125
 * # Wrappers for xGETRS
 * 
 * def sgetrs(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":155
 *     return b
 * 
 * def dgetrs(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_15dgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_15dgetrs = {"dgetrs", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_15dgetrs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_15dgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  PyArrayObject *__pyx_v_IPIV = 0;
  PyObject *__pyx_v_B = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dgetrs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_IPIV,&__pyx_n_s_B,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_LU)) != 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_IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgetrs", 1, 3, 3, 1); __PYX_ERR(0, 155, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgetrs", 1, 3, 3, 2); __PYX_ERR(0, 155, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dgetrs") < 0)) __PYX_ERR(0, 155, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_IPIV = ((PyArrayObject *)values[1]);
    __pyx_v_B = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dgetrs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 155, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 155, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) __PYX_ERR(0, 156, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_14dgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_14dgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_NRHS;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_b = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_IPIV;
  __Pyx_Buffer __pyx_pybuffer_IPIV;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  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;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  __Pyx_TraceFrameInit(__pyx_codeobj__11)
  __Pyx_RefNannySetupContext("dgetrs", 0);
  __Pyx_TraceCall("dgetrs", __pyx_f[0], 155, 0, __PYX_ERR(0, 155, __pyx_L1_error));
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  __pyx_pybuffer_IPIV.pybuffer.buf = NULL;
  __pyx_pybuffer_IPIV.refcount = 0;
  __pyx_pybuffernd_IPIV.data = NULL;
  __pyx_pybuffernd_IPIV.rcbuffer = &__pyx_pybuffer_IPIV;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 155, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer, (PyObject*)__pyx_v_IPIV, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 155, __pyx_L1_error)
  }
  __pyx_pybuffernd_IPIV.diminfo[0].strides = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_IPIV.diminfo[0].shape = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":160
 *     cdef np.ndarray b
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 */
  __Pyx_TraceLine(160,0,__PYX_ERR(0, 160, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 160, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":163
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(163,0,__PYX_ERR(0, 163, __pyx_L1_error))
  __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_B, __pyx_ptype_5numpy_ndarray); 
  __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }

  /* "kwant/linalg/lapack.pyx":164
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 */
  __Pyx_TraceLine(164,0,__PYX_ERR(0, 164, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __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, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __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, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_7) {
  } else {
    goto __pyx_L7_next_and;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 164, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_L7_next_and:;

  /* "kwant/linalg/lapack.pyx":165
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):             # <<<<<<<<<<<<<<
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 */
  __Pyx_TraceLine(165,0,__PYX_ERR(0, 165, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_flags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_7) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;

  /* "kwant/linalg/lapack.pyx":163
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(163,0,__PYX_ERR(0, 163, __pyx_L1_error))
  if (unlikely(__pyx_t_5)) {

    /* "kwant/linalg/lapack.pyx":166
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
    __Pyx_TraceLine(166,0,__PYX_ERR(0, 166, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __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, 166, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":163
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  }

  /* "kwant/linalg/lapack.pyx":168
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 *     b = B             # <<<<<<<<<<<<<<
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 */
  __Pyx_TraceLine(168,0,__PYX_ERR(0, 168, __pyx_L1_error))
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 168, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_B;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_b = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":169
 * 
 *     b = B
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     if b.ndim == 1:
 *         NRHS = 1
 */
  __Pyx_TraceLine(169,0,__PYX_ERR(0, 169, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":170
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
  __Pyx_TraceLine(170,0,__PYX_ERR(0, 170, __pyx_L1_error))
  switch (__pyx_v_b->nd) {
    case 1:

    /* "kwant/linalg/lapack.pyx":171
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 *         NRHS = 1             # <<<<<<<<<<<<<<
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]
 */
    __Pyx_TraceLine(171,0,__PYX_ERR(0, 171, __pyx_L1_error))
    __pyx_v_NRHS = 1;

    /* "kwant/linalg/lapack.pyx":170
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    break;

    /* "kwant/linalg/lapack.pyx":172
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    __Pyx_TraceLine(172,0,__PYX_ERR(0, 172, __pyx_L1_error))
    case 2:

    /* "kwant/linalg/lapack.pyx":173
 *         NRHS = 1
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("In dgetrs: B must be a vector or matrix")
 */
    __Pyx_TraceLine(173,0,__PYX_ERR(0, 173, __pyx_L1_error))
    __pyx_v_NRHS = (__pyx_v_b->dimensions[1]);

    /* "kwant/linalg/lapack.pyx":172
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    break;
    default:

    /* "kwant/linalg/lapack.pyx":175
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In dgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dgetrs_("N", &N, &NRHS, <double *>LU.data, &N,
 */
    __Pyx_TraceLine(175,0,__PYX_ERR(0, 175, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __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, 175, __pyx_L1_error)
    break;
  }

  /* "kwant/linalg/lapack.pyx":177
 *         raise ValueError("In dgetrs: B must be a vector or matrix")
 * 
 *     f_lapack.dgetrs_("N", &N, &NRHS, <double *>LU.data, &N,             # <<<<<<<<<<<<<<
 *                      <l_int *>IPIV.data, <double *>b.data, &N,
 *                      &info)
 */
  __Pyx_TraceLine(177,0,__PYX_ERR(0, 177, __pyx_L1_error))
  dgetrs_(((char *)"N"), (&__pyx_v_N), (&__pyx_v_NRHS), ((double *)__pyx_v_LU->data), (&__pyx_v_N), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_IPIV->data), ((double *)__pyx_v_b->data), (&__pyx_v_N), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":181
 *                      &info)
 * 
 *     assert info == 0, "Argument error in dgetrs"             # <<<<<<<<<<<<<<
 * 
 *     return b
 */
  __Pyx_TraceLine(181,0,__PYX_ERR(0, 181, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dgetrs);
      __PYX_ERR(0, 181, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":183
 *     assert info == 0, "Argument error in dgetrs"
 * 
 *     return b             # <<<<<<<<<<<<<<
 * 
 * def cgetrs(np.ndarray[np.complex64_t, ndim=2] LU,
 */
  __Pyx_TraceLine(183,0,__PYX_ERR(0, 183, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":155
 *     return b
 * 
 * def dgetrs(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":185
 *     return b
 * 
 * def cgetrs(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_17cgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_17cgetrs = {"cgetrs", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_17cgetrs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_17cgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  PyArrayObject *__pyx_v_IPIV = 0;
  PyObject *__pyx_v_B = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cgetrs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_IPIV,&__pyx_n_s_B,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_LU)) != 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_IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgetrs", 1, 3, 3, 1); __PYX_ERR(0, 185, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgetrs", 1, 3, 3, 2); __PYX_ERR(0, 185, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cgetrs") < 0)) __PYX_ERR(0, 185, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_IPIV = ((PyArrayObject *)values[1]);
    __pyx_v_B = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cgetrs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 185, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.cgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 185, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) __PYX_ERR(0, 186, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_16cgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_16cgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_NRHS;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_b = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_IPIV;
  __Pyx_Buffer __pyx_pybuffer_IPIV;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  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;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  __Pyx_TraceFrameInit(__pyx_codeobj__14)
  __Pyx_RefNannySetupContext("cgetrs", 0);
  __Pyx_TraceCall("cgetrs", __pyx_f[0], 185, 0, __PYX_ERR(0, 185, __pyx_L1_error));
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  __pyx_pybuffer_IPIV.pybuffer.buf = NULL;
  __pyx_pybuffer_IPIV.refcount = 0;
  __pyx_pybuffernd_IPIV.data = NULL;
  __pyx_pybuffernd_IPIV.rcbuffer = &__pyx_pybuffer_IPIV;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 185, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer, (PyObject*)__pyx_v_IPIV, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 185, __pyx_L1_error)
  }
  __pyx_pybuffernd_IPIV.diminfo[0].strides = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_IPIV.diminfo[0].shape = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":190
 *     cdef np.ndarray b
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 */
  __Pyx_TraceLine(190,0,__PYX_ERR(0, 190, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 190, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":193
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(193,0,__PYX_ERR(0, 193, __pyx_L1_error))
  __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_B, __pyx_ptype_5numpy_ndarray); 
  __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }

  /* "kwant/linalg/lapack.pyx":194
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 */
  __Pyx_TraceLine(194,0,__PYX_ERR(0, 194, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __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, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __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, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_7) {
  } else {
    goto __pyx_L7_next_and;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_L7_next_and:;

  /* "kwant/linalg/lapack.pyx":195
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):             # <<<<<<<<<<<<<<
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 */
  __Pyx_TraceLine(195,0,__PYX_ERR(0, 195, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_flags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_7) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;

  /* "kwant/linalg/lapack.pyx":193
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(193,0,__PYX_ERR(0, 193, __pyx_L1_error))
  if (unlikely(__pyx_t_5)) {

    /* "kwant/linalg/lapack.pyx":196
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
    __Pyx_TraceLine(196,0,__PYX_ERR(0, 196, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __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, 196, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":193
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  }

  /* "kwant/linalg/lapack.pyx":198
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 *     b = B             # <<<<<<<<<<<<<<
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 */
  __Pyx_TraceLine(198,0,__PYX_ERR(0, 198, __pyx_L1_error))
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 198, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_B;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_b = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":199
 * 
 *     b = B
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     if b.ndim == 1:
 *         NRHS = 1
 */
  __Pyx_TraceLine(199,0,__PYX_ERR(0, 199, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":200
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
  __Pyx_TraceLine(200,0,__PYX_ERR(0, 200, __pyx_L1_error))
  switch (__pyx_v_b->nd) {
    case 1:

    /* "kwant/linalg/lapack.pyx":201
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 *         NRHS = 1             # <<<<<<<<<<<<<<
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]
 */
    __Pyx_TraceLine(201,0,__PYX_ERR(0, 201, __pyx_L1_error))
    __pyx_v_NRHS = 1;

    /* "kwant/linalg/lapack.pyx":200
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    break;

    /* "kwant/linalg/lapack.pyx":202
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    __Pyx_TraceLine(202,0,__PYX_ERR(0, 202, __pyx_L1_error))
    case 2:

    /* "kwant/linalg/lapack.pyx":203
 *         NRHS = 1
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("In cgetrs: B must be a vector or matrix")
 */
    __Pyx_TraceLine(203,0,__PYX_ERR(0, 203, __pyx_L1_error))
    __pyx_v_NRHS = (__pyx_v_b->dimensions[1]);

    /* "kwant/linalg/lapack.pyx":202
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    break;
    default:

    /* "kwant/linalg/lapack.pyx":205
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In cgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cgetrs_("N", &N, &NRHS, <float complex *>LU.data, &N,
 */
    __Pyx_TraceLine(205,0,__PYX_ERR(0, 205, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __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, 205, __pyx_L1_error)
    break;
  }

  /* "kwant/linalg/lapack.pyx":207
 *         raise ValueError("In cgetrs: B must be a vector or matrix")
 * 
 *     f_lapack.cgetrs_("N", &N, &NRHS, <float complex *>LU.data, &N,             # <<<<<<<<<<<<<<
 *                      <l_int *>IPIV.data, <float complex *>b.data, &N,
 *                      &info)
 */
  __Pyx_TraceLine(207,0,__PYX_ERR(0, 207, __pyx_L1_error))
  cgetrs_(((char *)"N"), (&__pyx_v_N), (&__pyx_v_NRHS), ((__pyx_t_float_complex *)__pyx_v_LU->data), (&__pyx_v_N), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_IPIV->data), ((__pyx_t_float_complex *)__pyx_v_b->data), (&__pyx_v_N), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":211
 *                      &info)
 * 
 *     assert info == 0, "Argument error in cgetrs"             # <<<<<<<<<<<<<<
 * 
 *     return b
 */
  __Pyx_TraceLine(211,0,__PYX_ERR(0, 211, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cgetrs);
      __PYX_ERR(0, 211, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":213
 *     assert info == 0, "Argument error in cgetrs"
 * 
 *     return b             # <<<<<<<<<<<<<<
 * 
 * def zgetrs(np.ndarray[np.complex128_t, ndim=2] LU,
 */
  __Pyx_TraceLine(213,0,__PYX_ERR(0, 213, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":185
 *     return b
 * 
 * def cgetrs(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":215
 *     return b
 * 
 * def zgetrs(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_19zgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_19zgetrs = {"zgetrs", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_19zgetrs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_19zgetrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  PyArrayObject *__pyx_v_IPIV = 0;
  PyObject *__pyx_v_B = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zgetrs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_IPIV,&__pyx_n_s_B,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_LU)) != 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_IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgetrs", 1, 3, 3, 1); __PYX_ERR(0, 215, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgetrs", 1, 3, 3, 2); __PYX_ERR(0, 215, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zgetrs") < 0)) __PYX_ERR(0, 215, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_IPIV = ((PyArrayObject *)values[1]);
    __pyx_v_B = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zgetrs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 215, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.zgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 215, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) __PYX_ERR(0, 216, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_18zgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_18zgetrs(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, PyArrayObject *__pyx_v_IPIV, PyObject *__pyx_v_B) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_NRHS;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  PyArrayObject *__pyx_v_b = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_IPIV;
  __Pyx_Buffer __pyx_pybuffer_IPIV;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  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;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  __Pyx_TraceFrameInit(__pyx_codeobj__17)
  __Pyx_RefNannySetupContext("zgetrs", 0);
  __Pyx_TraceCall("zgetrs", __pyx_f[0], 215, 0, __PYX_ERR(0, 215, __pyx_L1_error));
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  __pyx_pybuffer_IPIV.pybuffer.buf = NULL;
  __pyx_pybuffer_IPIV.refcount = 0;
  __pyx_pybuffernd_IPIV.data = NULL;
  __pyx_pybuffernd_IPIV.rcbuffer = &__pyx_pybuffer_IPIV;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer, (PyObject*)__pyx_v_IPIV, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 215, __pyx_L1_error)
  }
  __pyx_pybuffernd_IPIV.diminfo[0].strides = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_IPIV.diminfo[0].shape = __pyx_pybuffernd_IPIV.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":220
 *     cdef np.ndarray b
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 */
  __Pyx_TraceLine(220,0,__PYX_ERR(0, 220, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 220, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":223
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(223,0,__PYX_ERR(0, 223, __pyx_L1_error))
  __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_B, __pyx_ptype_5numpy_ndarray); 
  __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }

  /* "kwant/linalg/lapack.pyx":224
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and             # <<<<<<<<<<<<<<
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 */
  __Pyx_TraceLine(224,0,__PYX_ERR(0, 224, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 224, __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, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __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, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_7) {
  } else {
    goto __pyx_L7_next_and;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_L7_next_and:;

  /* "kwant/linalg/lapack.pyx":225
 *     if (not isinstance(B, np.ndarray) or
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):             # <<<<<<<<<<<<<<
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 */
  __Pyx_TraceLine(225,0,__PYX_ERR(0, 225, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s_flags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 225, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_7) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;

  /* "kwant/linalg/lapack.pyx":223
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  __Pyx_TraceLine(223,0,__PYX_ERR(0, 223, __pyx_L1_error))
  if (unlikely(__pyx_t_5)) {

    /* "kwant/linalg/lapack.pyx":226
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
    __Pyx_TraceLine(226,0,__PYX_ERR(0, 226, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __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, 226, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":223
 * 
 *     # again: workaround for 1x1-Fortran bug in NumPy < v2.0
 *     if (not isinstance(B, np.ndarray) or             # <<<<<<<<<<<<<<
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 */
  }

  /* "kwant/linalg/lapack.pyx":228
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")
 * 
 *     b = B             # <<<<<<<<<<<<<<
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 */
  __Pyx_TraceLine(228,0,__PYX_ERR(0, 228, __pyx_L1_error))
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 228, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_B;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_b = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":229
 * 
 *     b = B
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     if b.ndim == 1:
 *         NRHS = 1
 */
  __Pyx_TraceLine(229,0,__PYX_ERR(0, 229, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":230
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
  __Pyx_TraceLine(230,0,__PYX_ERR(0, 230, __pyx_L1_error))
  switch (__pyx_v_b->nd) {
    case 1:

    /* "kwant/linalg/lapack.pyx":231
 *     N = LU.shape[0]
 *     if b.ndim == 1:
 *         NRHS = 1             # <<<<<<<<<<<<<<
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]
 */
    __Pyx_TraceLine(231,0,__PYX_ERR(0, 231, __pyx_L1_error))
    __pyx_v_NRHS = 1;

    /* "kwant/linalg/lapack.pyx":230
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    break;

    /* "kwant/linalg/lapack.pyx":232
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    __Pyx_TraceLine(232,0,__PYX_ERR(0, 232, __pyx_L1_error))
    case 2:

    /* "kwant/linalg/lapack.pyx":233
 *         NRHS = 1
 *     elif b.ndim == 2:
 *         NRHS = b.shape[1]             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError("In zgetrs: B must be a vector or matrix")
 */
    __Pyx_TraceLine(233,0,__PYX_ERR(0, 233, __pyx_L1_error))
    __pyx_v_NRHS = (__pyx_v_b->dimensions[1]);

    /* "kwant/linalg/lapack.pyx":232
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    break;
    default:

    /* "kwant/linalg/lapack.pyx":235
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In zgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zgetrs_("N", &N, &NRHS, <double complex *>LU.data, &N,
 */
    __Pyx_TraceLine(235,0,__PYX_ERR(0, 235, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __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, 235, __pyx_L1_error)
    break;
  }

  /* "kwant/linalg/lapack.pyx":237
 *         raise ValueError("In zgetrs: B must be a vector or matrix")
 * 
 *     f_lapack.zgetrs_("N", &N, &NRHS, <double complex *>LU.data, &N,             # <<<<<<<<<<<<<<
 *                      <l_int *>IPIV.data, <double complex *>b.data, &N,
 *                      &info)
 */
  __Pyx_TraceLine(237,0,__PYX_ERR(0, 237, __pyx_L1_error))
  zgetrs_(((char *)"N"), (&__pyx_v_N), (&__pyx_v_NRHS), ((__pyx_t_double_complex *)__pyx_v_LU->data), (&__pyx_v_N), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_IPIV->data), ((__pyx_t_double_complex *)__pyx_v_b->data), (&__pyx_v_N), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":241
 *                      &info)
 * 
 *     assert info == 0, "Argument error in zgetrs"             # <<<<<<<<<<<<<<
 * 
 *     return b
 */
  __Pyx_TraceLine(241,0,__PYX_ERR(0, 241, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgetrs);
      __PYX_ERR(0, 241, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":243
 *     assert info == 0, "Argument error in zgetrs"
 * 
 *     return b             # <<<<<<<<<<<<<<
 * 
 * # Wrappers for xGECON
 */
  __Pyx_TraceLine(243,0,__PYX_ERR(0, 243, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":215
 *     return b
 * 
 * def zgetrs(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zgetrs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_IPIV.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":247
 * # Wrappers for xGECON
 * 
 * def sgecon(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_21sgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_21sgecon = {"sgecon", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_21sgecon, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_21sgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  float __pyx_v_normA;
  char *__pyx_v_norm;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sgecon (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_normA,&__pyx_n_s_norm,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_LU)) != 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_normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgecon", 0, 2, 3, 1); __PYX_ERR(0, 247, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_norm);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sgecon") < 0)) __PYX_ERR(0, 247, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_normA = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_normA == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 248, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsWritableString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) __PYX_ERR(0, 248, __pyx_L3_error)
    } else {
      __pyx_v_norm = ((char *)((char *)"1"));
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 247, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.sgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 247, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_20sgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_20sgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, float __pyx_v_normA, char *__pyx_v_norm) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  float __pyx_v_rcond;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__20)
  __Pyx_RefNannySetupContext("sgecon", 0);
  __Pyx_TraceCall("sgecon", __pyx_f[0], 247, 0, __PYX_ERR(0, 247, __pyx_L1_error));
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 247, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":254
 *     cdef np.ndarray[l_int, ndim=1] iwork
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     N = LU.shape[0]
 */
  __Pyx_TraceLine(254,0,__PYX_ERR(0, 254, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":256
 *     assert_fortran_mat(LU)
 * 
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(4*N, dtype = np.float32)
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(256,0,__PYX_ERR(0, 256, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":257
 * 
 *     N = LU.shape[0]
 *     work = np.empty(4*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(257,0,__PYX_ERR(0, 257, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __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, 257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((4 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 257, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 257, __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, 257, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 257, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 257, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 257, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":258
 *     N = LU.shape[0]
 *     work = np.empty(4*N, dtype = np.float32)
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.sgecon_(norm, &N, <float *>LU.data, &N, &normA,
 */
  __Pyx_TraceLine(258,0,__PYX_ERR(0, 258, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __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, 258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 258, __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, 258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 258, __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, 258, __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, 258, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 258, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 258, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":260
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.sgecon_(norm, &N, <float *>LU.data, &N, &normA,             # <<<<<<<<<<<<<<
 *                      &rcond, <float *>work.data,
 *                      <l_int *>iwork.data, &info)
 */
  __Pyx_TraceLine(260,0,__PYX_ERR(0, 260, __pyx_L1_error))
  sgecon_(__pyx_v_norm, (&__pyx_v_N), ((float *)__pyx_v_LU->data), (&__pyx_v_N), (&__pyx_v_normA), (&__pyx_v_rcond), ((float *)__pyx_v_work->data), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":264
 *                      <l_int *>iwork.data, &info)
 * 
 *     assert info == 0, "Argument error in sgecon"             # <<<<<<<<<<<<<<
 * 
 *     return rcond
 */
  __Pyx_TraceLine(264,0,__PYX_ERR(0, 264, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sgecon);
      __PYX_ERR(0, 264, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":266
 *     assert info == 0, "Argument error in sgecon"
 * 
 *     return rcond             # <<<<<<<<<<<<<<
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,
 */
  __Pyx_TraceLine(266,0,__PYX_ERR(0, 266, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":247
 * # Wrappers for xGECON
 * 
 * def sgecon(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_23dgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_23dgecon = {"dgecon", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_23dgecon, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_23dgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  double __pyx_v_normA;
  char *__pyx_v_norm;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dgecon (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_normA,&__pyx_n_s_norm,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_LU)) != 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_normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgecon", 0, 2, 3, 1); __PYX_ERR(0, 268, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_norm);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dgecon") < 0)) __PYX_ERR(0, 268, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_normA = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_normA == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 269, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsWritableString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) __PYX_ERR(0, 269, __pyx_L3_error)
    } else {
      __pyx_v_norm = ((char *)((char *)"1"));
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 268, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 268, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_22dgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_22dgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, double __pyx_v_normA, char *__pyx_v_norm) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  double __pyx_v_rcond;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__21)
  __Pyx_RefNannySetupContext("dgecon", 0);
  __Pyx_TraceCall("dgecon", __pyx_f[0], 268, 0, __PYX_ERR(0, 268, __pyx_L1_error));
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 268, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":275
 *     cdef np.ndarray[l_int, ndim=1] iwork
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     N = LU.shape[0]
 */
  __Pyx_TraceLine(275,0,__PYX_ERR(0, 275, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 275, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":277
 *     assert_fortran_mat(LU)
 * 
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(4*N, dtype = np.float64)
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(277,0,__PYX_ERR(0, 277, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":278
 * 
 *     N = LU.shape[0]
 *     work = np.empty(4*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(278,0,__PYX_ERR(0, 278, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __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, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((4 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 278, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 278, __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, 278, __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, 278, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 278, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 278, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 278, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":279
 *     N = LU.shape[0]
 *     work = np.empty(4*N, dtype = np.float64)
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dgecon_(norm, &N, <double *>LU.data, &N, &normA,
 */
  __Pyx_TraceLine(279,0,__PYX_ERR(0, 279, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 279, __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, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 279, __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, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __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, 279, __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, 279, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 279, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 279, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":281
 *     iwork = np.empty(N, dtype = f_lapack.l_int_dtype)
 * 
 *     f_lapack.dgecon_(norm, &N, <double *>LU.data, &N, &normA,             # <<<<<<<<<<<<<<
 *                      &rcond, <double *>work.data,
 *                      <l_int *>iwork.data, &info)
 */
  __Pyx_TraceLine(281,0,__PYX_ERR(0, 281, __pyx_L1_error))
  dgecon_(__pyx_v_norm, (&__pyx_v_N), ((double *)__pyx_v_LU->data), (&__pyx_v_N), (&__pyx_v_normA), (&__pyx_v_rcond), ((double *)__pyx_v_work->data), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":285
 *                      <l_int *>iwork.data, &info)
 * 
 *     assert info == 0, "Argument error in dgecon"             # <<<<<<<<<<<<<<
 * 
 *     return rcond
 */
  __Pyx_TraceLine(285,0,__PYX_ERR(0, 285, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dgecon);
      __PYX_ERR(0, 285, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":287
 *     assert info == 0, "Argument error in dgecon"
 * 
 *     return rcond             # <<<<<<<<<<<<<<
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,
 */
  __Pyx_TraceLine(287,0,__PYX_ERR(0, 287, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_25cgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_25cgecon = {"cgecon", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_25cgecon, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_25cgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  float __pyx_v_normA;
  char *__pyx_v_norm;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cgecon (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_normA,&__pyx_n_s_norm,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_LU)) != 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_normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgecon", 0, 2, 3, 1); __PYX_ERR(0, 289, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_norm);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cgecon") < 0)) __PYX_ERR(0, 289, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_normA = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_normA == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 290, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsWritableString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) __PYX_ERR(0, 290, __pyx_L3_error)
    } else {
      __pyx_v_norm = ((char *)((char *)"1"));
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 289, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.cgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 289, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_24cgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_24cgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, float __pyx_v_normA, char *__pyx_v_norm) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  float __pyx_v_rcond;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__22)
  __Pyx_RefNannySetupContext("cgecon", 0);
  __Pyx_TraceCall("cgecon", __pyx_f[0], 289, 0, __PYX_ERR(0, 289, __pyx_L1_error));
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 289, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":296
 *     cdef np.ndarray[np.float32_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     N = LU.shape[0]
 */
  __Pyx_TraceLine(296,0,__PYX_ERR(0, 296, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 296, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 296, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 296, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":298
 *     assert_fortran_mat(LU)
 * 
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(2*N, dtype = np.float32)
 */
  __Pyx_TraceLine(298,0,__PYX_ERR(0, 298, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":299
 * 
 *     N = LU.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(299,0,__PYX_ERR(0, 299, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 299, __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, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 299, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 299, __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, 299, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 299, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 299, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 299, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":300
 *     N = LU.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(2*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cgecon_(norm, &N, <float complex *>LU.data, &N, &normA,
 */
  __Pyx_TraceLine(300,0,__PYX_ERR(0, 300, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 300, __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, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 300, __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, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 300, __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, 300, __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, 300, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 300, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 300, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":302
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 *     f_lapack.cgecon_(norm, &N, <float complex *>LU.data, &N, &normA,             # <<<<<<<<<<<<<<
 *                      &rcond, <float complex *>work.data,
 *                      <float *>rwork.data, &info)
 */
  __Pyx_TraceLine(302,0,__PYX_ERR(0, 302, __pyx_L1_error))
  cgecon_(__pyx_v_norm, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_LU->data), (&__pyx_v_N), (&__pyx_v_normA), (&__pyx_v_rcond), ((__pyx_t_float_complex *)__pyx_v_work->data), ((float *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":306
 *                      <float *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in cgecon"             # <<<<<<<<<<<<<<
 * 
 *     return rcond
 */
  __Pyx_TraceLine(306,0,__PYX_ERR(0, 306, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cgecon);
      __PYX_ERR(0, 306, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":308
 *     assert info == 0, "Argument error in cgecon"
 * 
 *     return rcond             # <<<<<<<<<<<<<<
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,
 */
  __Pyx_TraceLine(308,0,__PYX_ERR(0, 308, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_27zgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_27zgecon = {"zgecon", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_27zgecon, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_27zgecon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_LU = 0;
  double __pyx_v_normA;
  char *__pyx_v_norm;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zgecon (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_LU,&__pyx_n_s_normA,&__pyx_n_s_norm,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_LU)) != 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_normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgecon", 0, 2, 3, 1); __PYX_ERR(0, 310, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_norm);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zgecon") < 0)) __PYX_ERR(0, 310, __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_LU = ((PyArrayObject *)values[0]);
    __pyx_v_normA = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_normA == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 311, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsWritableString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) __PYX_ERR(0, 311, __pyx_L3_error)
    } else {
      __pyx_v_norm = ((char *)((char *)"1"));
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 310, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.zgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_LU), __pyx_ptype_5numpy_ndarray, 1, "LU", 0))) __PYX_ERR(0, 310, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_26zgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_26zgecon(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_LU, double __pyx_v_normA, char *__pyx_v_norm) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  double __pyx_v_rcond;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_LU;
  __Pyx_Buffer __pyx_pybuffer_LU;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__23)
  __Pyx_RefNannySetupContext("zgecon", 0);
  __Pyx_TraceCall("zgecon", __pyx_f[0], 310, 0, __PYX_ERR(0, 310, __pyx_L1_error));
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_LU.pybuffer.buf = NULL;
  __pyx_pybuffer_LU.refcount = 0;
  __pyx_pybuffernd_LU.data = NULL;
  __pyx_pybuffernd_LU.rcbuffer = &__pyx_pybuffer_LU;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_LU.rcbuffer->pybuffer, (PyObject*)__pyx_v_LU, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 310, __pyx_L1_error)
  }
  __pyx_pybuffernd_LU.diminfo[0].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_LU.diminfo[0].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_LU.diminfo[1].strides = __pyx_pybuffernd_LU.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_LU.diminfo[1].shape = __pyx_pybuffernd_LU.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":317
 *     cdef np.ndarray[np.float64_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(LU)             # <<<<<<<<<<<<<<
 * 
 *     N = LU.shape[0]
 */
  __Pyx_TraceLine(317,0,__PYX_ERR(0, 317, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_LU)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_LU)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_LU));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_LU));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":319
 *     assert_fortran_mat(LU)
 * 
 *     N = LU.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(2*N, dtype = np.float64)
 */
  __Pyx_TraceLine(319,0,__PYX_ERR(0, 319, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_LU->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":320
 * 
 *     N = LU.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(320,0,__PYX_ERR(0, 320, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __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, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 320, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 320, __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, 320, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 320, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 320, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 320, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":321
 *     N = LU.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(2*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zgecon_(norm, &N, <double complex *>LU.data, &N, &normA,
 */
  __Pyx_TraceLine(321,0,__PYX_ERR(0, 321, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 321, __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, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __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, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __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, 321, __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, 321, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 321, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 321, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":323
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 *     f_lapack.zgecon_(norm, &N, <double complex *>LU.data, &N, &normA,             # <<<<<<<<<<<<<<
 *                      &rcond, <double complex *>work.data,
 *                      <double *>rwork.data, &info)
 */
  __Pyx_TraceLine(323,0,__PYX_ERR(0, 323, __pyx_L1_error))
  zgecon_(__pyx_v_norm, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_LU->data), (&__pyx_v_N), (&__pyx_v_normA), (&__pyx_v_rcond), ((__pyx_t_double_complex *)__pyx_v_work->data), ((double *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":327
 *                      <double *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in zgecon"             # <<<<<<<<<<<<<<
 * 
 *     return rcond
 */
  __Pyx_TraceLine(327,0,__PYX_ERR(0, 327, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgecon);
      __PYX_ERR(0, 327, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":329
 *     assert info == 0, "Argument error in zgecon"
 * 
 *     return rcond             # <<<<<<<<<<<<<<
 * 
 * # Wrappers for xGGEV
 */
  __Pyx_TraceLine(329,0,__PYX_ERR(0, 329, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zgecon", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_LU.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":334
 * 
 * # Helper function for xGGEV
 * def ggev_postprocess(dtype, alphar, alphai, vl_r=None, vr_r=None):             # <<<<<<<<<<<<<<
 *     # depending on whether the eigenvalues are purely real or complex,
 *     # some post-processing of the eigenvalues and -vectors is necessary
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_29ggev_postprocess(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_29ggev_postprocess = {"ggev_postprocess", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_29ggev_postprocess, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_29ggev_postprocess(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dtype = 0;
  PyObject *__pyx_v_alphar = 0;
  PyObject *__pyx_v_alphai = 0;
  PyObject *__pyx_v_vl_r = 0;
  PyObject *__pyx_v_vr_r = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ggev_postprocess (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dtype,&__pyx_n_s_alphar,&__pyx_n_s_alphai,&__pyx_n_s_vl_r,&__pyx_n_s_vr_r,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)Py_None);
    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_dtype)) != 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_alphar)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ggev_postprocess", 0, 3, 5, 1); __PYX_ERR(0, 334, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alphai)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ggev_postprocess", 0, 3, 5, 2); __PYX_ERR(0, 334, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_vl_r);
          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_vr_r);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ggev_postprocess") < 0)) __PYX_ERR(0, 334, __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_dtype = values[0];
    __pyx_v_alphar = values[1];
    __pyx_v_alphai = values[2];
    __pyx_v_vl_r = values[3];
    __pyx_v_vr_r = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ggev_postprocess", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 334, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ggev_postprocess", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_28ggev_postprocess(__pyx_self, __pyx_v_dtype, __pyx_v_alphar, __pyx_v_alphai, __pyx_v_vl_r, __pyx_v_vr_r);

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

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_28ggev_postprocess(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtype, PyObject *__pyx_v_alphar, PyObject *__pyx_v_alphai, PyObject *__pyx_v_vl_r, PyObject *__pyx_v_vr_r) {
  PyObject *__pyx_v_indx = NULL;
  PyObject *__pyx_v_alpha = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_vr = 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;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__24)
  __Pyx_RefNannySetupContext("ggev_postprocess", 0);
  __Pyx_TraceCall("ggev_postprocess", __pyx_f[0], 334, 0, __PYX_ERR(0, 334, __pyx_L1_error));

  /* "kwant/linalg/lapack.pyx":338
 *     # some post-processing of the eigenvalues and -vectors is necessary
 * 
 *     indx = (alphai > 0.0).nonzero()[0]             # <<<<<<<<<<<<<<
 * 
 *     if indx.size:
 */
  __Pyx_TraceLine(338,0,__PYX_ERR(0, 338, __pyx_L1_error))
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_alphai, __pyx_float_0_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && 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);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_indx = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":340
 *     indx = (alphai > 0.0).nonzero()[0]
 * 
 *     if indx.size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 * 
 */
  __Pyx_TraceLine(340,0,__PYX_ERR(0, 340, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_indx, __pyx_n_s_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {

    /* "kwant/linalg/lapack.pyx":341
 * 
 *     if indx.size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 * 
 *         if vl_r is not None:
 */
    __Pyx_TraceLine(341,0,__PYX_ERR(0, 341, __pyx_L1_error))
    __pyx_t_3 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_3, __pyx_v_alphai); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(__pyx_v_alphar, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_alpha = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":343
 *         alpha = alphar + 1j * alphai
 * 
 *         if vl_r is not None:             # <<<<<<<<<<<<<<
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:
 */
    __Pyx_TraceLine(343,0,__PYX_ERR(0, 343, __pyx_L1_error))
    __pyx_t_4 = (__pyx_v_vl_r != Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "kwant/linalg/lapack.pyx":344
 * 
 *         if vl_r is not None:
 *             vl = np.array(vl_r, dtype = dtype)             # <<<<<<<<<<<<<<
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]
 */
      __Pyx_TraceLine(344,0,__PYX_ERR(0, 344, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __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, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_vl_r);
      __Pyx_GIVEREF(__pyx_v_vl_r);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_vl_r);
      __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 344, __pyx_L1_error)
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_vl = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":345
 *         if vl_r is not None:
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:             # <<<<<<<<<<<<<<
 *                 vl.imag[:, i] = vl_r[:,i+1]
 *                 vl[:, i+1] = np.conj(vl[:, i])
 */
      __Pyx_TraceLine(345,0,__PYX_ERR(0, 345, __pyx_L1_error))
      if (likely(PyList_CheckExact(__pyx_v_indx)) || PyTuple_CheckExact(__pyx_v_indx)) {
        __pyx_t_6 = __pyx_v_indx; __Pyx_INCREF(__pyx_t_6); __pyx_t_7 = 0;
        __pyx_t_8 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_indx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 345, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 345, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_8)) {
          if (likely(PyList_CheckExact(__pyx_t_6))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_6)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 345, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 345, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_8(__pyx_t_6);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 345, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "kwant/linalg/lapack.pyx":346
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]             # <<<<<<<<<<<<<<
 *                 vl[:, i+1] = np.conj(vl[:, i])
 *         else:
 */
        __Pyx_TraceLine(346,0,__PYX_ERR(0, 346, __pyx_L1_error))
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_slice__25);
        __Pyx_GIVEREF(__pyx_slice__25);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_slice__25);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_vl_r, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_vl, __pyx_n_s_imag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_slice__26);
        __Pyx_GIVEREF(__pyx_slice__26);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__26);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_i);
        if (unlikely(PyObject_SetItem(__pyx_t_3, __pyx_t_1, __pyx_t_2) < 0)) __PYX_ERR(0, 346, __pyx_L1_error)
        __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;

        /* "kwant/linalg/lapack.pyx":347
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]
 *                 vl[:, i+1] = np.conj(vl[:, i])             # <<<<<<<<<<<<<<
 *         else:
 *             vl = None
 */
        __Pyx_TraceLine(347,0,__PYX_ERR(0, 347, __pyx_L1_error))
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_conj); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_slice__27);
        __Pyx_GIVEREF(__pyx_slice__27);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__27);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_i);
        __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_vl, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __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);
          }
        }
        if (!__pyx_t_1) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_3)) {
            PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_9};
            __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
            PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_9};
            __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          {
            __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 347, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL;
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_9);
            __pyx_t_9 = 0;
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __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_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_INCREF(__pyx_slice__28);
        __Pyx_GIVEREF(__pyx_slice__28);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_slice__28);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
        __pyx_t_3 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_vl, __pyx_t_10, __pyx_t_2) < 0)) __PYX_ERR(0, 347, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "kwant/linalg/lapack.pyx":345
 *         if vl_r is not None:
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:             # <<<<<<<<<<<<<<
 *                 vl.imag[:, i] = vl_r[:,i+1]
 *                 vl[:, i+1] = np.conj(vl[:, i])
 */
        __Pyx_TraceLine(345,0,__PYX_ERR(0, 345, __pyx_L1_error))
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":343
 *         alpha = alphar + 1j * alphai
 * 
 *         if vl_r is not None:             # <<<<<<<<<<<<<<
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:
 */
      goto __pyx_L4;
    }

    /* "kwant/linalg/lapack.pyx":349
 *                 vl[:, i+1] = np.conj(vl[:, i])
 *         else:
 *             vl = None             # <<<<<<<<<<<<<<
 * 
 *         if vr_r is not None:
 */
    __Pyx_TraceLine(349,0,__PYX_ERR(0, 349, __pyx_L1_error))
    /*else*/ {
      __Pyx_INCREF(Py_None);
      __pyx_v_vl = Py_None;
    }
    __pyx_L4:;

    /* "kwant/linalg/lapack.pyx":351
 *             vl = None
 * 
 *         if vr_r is not None:             # <<<<<<<<<<<<<<
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:
 */
    __Pyx_TraceLine(351,0,__PYX_ERR(0, 351, __pyx_L1_error))
    __pyx_t_5 = (__pyx_v_vr_r != Py_None);
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (__pyx_t_4) {

      /* "kwant/linalg/lapack.pyx":352
 * 
 *         if vr_r is not None:
 *             vr = np.array(vr_r, dtype = dtype)             # <<<<<<<<<<<<<<
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]
 */
      __Pyx_TraceLine(352,0,__PYX_ERR(0, 352, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __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, 352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_v_vr_r);
      __Pyx_GIVEREF(__pyx_v_vr_r);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_vr_r);
      __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 352, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_v_vr = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":353
 *         if vr_r is not None:
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:             # <<<<<<<<<<<<<<
 *                 vr.imag[:, i] = vr_r[:,i+1]
 *                 vr[:, i+1] = np.conj(vr[:, i])
 */
      __Pyx_TraceLine(353,0,__PYX_ERR(0, 353, __pyx_L1_error))
      if (likely(PyList_CheckExact(__pyx_v_indx)) || PyTuple_CheckExact(__pyx_v_indx)) {
        __pyx_t_3 = __pyx_v_indx; __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_indx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __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(0, 353, __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_10 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_10); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 353, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 353, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_10); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 353, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 353, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          }
        } else {
          __pyx_t_10 = __pyx_t_8(__pyx_t_3);
          if (unlikely(!__pyx_t_10)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 353, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_10);
        }
        __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "kwant/linalg/lapack.pyx":354
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]             # <<<<<<<<<<<<<<
 *                 vr[:, i+1] = np.conj(vr[:, i])
 *         else:
 */
        __Pyx_TraceLine(354,0,__PYX_ERR(0, 354, __pyx_L1_error))
        __pyx_t_10 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_slice__29);
        __Pyx_GIVEREF(__pyx_slice__29);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_slice__29);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_vr_r, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_vr, __pyx_n_s_imag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_slice__30);
        __Pyx_GIVEREF(__pyx_slice__30);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__30);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_i);
        if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_t_2, __pyx_t_10) < 0)) __PYX_ERR(0, 354, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "kwant/linalg/lapack.pyx":355
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]
 *                 vr[:, i+1] = np.conj(vr[:, i])             # <<<<<<<<<<<<<<
 *         else:
 *             vr = None
 */
        __Pyx_TraceLine(355,0,__PYX_ERR(0, 355, __pyx_L1_error))
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_conj); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_slice__31);
        __Pyx_GIVEREF(__pyx_slice__31);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__31);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_i);
        __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_vr, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 355, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_9};
            __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 355, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_9};
            __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 355, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          {
            __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __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 = NULL;
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_9);
            __pyx_t_9 = 0;
            __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 355, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_slice__32);
        __Pyx_GIVEREF(__pyx_slice__32);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__32);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
        __pyx_t_6 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_vr, __pyx_t_1, __pyx_t_10) < 0)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "kwant/linalg/lapack.pyx":353
 *         if vr_r is not None:
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:             # <<<<<<<<<<<<<<
 *                 vr.imag[:, i] = vr_r[:,i+1]
 *                 vr[:, i+1] = np.conj(vr[:, i])
 */
        __Pyx_TraceLine(353,0,__PYX_ERR(0, 353, __pyx_L1_error))
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":351
 *             vl = None
 * 
 *         if vr_r is not None:             # <<<<<<<<<<<<<<
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:
 */
      goto __pyx_L7;
    }

    /* "kwant/linalg/lapack.pyx":357
 *                 vr[:, i+1] = np.conj(vr[:, i])
 *         else:
 *             vr = None             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __Pyx_TraceLine(357,0,__PYX_ERR(0, 357, __pyx_L1_error))
    /*else*/ {
      __Pyx_INCREF(Py_None);
      __pyx_v_vr = Py_None;
    }
    __pyx_L7:;

    /* "kwant/linalg/lapack.pyx":340
 *     indx = (alphai > 0.0).nonzero()[0]
 * 
 *     if indx.size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 * 
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":359
 *             vr = None
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 *         vl = vl_r
 *         vr = vr_r
 */
  __Pyx_TraceLine(359,0,__PYX_ERR(0, 359, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(__pyx_v_alphar);
    __pyx_v_alpha = __pyx_v_alphar;

    /* "kwant/linalg/lapack.pyx":360
 *     else:
 *         alpha = alphar
 *         vl = vl_r             # <<<<<<<<<<<<<<
 *         vr = vr_r
 * 
 */
    __Pyx_TraceLine(360,0,__PYX_ERR(0, 360, __pyx_L1_error))
    __Pyx_INCREF(__pyx_v_vl_r);
    __pyx_v_vl = __pyx_v_vl_r;

    /* "kwant/linalg/lapack.pyx":361
 *         alpha = alphar
 *         vl = vl_r
 *         vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     return (alpha, vl, vr)
 */
    __Pyx_TraceLine(361,0,__PYX_ERR(0, 361, __pyx_L1_error))
    __Pyx_INCREF(__pyx_v_vr_r);
    __pyx_v_vr = __pyx_v_vr_r;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":363
 *         vr = vr_r
 * 
 *     return (alpha, vl, vr)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(363,0,__PYX_ERR(0, 363, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_alpha);
  __Pyx_INCREF(__pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_vr);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":334
 * 
 * # Helper function for xGGEV
 * def ggev_postprocess(dtype, alphar, alphai, vl_r=None, vr_r=None):             # <<<<<<<<<<<<<<
 *     # depending on whether the eigenvalues are purely real or complex,
 *     # some post-processing of the eigenvalues and -vectors is necessary
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("kwant.linalg.lapack.ggev_postprocess", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_indx);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":366
 * 
 * 
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_31sggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_31sggev = {"sggev", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_31sggev, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_31sggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sggev (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":368
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, lwork
 *     cdef char *jobvl
 */
    values[2] = ((PyObject *)Py_False);
    values[3] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sggev", 0, 2, 4, 1); __PYX_ERR(0, 366, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          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_right);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sggev") < 0)) __PYX_ERR(0, 366, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_left = values[2];
    __pyx_v_right = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sggev", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 366, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.sggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 366, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 367, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_30sggev(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":366
 * 
 * 
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_30sggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  char *__pyx_v_jobvl;
  char *__pyx_v_jobvr;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  float *__pyx_v_vl_ptr;
  float *__pyx_v_vr_ptr;
  float __pyx_v_qwork;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyObject *__pyx_v_alpha = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__33)
  __Pyx_RefNannySetupContext("sggev", 0);
  __Pyx_TraceCall("sggev", __pyx_f[0], 366, 0, __PYX_ERR(0, 366, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 366, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 366, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":378
 *     cdef np.ndarray[np.float32_t, ndim=1] work, alphar, alphai, beta
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(378,0,__PYX_ERR(0, 378, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 378, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":380
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(380,0,__PYX_ERR(0, 380, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":381
 * 
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(381,0,__PYX_ERR(0, 381, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 381, __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, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 381, __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, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 381, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 381, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 381, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":382
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(382,0,__PYX_ERR(0, 382, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 382, __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, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 382, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 382, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 382, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":383
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __Pyx_TraceLine(383,0,__PYX_ERR(0, 383, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 383, __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, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 383, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 383, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":385
 *     beta = np.empty(N, dtype = np.float32)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vl_ptr = <float *>vl_r.data
 */
  __Pyx_TraceLine(385,0,__PYX_ERR(0, 385, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 385, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":386
 * 
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float *>vl_r.data
 *         jobvl = "V"
 */
    __Pyx_TraceLine(386,0,__PYX_ERR(0, 386, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 386, __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, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 386, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 386, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 386, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 386, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 386, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":387
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vl_ptr = <float *>vl_r.data             # <<<<<<<<<<<<<<
 *         jobvl = "V"
 *     else:
 */
    __Pyx_TraceLine(387,0,__PYX_ERR(0, 387, __pyx_L1_error))
    __pyx_v_vl_ptr = ((float *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":388
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vl_ptr = <float *>vl_r.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r = None
 */
    __Pyx_TraceLine(388,0,__PYX_ERR(0, 388, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":385
 *     beta = np.empty(N, dtype = np.float32)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vl_ptr = <float *>vl_r.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":390
 *         jobvl = "V"
 *     else:
 *         vl_r = None             # <<<<<<<<<<<<<<
 *         vl_ptr = NULL
 *         jobvl = "N"
 */
  __Pyx_TraceLine(390,0,__PYX_ERR(0, 390, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 390, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vl_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":391
 *     else:
 *         vl_r = None
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __Pyx_TraceLine(391,0,__PYX_ERR(0, 391, __pyx_L1_error))
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":392
 *         vl_r = None
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __Pyx_TraceLine(392,0,__PYX_ERR(0, 392, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":394
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data
 */
  __Pyx_TraceLine(394,0,__PYX_ERR(0, 394, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 394, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":395
 * 
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float *>vr_r.data
 *         jobvr = "V"
 */
    __Pyx_TraceLine(395,0,__PYX_ERR(0, 395, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 395, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 395, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 395, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 395, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 395, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":396
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data             # <<<<<<<<<<<<<<
 *         jobvr = "V"
 *     else:
 */
    __Pyx_TraceLine(396,0,__PYX_ERR(0, 396, __pyx_L1_error))
    __pyx_v_vr_ptr = ((float *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":397
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r = None
 */
    __Pyx_TraceLine(397,0,__PYX_ERR(0, 397, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":394
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":399
 *         jobvr = "V"
 *     else:
 *         vr_r = None             # <<<<<<<<<<<<<<
 *         vr_ptr = NULL
 *         jobvr = "N"
 */
  __Pyx_TraceLine(399,0,__PYX_ERR(0, 399, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 399, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vr_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":400
 *     else:
 *         vr_r = None
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __Pyx_TraceLine(400,0,__PYX_ERR(0, 400, __pyx_L1_error))
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":401
 *         vr_r = None
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(401,0,__PYX_ERR(0, 401, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":404
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.sggev_(jobvl, jobvr, &N, <float *>A.data, &N,
 */
  __Pyx_TraceLine(404,0,__PYX_ERR(0, 404, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":406
 *     lwork = -1
 * 
 *     f_lapack.sggev_(jobvl, jobvr, &N, <float *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <float *>B.data, &N,
 *                     <float *>alphar.data, <float *> alphai.data,
 */
  __Pyx_TraceLine(406,0,__PYX_ERR(0, 406, __pyx_L1_error))
  sggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), ((float *)__pyx_v_B->data), (&__pyx_v_N), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":413
 *                     &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in sggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork
 */
  __Pyx_TraceLine(413,0,__PYX_ERR(0, 413, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sggev);
      __PYX_ERR(0, 413, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":415
 *     assert info == 0, "Argument error in sggev"
 * 
 *     lwork = <l_int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(415,0,__PYX_ERR(0, 415, __pyx_L1_error))
  __pyx_v_lwork = ((__pyx_t_5kwant_6linalg_8f_lapack_l_int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":416
 * 
 *     lwork = <l_int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(416,0,__PYX_ERR(0, 416, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 416, __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, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 416, __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, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __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, 416, __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, 416, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 416, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 416, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":419
 * 
 *     # Now the real calculation
 *     f_lapack.sggev_(jobvl, jobvr, &N, <float *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <float *>B.data, &N,
 *                     <float *>alphar.data, <float *> alphai.data,
 */
  __Pyx_TraceLine(419,0,__PYX_ERR(0, 419, __pyx_L1_error))
  sggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), ((float *)__pyx_v_B->data), (&__pyx_v_N), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), ((float *)__pyx_v_work->data), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":426
 *                     <float *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sggev")
 * 
 */
  __Pyx_TraceLine(426,0,__PYX_ERR(0, 426, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":427
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sggev"
 */
    __Pyx_TraceLine(427,0,__PYX_ERR(0, 427, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __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, 427, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":426
 *                     <float *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sggev")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":429
 *         raise LinAlgError("QZ iteration failed to converge in sggev")
 * 
 *     assert info == 0, "Argument error in sggev"             # <<<<<<<<<<<<<<
 * 
 *     alpha, vl, vr = ggev_postprocess(np.complex64, alphar, alphai, vl_r, vr_r)
 */
  __Pyx_TraceLine(429,0,__PYX_ERR(0, 429, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sggev);
      __PYX_ERR(0, 429, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":431
 *     assert info == 0, "Argument error in sggev"
 * 
 *     alpha, vl, vr = ggev_postprocess(np.complex64, alphar, alphai, vl_r, vr_r)             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))
 */
  __Pyx_TraceLine(431,0,__PYX_ERR(0, 431, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ggev_postprocess); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_alphar), ((PyObject *)__pyx_v_alphai), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_vr_r)};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 5+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_alphar), ((PyObject *)__pyx_v_alphai), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_vr_r)};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 5+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(5+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_alphar));
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_alphar));
    __Pyx_INCREF(((PyObject *)__pyx_v_alphai));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_alphai));
    PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_4, ((PyObject *)__pyx_v_alphai));
    __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
    PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
    PyTuple_SET_ITEM(__pyx_t_6, 4+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 431, __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_6 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_6 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    index = 2; __pyx_t_3 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_5), 3) < 0) __PYX_ERR(0, 431, __pyx_L1_error)
    __pyx_t_13 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_13 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 431, __pyx_L1_error)
    __pyx_L7_unpacking_done:;
  }
  __pyx_v_alpha = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_vl = __pyx_t_6;
  __pyx_t_6 = 0;
  __pyx_v_vr = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":433
 *     alpha, vl, vr = ggev_postprocess(np.complex64, alphar, alphai, vl_r, vr_r)
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(433,0,__PYX_ERR(0, 433, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 1, Py_True);
  __Pyx_INCREF(__pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_right);
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(__pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_vr);
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 433, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_1);
    __pyx_t_6 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":366
 * 
 * 
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":436
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_33dggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_33dggev = {"dggev", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_33dggev, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_33dggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dggev (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":438
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, lwork
 *     cdef char *jobvl
 */
    values[2] = ((PyObject *)Py_False);
    values[3] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dggev", 0, 2, 4, 1); __PYX_ERR(0, 436, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          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_right);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dggev") < 0)) __PYX_ERR(0, 436, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_left = values[2];
    __pyx_v_right = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dggev", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 436, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 436, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 437, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_32dggev(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":436
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_32dggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  char *__pyx_v_jobvl;
  char *__pyx_v_jobvr;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  double *__pyx_v_vl_ptr;
  double *__pyx_v_vr_ptr;
  double __pyx_v_qwork;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyObject *__pyx_v_alpha = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__35)
  __Pyx_RefNannySetupContext("dggev", 0);
  __Pyx_TraceCall("dggev", __pyx_f[0], 436, 0, __PYX_ERR(0, 436, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 436, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 436, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":448
 *     cdef np.ndarray[np.float64_t, ndim=1] work, alphar, alphai, beta
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(448,0,__PYX_ERR(0, 448, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 448, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":450
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(450,0,__PYX_ERR(0, 450, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":451
 * 
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(451,0,__PYX_ERR(0, 451, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __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, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 451, __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, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 451, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 451, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 451, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":452
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(452,0,__PYX_ERR(0, 452, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 452, __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, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 452, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 452, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 452, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 452, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":453
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __Pyx_TraceLine(453,0,__PYX_ERR(0, 453, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 453, __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, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 453, __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, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 453, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 453, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":455
 *     beta = np.empty(N, dtype = np.float64)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vl_ptr = <double *>vl_r.data
 */
  __Pyx_TraceLine(455,0,__PYX_ERR(0, 455, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 455, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":456
 * 
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double *>vl_r.data
 *         jobvl = "V"
 */
    __Pyx_TraceLine(456,0,__PYX_ERR(0, 456, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __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, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 456, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 456, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 456, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 456, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 456, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 456, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":457
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vl_ptr = <double *>vl_r.data             # <<<<<<<<<<<<<<
 *         jobvl = "V"
 *     else:
 */
    __Pyx_TraceLine(457,0,__PYX_ERR(0, 457, __pyx_L1_error))
    __pyx_v_vl_ptr = ((double *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":458
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vl_ptr = <double *>vl_r.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r = None
 */
    __Pyx_TraceLine(458,0,__PYX_ERR(0, 458, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":455
 *     beta = np.empty(N, dtype = np.float64)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vl_ptr = <double *>vl_r.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":460
 *         jobvl = "V"
 *     else:
 *         vl_r = None             # <<<<<<<<<<<<<<
 *         vl_ptr = NULL
 *         jobvl = "N"
 */
  __Pyx_TraceLine(460,0,__PYX_ERR(0, 460, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 460, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vl_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":461
 *     else:
 *         vl_r = None
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __Pyx_TraceLine(461,0,__PYX_ERR(0, 461, __pyx_L1_error))
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":462
 *         vl_r = None
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __Pyx_TraceLine(462,0,__PYX_ERR(0, 462, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":464
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data
 */
  __Pyx_TraceLine(464,0,__PYX_ERR(0, 464, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 464, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":465
 * 
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double *>vr_r.data
 *         jobvr = "V"
 */
    __Pyx_TraceLine(465,0,__PYX_ERR(0, 465, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 465, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 465, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __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, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 465, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 465, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 465, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":466
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data             # <<<<<<<<<<<<<<
 *         jobvr = "V"
 *     else:
 */
    __Pyx_TraceLine(466,0,__PYX_ERR(0, 466, __pyx_L1_error))
    __pyx_v_vr_ptr = ((double *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":467
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r = None
 */
    __Pyx_TraceLine(467,0,__PYX_ERR(0, 467, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":464
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":469
 *         jobvr = "V"
 *     else:
 *         vr_r = None             # <<<<<<<<<<<<<<
 *         vr_ptr = NULL
 *         jobvr = "N"
 */
  __Pyx_TraceLine(469,0,__PYX_ERR(0, 469, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 469, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vr_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":470
 *     else:
 *         vr_r = None
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __Pyx_TraceLine(470,0,__PYX_ERR(0, 470, __pyx_L1_error))
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":471
 *         vr_r = None
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(471,0,__PYX_ERR(0, 471, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":474
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dggev_(jobvl, jobvr, &N, <double *>A.data, &N,
 */
  __Pyx_TraceLine(474,0,__PYX_ERR(0, 474, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":476
 *     lwork = -1
 * 
 *     f_lapack.dggev_(jobvl, jobvr, &N, <double *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <double *>B.data, &N,
 *                     <double *>alphar.data, <double *> alphai.data,
 */
  __Pyx_TraceLine(476,0,__PYX_ERR(0, 476, __pyx_L1_error))
  dggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), ((double *)__pyx_v_B->data), (&__pyx_v_N), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":483
 *                     &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in dggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork
 */
  __Pyx_TraceLine(483,0,__PYX_ERR(0, 483, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dggev);
      __PYX_ERR(0, 483, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":485
 *     assert info == 0, "Argument error in dggev"
 * 
 *     lwork = <l_int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(485,0,__PYX_ERR(0, 485, __pyx_L1_error))
  __pyx_v_lwork = ((__pyx_t_5kwant_6linalg_8f_lapack_l_int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":486
 * 
 *     lwork = <l_int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(486,0,__PYX_ERR(0, 486, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 486, __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, 486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __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, 486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 486, __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, 486, __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, 486, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 486, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 486, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":489
 * 
 *     # Now the real calculation
 *     f_lapack.dggev_(jobvl, jobvr, &N, <double *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <double *>B.data, &N,
 *                     <double *>alphar.data, <double *> alphai.data,
 */
  __Pyx_TraceLine(489,0,__PYX_ERR(0, 489, __pyx_L1_error))
  dggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), ((double *)__pyx_v_B->data), (&__pyx_v_N), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), ((double *)__pyx_v_work->data), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":496
 *                     <double *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dggev")
 * 
 */
  __Pyx_TraceLine(496,0,__PYX_ERR(0, 496, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":497
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dggev"
 */
    __Pyx_TraceLine(497,0,__PYX_ERR(0, 497, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 497, __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, 497, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":496
 *                     <double *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dggev")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":499
 *         raise LinAlgError("QZ iteration failed to converge in dggev")
 * 
 *     assert info == 0, "Argument error in dggev"             # <<<<<<<<<<<<<<
 * 
 *     alpha, vl, vr = ggev_postprocess(np.complex128, alphar, alphai, vl_r, vr_r)
 */
  __Pyx_TraceLine(499,0,__PYX_ERR(0, 499, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dggev);
      __PYX_ERR(0, 499, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":501
 *     assert info == 0, "Argument error in dggev"
 * 
 *     alpha, vl, vr = ggev_postprocess(np.complex128, alphar, alphai, vl_r, vr_r)             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))
 */
  __Pyx_TraceLine(501,0,__PYX_ERR(0, 501, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ggev_postprocess); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_alphar), ((PyObject *)__pyx_v_alphai), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_vr_r)};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 5+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_alphar), ((PyObject *)__pyx_v_alphai), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_vr_r)};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 5+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(5+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_alphar));
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_alphar));
    __Pyx_INCREF(((PyObject *)__pyx_v_alphai));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_alphai));
    PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_4, ((PyObject *)__pyx_v_alphai));
    __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
    PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
    PyTuple_SET_ITEM(__pyx_t_6, 4+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 501, __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_6 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 501, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_6 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    index = 2; __pyx_t_3 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_5), 3) < 0) __PYX_ERR(0, 501, __pyx_L1_error)
    __pyx_t_13 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_13 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 501, __pyx_L1_error)
    __pyx_L7_unpacking_done:;
  }
  __pyx_v_alpha = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_vl = __pyx_t_6;
  __pyx_t_6 = 0;
  __pyx_v_vr = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":503
 *     alpha, vl, vr = ggev_postprocess(np.complex128, alphar, alphai, vl_r, vr_r)
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(503,0,__PYX_ERR(0, 503, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 1, Py_True);
  __Pyx_INCREF(__pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_right);
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(__pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_vr);
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_1);
    __pyx_t_6 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":436
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":506
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_35cggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_35cggev = {"cggev", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_35cggev, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_35cggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cggev (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":508
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, lwork
 *     cdef char *jobvl
 */
    values[2] = ((PyObject *)Py_False);
    values[3] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cggev", 0, 2, 4, 1); __PYX_ERR(0, 506, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          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_right);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cggev") < 0)) __PYX_ERR(0, 506, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_left = values[2];
    __pyx_v_right = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cggev", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 506, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.cggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 506, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 507, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_34cggev(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":506
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_34cggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  char *__pyx_v_jobvl;
  char *__pyx_v_jobvr;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_float_complex *__pyx_v_vl_ptr;
  __pyx_t_float_complex *__pyx_v_vr_ptr;
  __pyx_t_float_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__37)
  __Pyx_RefNannySetupContext("cggev", 0);
  __Pyx_TraceCall("cggev", __pyx_f[0], 506, 0, __PYX_ERR(0, 506, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 506, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 506, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":519
 *     cdef np.ndarray[np.float32_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(519,0,__PYX_ERR(0, 519, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 519, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":521
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 */
  __Pyx_TraceLine(521,0,__PYX_ERR(0, 521, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":522
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(522,0,__PYX_ERR(0, 522, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 522, __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, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __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, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 522, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 522, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":523
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __Pyx_TraceLine(523,0,__PYX_ERR(0, 523, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 523, __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, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 523, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 523, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 523, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 523, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":525
 *     beta = np.empty(N, dtype = np.complex64)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data
 */
  __Pyx_TraceLine(525,0,__PYX_ERR(0, 525, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 525, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":526
 * 
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *         jobvl = "V"
 */
    __Pyx_TraceLine(526,0,__PYX_ERR(0, 526, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __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_5);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 526, __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(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 526, __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, 526, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 526, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 526, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 526, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 526, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":527
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data             # <<<<<<<<<<<<<<
 *         jobvl = "V"
 *     else:
 */
    __Pyx_TraceLine(527,0,__PYX_ERR(0, 527, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_float_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":528
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(528,0,__PYX_ERR(0, 528, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":525
 *     beta = np.empty(N, dtype = np.complex64)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":530
 *         jobvl = "V"
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
  __Pyx_TraceLine(530,0,__PYX_ERR(0, 530, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":531
 *     else:
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __Pyx_TraceLine(531,0,__PYX_ERR(0, 531, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":533
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data
 */
  __Pyx_TraceLine(533,0,__PYX_ERR(0, 533, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 533, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":534
 * 
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *         jobvr = "V"
 */
    __Pyx_TraceLine(534,0,__PYX_ERR(0, 534, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __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); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 534, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 534, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 534, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 534, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 534, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 534, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":535
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data             # <<<<<<<<<<<<<<
 *         jobvr = "V"
 *     else:
 */
    __Pyx_TraceLine(535,0,__PYX_ERR(0, 535, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_float_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":536
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(536,0,__PYX_ERR(0, 536, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":533
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":538
 *         jobvr = "V"
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
  __Pyx_TraceLine(538,0,__PYX_ERR(0, 538, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":539
 *     else:
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     rwork = np.empty(8 * N, dtype = np.float32)
 */
    __Pyx_TraceLine(539,0,__PYX_ERR(0, 539, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":541
 *         jobvr = "N"
 * 
 *     rwork = np.empty(8 * N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
  __Pyx_TraceLine(541,0,__PYX_ERR(0, 541, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((8 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 541, __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, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 541, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 541, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":544
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     work = np.empty(1, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(544,0,__PYX_ERR(0, 544, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":545
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,
 */
  __Pyx_TraceLine(545,0,__PYX_ERR(0, 545, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 545, __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, 545, __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, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 545, __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, 545, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__38, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 545, __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;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 545, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 545, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":547
 *     work = np.empty(1, dtype = np.complex64)
 * 
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <float complex *>B.data, &N,
 *                     <float complex *>alpha.data, <float complex *>beta.data,
 */
  __Pyx_TraceLine(547,0,__PYX_ERR(0, 547, __pyx_L1_error))
  cggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_B->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":554
 *                     <float *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in cggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork.real
 */
  __Pyx_TraceLine(554,0,__PYX_ERR(0, 554, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cggev);
      __PYX_ERR(0, 554, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":556
 *     assert info == 0, "Argument error in cggev"
 * 
 *     lwork = <l_int>qwork.real             # <<<<<<<<<<<<<<
 * 
 *     work = np.empty(lwork, dtype = np.complex64)
 */
  __Pyx_TraceLine(556,0,__PYX_ERR(0, 556, __pyx_L1_error))
  __pyx_v_lwork = ((__pyx_t_5kwant_6linalg_8f_lapack_l_int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":558
 *     lwork = <l_int>qwork.real
 * 
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(558,0,__PYX_ERR(0, 558, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 558, __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, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 558, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 558, __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_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 558, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 558, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_work, ((PyArrayObject *)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":561
 * 
 *     # Now the real calculation
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <float complex *>B.data, &N,
 *                     <float complex *>alpha.data, <float complex *>beta.data,
 */
  __Pyx_TraceLine(561,0,__PYX_ERR(0, 561, __pyx_L1_error))
  cggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_B->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":568
 *                     <float *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cggev")
 * 
 */
  __Pyx_TraceLine(568,0,__PYX_ERR(0, 568, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":569
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cggev"
 */
    __Pyx_TraceLine(569,0,__PYX_ERR(0, 569, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_ERR(0, 569, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":568
 *                     <float *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cggev")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":571
 *         raise LinAlgError("QZ iteration failed to converge in cggev")
 * 
 *     assert info == 0, "Argument error in cggev"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))
 */
  __Pyx_TraceLine(571,0,__PYX_ERR(0, 571, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cggev);
      __PYX_ERR(0, 571, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":573
 *     assert info == 0, "Argument error in cggev"
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(573,0,__PYX_ERR(0, 573, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 1, Py_True);
  __Pyx_INCREF(__pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_right);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_vl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_vr));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_2};
    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_2};
    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":506
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":576
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_37zggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_37zggev = {"zggev", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_37zggev, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_37zggev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zggev (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":578
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, lwork
 *     cdef char *jobvl
 */
    values[2] = ((PyObject *)Py_False);
    values[3] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zggev", 0, 2, 4, 1); __PYX_ERR(0, 576, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          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_right);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zggev") < 0)) __PYX_ERR(0, 576, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_left = values[2];
    __pyx_v_right = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zggev", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 576, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.zggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 576, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 577, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_36zggev(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":576
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_36zggev(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  char *__pyx_v_jobvl;
  char *__pyx_v_jobvr;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_double_complex *__pyx_v_vl_ptr;
  __pyx_t_double_complex *__pyx_v_vr_ptr;
  __pyx_t_double_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__40)
  __Pyx_RefNannySetupContext("zggev", 0);
  __Pyx_TraceCall("zggev", __pyx_f[0], 576, 0, __PYX_ERR(0, 576, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 576, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 576, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":589
 *     cdef np.ndarray[np.float64_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(589,0,__PYX_ERR(0, 589, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 589, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 589, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 589, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 589, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":591
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 */
  __Pyx_TraceLine(591,0,__PYX_ERR(0, 591, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":592
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(592,0,__PYX_ERR(0, 592, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __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, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __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, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 592, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 592, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 592, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":593
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __Pyx_TraceLine(593,0,__PYX_ERR(0, 593, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 593, __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, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 593, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 593, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 593, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":595
 *     beta = np.empty(N, dtype = np.complex128)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data
 */
  __Pyx_TraceLine(595,0,__PYX_ERR(0, 595, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 595, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":596
 * 
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *         jobvl = "V"
 */
    __Pyx_TraceLine(596,0,__PYX_ERR(0, 596, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __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_5);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 596, __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(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 596, __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, 596, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 596, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 596, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 596, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 596, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":597
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data             # <<<<<<<<<<<<<<
 *         jobvl = "V"
 *     else:
 */
    __Pyx_TraceLine(597,0,__PYX_ERR(0, 597, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_double_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":598
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(598,0,__PYX_ERR(0, 598, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":595
 *     beta = np.empty(N, dtype = np.complex128)
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":600
 *         jobvl = "V"
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
  __Pyx_TraceLine(600,0,__PYX_ERR(0, 600, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":601
 *     else:
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __Pyx_TraceLine(601,0,__PYX_ERR(0, 601, __pyx_L1_error))
    __pyx_v_jobvl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":603
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data
 */
  __Pyx_TraceLine(603,0,__PYX_ERR(0, 603, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 603, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":604
 * 
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *         jobvr = "V"
 */
    __Pyx_TraceLine(604,0,__PYX_ERR(0, 604, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 604, __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); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 604, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 604, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 604, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 604, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 604, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":605
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data             # <<<<<<<<<<<<<<
 *         jobvr = "V"
 *     else:
 */
    __Pyx_TraceLine(605,0,__PYX_ERR(0, 605, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_double_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":606
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(606,0,__PYX_ERR(0, 606, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":603
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":608
 *         jobvr = "V"
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
  __Pyx_TraceLine(608,0,__PYX_ERR(0, 608, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":609
 *     else:
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     rwork = np.empty(8 * N, dtype = np.float64)
 */
    __Pyx_TraceLine(609,0,__PYX_ERR(0, 609, __pyx_L1_error))
    __pyx_v_jobvr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":611
 *         jobvr = "N"
 * 
 *     rwork = np.empty(8 * N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
  __Pyx_TraceLine(611,0,__PYX_ERR(0, 611, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((8 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 611, __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, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 611, __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, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 611, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 611, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":614
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     work = np.empty(1, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(614,0,__PYX_ERR(0, 614, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":615
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,
 */
  __Pyx_TraceLine(615,0,__PYX_ERR(0, 615, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __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, 615, __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, 615, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 615, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __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, 615, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__41, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __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;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 615, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 615, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":617
 *     work = np.empty(1, dtype = np.complex128)
 * 
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <double complex *>B.data, &N,
 *                     <double complex *>alpha.data, <double complex *>beta.data,
 */
  __Pyx_TraceLine(617,0,__PYX_ERR(0, 617, __pyx_L1_error))
  zggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_B->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":624
 *                     <double *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in zggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork.real
 */
  __Pyx_TraceLine(624,0,__PYX_ERR(0, 624, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zggev);
      __PYX_ERR(0, 624, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":626
 *     assert info == 0, "Argument error in zggev"
 * 
 *     lwork = <l_int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(626,0,__PYX_ERR(0, 626, __pyx_L1_error))
  __pyx_v_lwork = ((__pyx_t_5kwant_6linalg_8f_lapack_l_int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":627
 * 
 *     lwork = <l_int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(627,0,__PYX_ERR(0, 627, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 627, __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, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 627, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 627, __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_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 627, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 627, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_work, ((PyArrayObject *)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":630
 * 
 *     # Now the real calculation
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     <double complex *>B.data, &N,
 *                     <double complex *>alpha.data, <double complex *>beta.data,
 */
  __Pyx_TraceLine(630,0,__PYX_ERR(0, 630, __pyx_L1_error))
  zggev_(__pyx_v_jobvl, __pyx_v_jobvr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_B->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":637
 *                     <double *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zggev")
 * 
 */
  __Pyx_TraceLine(637,0,__PYX_ERR(0, 637, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":638
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zggev"
 */
    __Pyx_TraceLine(638,0,__PYX_ERR(0, 638, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 638, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_ERR(0, 638, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":637
 *                     <double *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zggev")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":640
 *         raise LinAlgError("QZ iteration failed to converge in zggev")
 * 
 *     assert info == 0, "Argument error in zggev"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))
 */
  __Pyx_TraceLine(640,0,__PYX_ERR(0, 640, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zggev);
      __PYX_ERR(0, 640, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":642
 *     assert info == 0, "Argument error in zggev"
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(642,0,__PYX_ERR(0, 642, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 1, Py_True);
  __Pyx_INCREF(__pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_right);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_vl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_vr));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_2};
    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_2};
    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":576
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zggev", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":646
 * 
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_39sgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_39sgees = {"sgees", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_39sgees, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_39sgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sgees (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_calc_q,&__pyx_n_s_calc_ev,0};
    PyObject* values[3] = {0,0,0};

    /* "kwant/linalg/lapack.pyx":647
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,
 *           calc_q=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvs
 */
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_True);
    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_A)) != 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_calc_q);
          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_calc_ev);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sgees") < 0)) __PYX_ERR(0, 646, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_calc_q = values[1];
    __pyx_v_calc_ev = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sgees", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 646, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.sgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 646, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_38sgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":646
 * 
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_38sgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvs;
  float *__pyx_v_vs_ptr;
  float __pyx_v_qwork;
  PyArrayObject *__pyx_v_vs = 0;
  PyArrayObject *__pyx_v_wr = 0;
  PyArrayObject *__pyx_v_wi = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_w = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vs;
  __Pyx_Buffer __pyx_pybuffer_vs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wi;
  __Pyx_Buffer __pyx_pybuffer_wi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wr;
  __Pyx_Buffer __pyx_pybuffer_wr;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__43)
  __Pyx_RefNannySetupContext("sgees", 0);
  __Pyx_TraceCall("sgees", __pyx_f[0], 646, 0, __PYX_ERR(0, 646, __pyx_L1_error));
  __pyx_pybuffer_vs.pybuffer.buf = NULL;
  __pyx_pybuffer_vs.refcount = 0;
  __pyx_pybuffernd_vs.data = NULL;
  __pyx_pybuffernd_vs.rcbuffer = &__pyx_pybuffer_vs;
  __pyx_pybuffer_wr.pybuffer.buf = NULL;
  __pyx_pybuffer_wr.refcount = 0;
  __pyx_pybuffernd_wr.data = NULL;
  __pyx_pybuffernd_wr.rcbuffer = &__pyx_pybuffer_wr;
  __pyx_pybuffer_wi.pybuffer.buf = NULL;
  __pyx_pybuffer_wi.refcount = 0;
  __pyx_pybuffernd_wi.data = NULL;
  __pyx_pybuffernd_wi.rcbuffer = &__pyx_pybuffer_wi;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 646, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":655
 *     cdef np.ndarray[np.float32_t] wr, wi, work
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(655,0,__PYX_ERR(0, 655, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); 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_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":657
 *     assert_fortran_mat(A)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(657,0,__PYX_ERR(0, 657, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":658
 * 
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(658,0,__PYX_ERR(0, 658, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __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, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 658, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 658, __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, 658, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 658, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 658, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_v_wr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_wr.diminfo[0].strides = __pyx_pybuffernd_wr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wr.diminfo[0].shape = __pyx_pybuffernd_wr.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 658, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":659
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(659,0,__PYX_ERR(0, 659, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 659, __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, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __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, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); 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;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 659, __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, 659, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 659, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_v_wi, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_wi.diminfo[0].strides = __pyx_pybuffernd_wi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wi.diminfo[0].shape = __pyx_pybuffernd_wi.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":661
 *     wi = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.float32, order='F')
 *         vs_ptr = <float *>vs.data
 */
  __Pyx_TraceLine(661,0,__PYX_ERR(0, 661, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 661, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":662
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <float *>vs.data
 *         jobvs = "V"
 */
    __Pyx_TraceLine(662,0,__PYX_ERR(0, 662, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 662, __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, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 662, __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_4);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 662, __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, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 662, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 662, __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, 662, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 662, __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, 662, __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 662, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_v_vs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vs.diminfo[0].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vs.diminfo[0].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vs.diminfo[1].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vs.diminfo[1].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 662, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":663
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float32, order='F')
 *         vs_ptr = <float *>vs.data             # <<<<<<<<<<<<<<
 *         jobvs = "V"
 *     else:
 */
    __Pyx_TraceLine(663,0,__PYX_ERR(0, 663, __pyx_L1_error))
    __pyx_v_vs_ptr = ((float *)__pyx_v_vs->data);

    /* "kwant/linalg/lapack.pyx":664
 *         vs = np.empty((N,N), dtype = np.float32, order='F')
 *         vs_ptr = <float *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __Pyx_TraceLine(664,0,__PYX_ERR(0, 664, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":661
 *     wi = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.float32, order='F')
 *         vs_ptr = <float *>vs.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":666
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
  __Pyx_TraceLine(666,0,__PYX_ERR(0, 666, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":667
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(667,0,__PYX_ERR(0, 667, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":670
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.sgees_(jobvs, "N", NULL, &N, <float *>A.data, &N,
 *                     &sdim, <float *>wr.data, <float *>wi.data, vs_ptr, &N,
 */
  __Pyx_TraceLine(670,0,__PYX_ERR(0, 670, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":671
 *     # workspace query
 *     lwork = -1
 *     f_lapack.sgees_(jobvs, "N", NULL, &N, <float *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <float *>wr.data, <float *>wi.data, vs_ptr, &N,
 *                     &qwork, &lwork, NULL, &info)
 */
  __Pyx_TraceLine(671,0,__PYX_ERR(0, 671, __pyx_L1_error))
  sgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((float *)__pyx_v_wr->data), ((float *)__pyx_v_wi->data), __pyx_v_vs_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":675
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in sgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(675,0,__PYX_ERR(0, 675, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sgees);
      __PYX_ERR(0, 675, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":677
 *     assert info == 0, "Argument error in sgees"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(677,0,__PYX_ERR(0, 677, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":678
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(678,0,__PYX_ERR(0, 678, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __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_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 678, __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, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 678, __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_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 678, __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_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 678, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 678, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":681
 * 
 *     # Now the real calculation
 *     f_lapack.sgees_(jobvs, "N", NULL, &N, <float *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <float *>wr.data, <float *>wi.data, vs_ptr, &N,
 *                     <float *>work.data, &lwork, NULL, &info)
 */
  __Pyx_TraceLine(681,0,__PYX_ERR(0, 681, __pyx_L1_error))
  sgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((float *)__pyx_v_wr->data), ((float *)__pyx_v_wi->data), __pyx_v_vs_ptr, (&__pyx_v_N), ((float *)__pyx_v_work->data), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":685
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in sgees")
 * 
 */
  __Pyx_TraceLine(685,0,__PYX_ERR(0, 685, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":686
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in sgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgees"
 */
    __Pyx_TraceLine(686,0,__PYX_ERR(0, 686, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 686, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":685
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in sgees")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":688
 *         raise LinAlgError("QR iteration failed to converge in sgees")
 * 
 *     assert info == 0, "Argument error in sgees"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  __Pyx_TraceLine(688,0,__PYX_ERR(0, 688, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_sgees);
      __PYX_ERR(0, 688, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":690
 *     assert info == 0, "Argument error in sgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __Pyx_TraceLine(690,0,__PYX_ERR(0, 690, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 690, __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);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 690, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 690, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __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, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":691
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __Pyx_TraceLine(691,0,__PYX_ERR(0, 691, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 691, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_w = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":690
 *     assert info == 0, "Argument error in sgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
    goto __pyx_L5;
  }

  /* "kwant/linalg/lapack.pyx":693
 *         w = wr + 1j * wi
 *     else:
 *         w = wr             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))
 */
  __Pyx_TraceLine(693,0,__PYX_ERR(0, 693, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_wr));
    __pyx_v_w = ((PyObject *)__pyx_v_wr);
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":695
 *         w = wr
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(695,0,__PYX_ERR(0, 695, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_4, 0, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(__pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_w);
  __pyx_t_5 = NULL;
  __pyx_t_7 = 0;
  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_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_7, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_7, __pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":646
 * 
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* 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_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vs);
  __Pyx_XDECREF((PyObject *)__pyx_v_wr);
  __Pyx_XDECREF((PyObject *)__pyx_v_wi);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_w);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":698
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_41dgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_41dgees = {"dgees", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_41dgees, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_41dgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dgees (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_calc_q,&__pyx_n_s_calc_ev,0};
    PyObject* values[3] = {0,0,0};

    /* "kwant/linalg/lapack.pyx":699
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,
 *           calc_q=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvs
 */
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_True);
    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_A)) != 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_calc_q);
          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_calc_ev);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dgees") < 0)) __PYX_ERR(0, 698, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_calc_q = values[1];
    __pyx_v_calc_ev = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dgees", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 698, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 698, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_40dgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":698
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_40dgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvs;
  double *__pyx_v_vs_ptr;
  double __pyx_v_qwork;
  PyArrayObject *__pyx_v_vs = 0;
  PyArrayObject *__pyx_v_wr = 0;
  PyArrayObject *__pyx_v_wi = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_w = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vs;
  __Pyx_Buffer __pyx_pybuffer_vs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wi;
  __Pyx_Buffer __pyx_pybuffer_wi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wr;
  __Pyx_Buffer __pyx_pybuffer_wr;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__45)
  __Pyx_RefNannySetupContext("dgees", 0);
  __Pyx_TraceCall("dgees", __pyx_f[0], 698, 0, __PYX_ERR(0, 698, __pyx_L1_error));
  __pyx_pybuffer_vs.pybuffer.buf = NULL;
  __pyx_pybuffer_vs.refcount = 0;
  __pyx_pybuffernd_vs.data = NULL;
  __pyx_pybuffernd_vs.rcbuffer = &__pyx_pybuffer_vs;
  __pyx_pybuffer_wr.pybuffer.buf = NULL;
  __pyx_pybuffer_wr.refcount = 0;
  __pyx_pybuffernd_wr.data = NULL;
  __pyx_pybuffernd_wr.rcbuffer = &__pyx_pybuffer_wr;
  __pyx_pybuffer_wi.pybuffer.buf = NULL;
  __pyx_pybuffer_wi.refcount = 0;
  __pyx_pybuffernd_wi.data = NULL;
  __pyx_pybuffernd_wi.rcbuffer = &__pyx_pybuffer_wi;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 698, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":707
 *     cdef np.ndarray[np.float64_t] wr, wi, work
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(707,0,__PYX_ERR(0, 707, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 707, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":709
 *     assert_fortran_mat(A)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(709,0,__PYX_ERR(0, 709, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":710
 * 
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(710,0,__PYX_ERR(0, 710, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __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, 710, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 710, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 710, __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, 710, __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, 710, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 710, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 710, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_v_wr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_wr.diminfo[0].strides = __pyx_pybuffernd_wr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wr.diminfo[0].shape = __pyx_pybuffernd_wr.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 710, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":711
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(711,0,__PYX_ERR(0, 711, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 711, __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, 711, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 711, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 711, __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, 711, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 711, __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, 711, __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, 711, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 711, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_v_wi, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_wi.diminfo[0].strides = __pyx_pybuffernd_wi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wi.diminfo[0].shape = __pyx_pybuffernd_wi.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 711, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":713
 *     wi = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.float64, order='F')
 *         vs_ptr = <double *>vs.data
 */
  __Pyx_TraceLine(713,0,__PYX_ERR(0, 713, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 713, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":714
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <double *>vs.data
 *         jobvs = "V"
 */
    __Pyx_TraceLine(714,0,__PYX_ERR(0, 714, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 714, __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, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __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_4);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 714, __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, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 714, __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, 714, __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, 714, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 714, __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, 714, __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 714, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_v_vs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vs.diminfo[0].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vs.diminfo[0].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vs.diminfo[1].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vs.diminfo[1].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 714, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":715
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float64, order='F')
 *         vs_ptr = <double *>vs.data             # <<<<<<<<<<<<<<
 *         jobvs = "V"
 *     else:
 */
    __Pyx_TraceLine(715,0,__PYX_ERR(0, 715, __pyx_L1_error))
    __pyx_v_vs_ptr = ((double *)__pyx_v_vs->data);

    /* "kwant/linalg/lapack.pyx":716
 *         vs = np.empty((N,N), dtype = np.float64, order='F')
 *         vs_ptr = <double *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __Pyx_TraceLine(716,0,__PYX_ERR(0, 716, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":713
 *     wi = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.float64, order='F')
 *         vs_ptr = <double *>vs.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":718
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
  __Pyx_TraceLine(718,0,__PYX_ERR(0, 718, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":719
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(719,0,__PYX_ERR(0, 719, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":722
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dgees_(jobvs, "N", NULL, &N, <double *>A.data, &N,
 *                     &sdim, <double *>wr.data, <double *>wi.data, vs_ptr, &N,
 */
  __Pyx_TraceLine(722,0,__PYX_ERR(0, 722, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":723
 *     # workspace query
 *     lwork = -1
 *     f_lapack.dgees_(jobvs, "N", NULL, &N, <double *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <double *>wr.data, <double *>wi.data, vs_ptr, &N,
 *                     &qwork, &lwork, NULL, &info)
 */
  __Pyx_TraceLine(723,0,__PYX_ERR(0, 723, __pyx_L1_error))
  dgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((double *)__pyx_v_wr->data), ((double *)__pyx_v_wi->data), __pyx_v_vs_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":727
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in dgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(727,0,__PYX_ERR(0, 727, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dgees);
      __PYX_ERR(0, 727, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":729
 *     assert info == 0, "Argument error in dgees"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(729,0,__PYX_ERR(0, 729, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":730
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(730,0,__PYX_ERR(0, 730, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 730, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 730, __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_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 730, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 730, __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, 730, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __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, 730, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 730, __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_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 730, __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_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 730, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 730, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":733
 * 
 *     # Now the real calculation
 *     f_lapack.dgees_(jobvs, "N", NULL, &N, <double *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <double *>wr.data, <double *>wi.data, vs_ptr, &N,
 *                     <double *>work.data, &lwork, NULL, &info)
 */
  __Pyx_TraceLine(733,0,__PYX_ERR(0, 733, __pyx_L1_error))
  dgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((double *)__pyx_v_wr->data), ((double *)__pyx_v_wi->data), __pyx_v_vs_ptr, (&__pyx_v_N), ((double *)__pyx_v_work->data), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":737
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in dgees")
 * 
 */
  __Pyx_TraceLine(737,0,__PYX_ERR(0, 737, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":738
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in dgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgees"
 */
    __Pyx_TraceLine(738,0,__PYX_ERR(0, 738, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 738, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 738, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 738, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":737
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in dgees")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":740
 *         raise LinAlgError("QR iteration failed to converge in dgees")
 * 
 *     assert info == 0, "Argument error in dgees"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  __Pyx_TraceLine(740,0,__PYX_ERR(0, 740, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dgees);
      __PYX_ERR(0, 740, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":742
 *     assert info == 0, "Argument error in dgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __Pyx_TraceLine(742,0,__PYX_ERR(0, 742, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __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);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __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, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":743
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __Pyx_TraceLine(743,0,__PYX_ERR(0, 743, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_w = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":742
 *     assert info == 0, "Argument error in dgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
    goto __pyx_L5;
  }

  /* "kwant/linalg/lapack.pyx":745
 *         w = wr + 1j * wi
 *     else:
 *         w = wr             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))
 */
  __Pyx_TraceLine(745,0,__PYX_ERR(0, 745, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_wr));
    __pyx_v_w = ((PyObject *)__pyx_v_wr);
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":747
 *         w = wr
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(747,0,__PYX_ERR(0, 747, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_4, 0, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(__pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_w);
  __pyx_t_5 = NULL;
  __pyx_t_7 = 0;
  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_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 747, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_7, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_7, __pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":698
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* 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_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vs);
  __Pyx_XDECREF((PyObject *)__pyx_v_wr);
  __Pyx_XDECREF((PyObject *)__pyx_v_wi);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_w);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":750
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_43cgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_43cgees = {"cgees", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_43cgees, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_43cgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cgees (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_calc_q,&__pyx_n_s_calc_ev,0};
    PyObject* values[3] = {0,0,0};

    /* "kwant/linalg/lapack.pyx":751
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,
 *           calc_q=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvs
 */
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_True);
    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_A)) != 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_calc_q);
          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_calc_ev);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cgees") < 0)) __PYX_ERR(0, 750, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_calc_q = values[1];
    __pyx_v_calc_ev = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cgees", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 750, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.cgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 750, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_42cgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":750
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_42cgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvs;
  __pyx_t_float_complex *__pyx_v_vs_ptr;
  __pyx_t_float_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_vs = 0;
  PyArrayObject *__pyx_v_w = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vs;
  __Pyx_Buffer __pyx_pybuffer_vs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_w;
  __Pyx_Buffer __pyx_pybuffer_w;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__47)
  __Pyx_RefNannySetupContext("cgees", 0);
  __Pyx_TraceCall("cgees", __pyx_f[0], 750, 0, __PYX_ERR(0, 750, __pyx_L1_error));
  __pyx_pybuffer_vs.pybuffer.buf = NULL;
  __pyx_pybuffer_vs.refcount = 0;
  __pyx_pybuffernd_vs.data = NULL;
  __pyx_pybuffernd_vs.rcbuffer = &__pyx_pybuffer_vs;
  __pyx_pybuffer_w.pybuffer.buf = NULL;
  __pyx_pybuffer_w.refcount = 0;
  __pyx_pybuffernd_w.data = NULL;
  __pyx_pybuffernd_w.rcbuffer = &__pyx_pybuffer_w;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 750, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":760
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(760,0,__PYX_ERR(0, 760, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 760, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":762
 *     assert_fortran_mat(A)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     w = np.empty(N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(762,0,__PYX_ERR(0, 762, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":763
 * 
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(763,0,__PYX_ERR(0, 763, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __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, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 763, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 763, __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, 763, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 763, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 763, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 763, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":764
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(764,0,__PYX_ERR(0, 764, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 764, __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, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __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, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __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, 764, __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, 764, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 764, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 764, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":766
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')
 *         vs_ptr = <float complex *>vs.data
 */
  __Pyx_TraceLine(766,0,__PYX_ERR(0, 766, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 766, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":767
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <float complex *>vs.data
 *         jobvs = "V"
 */
    __Pyx_TraceLine(767,0,__PYX_ERR(0, 767, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __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, 767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __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_4);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 767, __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, 767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 767, __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, 767, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 767, __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, 767, __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 767, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_v_vs, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vs.diminfo[0].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vs.diminfo[0].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vs.diminfo[1].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vs.diminfo[1].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 767, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":768
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')
 *         vs_ptr = <float complex *>vs.data             # <<<<<<<<<<<<<<
 *         jobvs = "V"
 *     else:
 */
    __Pyx_TraceLine(768,0,__PYX_ERR(0, 768, __pyx_L1_error))
    __pyx_v_vs_ptr = ((__pyx_t_float_complex *)__pyx_v_vs->data);

    /* "kwant/linalg/lapack.pyx":769
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')
 *         vs_ptr = <float complex *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __Pyx_TraceLine(769,0,__PYX_ERR(0, 769, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":766
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')
 *         vs_ptr = <float complex *>vs.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":771
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
  __Pyx_TraceLine(771,0,__PYX_ERR(0, 771, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":772
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(772,0,__PYX_ERR(0, 772, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":775
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.cgees_(jobvs, "N", NULL, &N, <float complex *>A.data, &N,
 *                     &sdim, <float complex *>w.data, vs_ptr, &N,
 */
  __Pyx_TraceLine(775,0,__PYX_ERR(0, 775, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":776
 *     # workspace query
 *     lwork = -1
 *     f_lapack.cgees_(jobvs, "N", NULL, &N, <float complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <float complex *>w.data, vs_ptr, &N,
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)
 */
  __Pyx_TraceLine(776,0,__PYX_ERR(0, 776, __pyx_L1_error))
  cgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_float_complex *)__pyx_v_w->data), __pyx_v_vs_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":780
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in cgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(780,0,__PYX_ERR(0, 780, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cgees);
      __PYX_ERR(0, 780, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":782
 *     assert info == 0, "Argument error in cgees"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(782,0,__PYX_ERR(0, 782, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":783
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(783,0,__PYX_ERR(0, 783, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __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_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 783, __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, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 783, __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_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 783, __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_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 783, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 783, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":786
 * 
 *     # Now the real calculation
 *     f_lapack.cgees_(jobvs, "N", NULL, &N, <float complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <float complex *>w.data, vs_ptr, &N,
 *                     <float complex *>work.data, &lwork,
 */
  __Pyx_TraceLine(786,0,__PYX_ERR(0, 786, __pyx_L1_error))
  cgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_float_complex *)__pyx_v_w->data), __pyx_v_vs_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":791
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in cgees")
 * 
 */
  __Pyx_TraceLine(791,0,__PYX_ERR(0, 791, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":792
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in cgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgees"
 */
    __Pyx_TraceLine(792,0,__PYX_ERR(0, 792, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 792, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 792, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":791
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in cgees")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":794
 *         raise LinAlgError("QR iteration failed to converge in cgees")
 * 
 *     assert info == 0, "Argument error in cgees"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))
 */
  __Pyx_TraceLine(794,0,__PYX_ERR(0, 794, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_cgees);
      __PYX_ERR(0, 794, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":796
 *     assert info == 0, "Argument error in cgees"
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(796,0,__PYX_ERR(0, 796, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_4, 0, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_w));
  __pyx_t_5 = NULL;
  __pyx_t_7 = 0;
  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_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 796, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_7, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_7, __pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":750
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* 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_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vs);
  __Pyx_XDECREF((PyObject *)__pyx_v_w);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":799
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_45zgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_45zgees = {"zgees", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_45zgees, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_45zgees(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zgees (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_calc_q,&__pyx_n_s_calc_ev,0};
    PyObject* values[3] = {0,0,0};

    /* "kwant/linalg/lapack.pyx":800
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,
 *           calc_q=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvs
 */
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)Py_True);
    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_A)) != 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_calc_q);
          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_calc_ev);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zgees") < 0)) __PYX_ERR(0, 799, __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_A = ((PyArrayObject *)values[0]);
    __pyx_v_calc_q = values[1];
    __pyx_v_calc_ev = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zgees", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 799, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.zgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 799, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_44zgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":799
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_44zgees(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvs;
  __pyx_t_double_complex *__pyx_v_vs_ptr;
  __pyx_t_double_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_vs = 0;
  PyArrayObject *__pyx_v_w = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vs;
  __Pyx_Buffer __pyx_pybuffer_vs;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_w;
  __Pyx_Buffer __pyx_pybuffer_w;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__49)
  __Pyx_RefNannySetupContext("zgees", 0);
  __Pyx_TraceCall("zgees", __pyx_f[0], 799, 0, __PYX_ERR(0, 799, __pyx_L1_error));
  __pyx_pybuffer_vs.pybuffer.buf = NULL;
  __pyx_pybuffer_vs.refcount = 0;
  __pyx_pybuffernd_vs.data = NULL;
  __pyx_pybuffernd_vs.rcbuffer = &__pyx_pybuffer_vs;
  __pyx_pybuffer_w.pybuffer.buf = NULL;
  __pyx_pybuffer_w.refcount = 0;
  __pyx_pybuffernd_w.data = NULL;
  __pyx_pybuffernd_w.rcbuffer = &__pyx_pybuffer_w;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 799, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":809
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(809,0,__PYX_ERR(0, 809, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 809, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_A)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __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[2] = {__pyx_t_3, ((PyObject *)__pyx_v_A)};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 809, __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 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_A));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_A));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":811
 *     assert_fortran_mat(A)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     w = np.empty(N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(811,0,__PYX_ERR(0, 811, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":812
 * 
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(812,0,__PYX_ERR(0, 812, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __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, 812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 812, __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(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __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, 812, __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_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 812, __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;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 812, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 812, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":813
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(813,0,__PYX_ERR(0, 813, __pyx_L1_error))
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 813, __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, 813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 813, __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, 813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 813, __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, 813, __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, 813, __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;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 813, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 813, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":815
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')
 *         vs_ptr = <double complex *>vs.data
 */
  __Pyx_TraceLine(815,0,__PYX_ERR(0, 815, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 815, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":816
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <double complex *>vs.data
 *         jobvs = "V"
 */
    __Pyx_TraceLine(816,0,__PYX_ERR(0, 816, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 816, __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, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 816, __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_4);
    PyTuple_SET_ITEM(__pyx_t_1, 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, 816, __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, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 816, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 816, __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, 816, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 816, __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, 816, __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;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 816, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vs.rcbuffer->pybuffer, (PyObject*)__pyx_v_vs, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vs.diminfo[0].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vs.diminfo[0].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vs.diminfo[1].strides = __pyx_pybuffernd_vs.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vs.diminfo[1].shape = __pyx_pybuffernd_vs.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 816, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":817
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')
 *         vs_ptr = <double complex *>vs.data             # <<<<<<<<<<<<<<
 *         jobvs = "V"
 *     else:
 */
    __Pyx_TraceLine(817,0,__PYX_ERR(0, 817, __pyx_L1_error))
    __pyx_v_vs_ptr = ((__pyx_t_double_complex *)__pyx_v_vs->data);

    /* "kwant/linalg/lapack.pyx":818
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')
 *         vs_ptr = <double complex *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __Pyx_TraceLine(818,0,__PYX_ERR(0, 818, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":815
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')
 *         vs_ptr = <double complex *>vs.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":820
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
  __Pyx_TraceLine(820,0,__PYX_ERR(0, 820, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":821
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(821,0,__PYX_ERR(0, 821, __pyx_L1_error))
    __pyx_v_jobvs = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":824
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.zgees_(jobvs, "N", NULL, &N, <double complex *>A.data, &N,
 *                     &sdim, <double complex *>w.data, vs_ptr, &N,
 */
  __Pyx_TraceLine(824,0,__PYX_ERR(0, 824, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":825
 *     # workspace query
 *     lwork = -1
 *     f_lapack.zgees_(jobvs, "N", NULL, &N, <double complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <double complex *>w.data, vs_ptr, &N,
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)
 */
  __Pyx_TraceLine(825,0,__PYX_ERR(0, 825, __pyx_L1_error))
  zgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_double_complex *)__pyx_v_w->data), __pyx_v_vs_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":829
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(829,0,__PYX_ERR(0, 829, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 829, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":831
 *     assert info == 0, "Argument error in zgees"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(831,0,__PYX_ERR(0, 831, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":832
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(832,0,__PYX_ERR(0, 832, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 832, __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_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 832, __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, 832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 832, __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_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 832, __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_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 832, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 832, __pyx_L1_error)
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":835
 * 
 *     # Now the real calculation
 *     f_lapack.zgees_(jobvs, "N", NULL, &N, <double complex *>A.data, &N,             # <<<<<<<<<<<<<<
 *                     &sdim, <double complex *>w.data, vs_ptr, &N,
 *                     <double complex *>work.data, &lwork,
 */
  __Pyx_TraceLine(835,0,__PYX_ERR(0, 835, __pyx_L1_error))
  zgees_(__pyx_v_jobvs, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_double_complex *)__pyx_v_w->data), __pyx_v_vs_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":840
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in zgees")
 * 
 */
  __Pyx_TraceLine(840,0,__PYX_ERR(0, 840, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":841
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in zgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __Pyx_TraceLine(841,0,__PYX_ERR(0, 841, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 841, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 841, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 841, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":840
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in zgees")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":843
 *         raise LinAlgError("QR iteration failed to converge in zgees")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))
 */
  __Pyx_TraceLine(843,0,__PYX_ERR(0, 843, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 843, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":845
 *     assert info == 0, "Argument error in zgees"
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * # Wrapper for xTRSEN
 */
  __Pyx_TraceLine(845,0,__PYX_ERR(0, 845, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 845, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 845, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_4, 0, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 845, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_w));
  __pyx_t_5 = NULL;
  __pyx_t_7 = 0;
  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_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_7, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_7, __pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":799
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */

  /* 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_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zgees", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vs.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vs);
  __Pyx_XDECREF((PyObject *)__pyx_v_w);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":848
 * 
 * # Wrapper for xTRSEN
 * def strsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_47strsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_47strsen = {"strsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_47strsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_47strsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("strsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_calc_ev,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":850
 * def strsen(np.ndarray[l_logical] select,
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":851
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info
 *     cdef char *compq
 */
    values[3] = ((PyObject *)Py_True);
    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_select)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("strsen", 0, 2, 4, 1); __PYX_ERR(0, 848, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_calc_ev);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "strsen") < 0)) __PYX_ERR(0, 848, __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_select = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_calc_ev = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("strsen", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 848, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.strsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 848, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 849, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 850, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_46strsen(__pyx_self, __pyx_v_select, __pyx_v_T, __pyx_v_Q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":848
 * 
 * # Wrapper for xTRSEN
 * def strsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_46strsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_compq;
  float __pyx_v_qwork;
  float *__pyx_v_q_ptr;
  PyArrayObject *__pyx_v_wr = 0;
  PyArrayObject *__pyx_v_wi = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  PyObject *__pyx_v_w = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wi;
  __Pyx_Buffer __pyx_pybuffer_wi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wr;
  __Pyx_Buffer __pyx_pybuffer_wr;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__51)
  __Pyx_RefNannySetupContext("strsen", 0);
  __Pyx_TraceCall("strsen", __pyx_f[0], 848, 0, __PYX_ERR(0, 848, __pyx_L1_error));
  __pyx_pybuffer_wr.pybuffer.buf = NULL;
  __pyx_pybuffer_wr.refcount = 0;
  __pyx_pybuffernd_wr.data = NULL;
  __pyx_pybuffernd_wr.rcbuffer = &__pyx_pybuffer_wr;
  __pyx_pybuffer_wi.pybuffer.buf = NULL;
  __pyx_pybuffer_wi.refcount = 0;
  __pyx_pybuffernd_wi.data = NULL;
  __pyx_pybuffernd_wi.rcbuffer = &__pyx_pybuffer_wi;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 848, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 848, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 848, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":859
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(859,0,__PYX_ERR(0, 859, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":861
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(861,0,__PYX_ERR(0, 861, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":862
 * 
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(862,0,__PYX_ERR(0, 862, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __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, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __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, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 862, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_v_wr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_wr.diminfo[0].strides = __pyx_pybuffernd_wr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wr.diminfo[0].shape = __pyx_pybuffernd_wr.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 862, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":863
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(863,0,__PYX_ERR(0, 863, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 863, __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, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 863, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 863, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 863, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 863, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_v_wi, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_wi.diminfo[0].strides = __pyx_pybuffernd_wi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wi.diminfo[0].shape = __pyx_pybuffernd_wi.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 863, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":865
 *     wi = np.empty(N, dtype = np.float32)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <float *>Q.data
 */
  __Pyx_TraceLine(865,0,__PYX_ERR(0, 865, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":866
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <float *>Q.data
 *     else:
 */
    __Pyx_TraceLine(866,0,__PYX_ERR(0, 866, __pyx_L1_error))
    __pyx_v_compq = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":867
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <float *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __Pyx_TraceLine(867,0,__PYX_ERR(0, 867, __pyx_L1_error))
    __pyx_v_q_ptr = ((float *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":865
 *     wi = np.empty(N, dtype = np.float32)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <float *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":869
 *         q_ptr = <float *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(869,0,__PYX_ERR(0, 869, __pyx_L1_error))
  /*else*/ {
    __pyx_v_compq = ((char *)"N");

    /* "kwant/linalg/lapack.pyx":870
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(870,0,__PYX_ERR(0, 870, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":873
 * 
 *     # workspace query
 *     lwork = liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.strsen_("N", compq, <l_logical *>select.data,
 *                      &N, <float *>T.data, &N, q_ptr, &N,
 */
  __Pyx_TraceLine(873,0,__PYX_ERR(0, 873, __pyx_L1_error))
  __pyx_v_lwork = -1;
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":874
 *     # workspace query
 *     lwork = liwork = -1
 *     f_lapack.strsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float *>T.data, &N, q_ptr, &N,
 *                      <float *>wr.data, <float *>wi.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(874,0,__PYX_ERR(0, 874, __pyx_L1_error))
  strsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((float *)__pyx_v_wr->data), ((float *)__pyx_v_wi->data), (&__pyx_v_M), NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":879
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in strsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(879,0,__PYX_ERR(0, 879, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_strsen);
      __PYX_ERR(0, 879, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":881
 *     assert info == 0, "Argument error in strsen"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(881,0,__PYX_ERR(0, 881, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":882
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(882,0,__PYX_ERR(0, 882, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __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, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 882, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 882, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":883
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(883,0,__PYX_ERR(0, 883, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":884
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(884,0,__PYX_ERR(0, 884, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __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, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 884, __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, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 884, __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, 884, __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, 884, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 884, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 884, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":887
 * 
 *     # Now the real calculation
 *     f_lapack.strsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float *>T.data, &N, q_ptr, &N,
 *                      <float *>wr.data, <float *>wi.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(887,0,__PYX_ERR(0, 887, __pyx_L1_error))
  strsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((float *)__pyx_v_wr->data), ((float *)__pyx_v_wi->data), (&__pyx_v_M), NULL, NULL, ((float *)__pyx_v_work->data), (&__pyx_v_lwork), ((int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":893
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(893,0,__PYX_ERR(0, 893, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":894
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strsen"
 */
    __Pyx_TraceLine(894,0,__PYX_ERR(0, 894, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 894, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__52, NULL); 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_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 894, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":893
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":896
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in strsen"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  __Pyx_TraceLine(896,0,__PYX_ERR(0, 896, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_strsen);
      __PYX_ERR(0, 896, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":898
 *     assert info == 0, "Argument error in strsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __Pyx_TraceLine(898,0,__PYX_ERR(0, 898, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 898, __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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 898, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 898, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __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, 898, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 898, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 898, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":899
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __Pyx_TraceLine(899,0,__PYX_ERR(0, 899, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_w = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":898
 *     assert info == 0, "Argument error in strsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
    goto __pyx_L5;
  }

  /* "kwant/linalg/lapack.pyx":901
 *         w = wr + 1j * wi
 *     else:
 *         w = wr             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))
 */
  __Pyx_TraceLine(901,0,__PYX_ERR(0, 901, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_wr));
    __pyx_v_w = ((PyObject *)__pyx_v_wr);
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":903
 *         w = wr
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(903,0,__PYX_ERR(0, 903, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(__pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_w);
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":848
 * 
 * # Wrapper for xTRSEN
 * def strsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.strsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_wr);
  __Pyx_XDECREF((PyObject *)__pyx_v_wi);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XDECREF(__pyx_v_w);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":906
 * 
 * 
 * def dtrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_49dtrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_49dtrsen = {"dtrsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_49dtrsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_49dtrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dtrsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_calc_ev,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":908
 * def dtrsen(np.ndarray[l_logical] select,
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":909
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info
 *     cdef char *compq
 */
    values[3] = ((PyObject *)Py_True);
    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_select)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtrsen", 0, 2, 4, 1); __PYX_ERR(0, 906, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_calc_ev);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dtrsen") < 0)) __PYX_ERR(0, 906, __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_select = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_calc_ev = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dtrsen", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 906, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dtrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 906, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 907, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 908, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_48dtrsen(__pyx_self, __pyx_v_select, __pyx_v_T, __pyx_v_Q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":906
 * 
 * 
 * def dtrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_48dtrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_compq;
  double __pyx_v_qwork;
  double *__pyx_v_q_ptr;
  PyArrayObject *__pyx_v_wr = 0;
  PyArrayObject *__pyx_v_wi = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  PyObject *__pyx_v_w = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wi;
  __Pyx_Buffer __pyx_pybuffer_wi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_wr;
  __Pyx_Buffer __pyx_pybuffer_wr;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__53)
  __Pyx_RefNannySetupContext("dtrsen", 0);
  __Pyx_TraceCall("dtrsen", __pyx_f[0], 906, 0, __PYX_ERR(0, 906, __pyx_L1_error));
  __pyx_pybuffer_wr.pybuffer.buf = NULL;
  __pyx_pybuffer_wr.refcount = 0;
  __pyx_pybuffernd_wr.data = NULL;
  __pyx_pybuffernd_wr.rcbuffer = &__pyx_pybuffer_wr;
  __pyx_pybuffer_wi.pybuffer.buf = NULL;
  __pyx_pybuffer_wi.refcount = 0;
  __pyx_pybuffernd_wi.data = NULL;
  __pyx_pybuffernd_wi.rcbuffer = &__pyx_pybuffer_wi;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 906, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 906, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 906, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":917
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(917,0,__PYX_ERR(0, 917, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 917, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 917, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":919
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(919,0,__PYX_ERR(0, 919, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":920
 * 
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(920,0,__PYX_ERR(0, 920, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 920, __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, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 920, __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, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 920, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wr.rcbuffer->pybuffer, (PyObject*)__pyx_v_wr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_wr.diminfo[0].strides = __pyx_pybuffernd_wr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wr.diminfo[0].shape = __pyx_pybuffernd_wr.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 920, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":921
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(921,0,__PYX_ERR(0, 921, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __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, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 921, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 921, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 921, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_wi.rcbuffer->pybuffer, (PyObject*)__pyx_v_wi, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_wi.diminfo[0].strides = __pyx_pybuffernd_wi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_wi.diminfo[0].shape = __pyx_pybuffernd_wi.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 921, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":923
 *     wi = np.empty(N, dtype = np.float64)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <double *>Q.data
 */
  __Pyx_TraceLine(923,0,__PYX_ERR(0, 923, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":924
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <double *>Q.data
 *     else:
 */
    __Pyx_TraceLine(924,0,__PYX_ERR(0, 924, __pyx_L1_error))
    __pyx_v_compq = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":925
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <double *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __Pyx_TraceLine(925,0,__PYX_ERR(0, 925, __pyx_L1_error))
    __pyx_v_q_ptr = ((double *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":923
 *     wi = np.empty(N, dtype = np.float64)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <double *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":927
 *         q_ptr = <double *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(927,0,__PYX_ERR(0, 927, __pyx_L1_error))
  /*else*/ {
    __pyx_v_compq = ((char *)"N");

    /* "kwant/linalg/lapack.pyx":928
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(928,0,__PYX_ERR(0, 928, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":931
 * 
 *     # workspace query
 *     lwork = liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dtrsen_("N", compq, <l_logical *>select.data,
 *                      &N, <double *>T.data, &N, q_ptr, &N,
 */
  __Pyx_TraceLine(931,0,__PYX_ERR(0, 931, __pyx_L1_error))
  __pyx_v_lwork = -1;
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":932
 *     # workspace query
 *     lwork = liwork = -1
 *     f_lapack.dtrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double *>T.data, &N, q_ptr, &N,
 *                      <double *>wr.data, <double *>wi.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(932,0,__PYX_ERR(0, 932, __pyx_L1_error))
  dtrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((double *)__pyx_v_wr->data), ((double *)__pyx_v_wi->data), (&__pyx_v_M), NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":937
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in dtrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(937,0,__PYX_ERR(0, 937, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtrsen);
      __PYX_ERR(0, 937, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":939
 *     assert info == 0, "Argument error in dtrsen"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(939,0,__PYX_ERR(0, 939, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":940
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 */
  __Pyx_TraceLine(940,0,__PYX_ERR(0, 940, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 940, __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, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 940, __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, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 940, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 940, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 940, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 940, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":941
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 * 
 */
  __Pyx_TraceLine(941,0,__PYX_ERR(0, 941, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":942
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(942,0,__PYX_ERR(0, 942, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __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, 942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 942, __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, 942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 942, __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, 942, __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, 942, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 942, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 942, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":945
 * 
 *     # Now the real calculation
 *     f_lapack.dtrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double *>T.data, &N, q_ptr, &N,
 *                      <double *>wr.data, <double *>wi.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(945,0,__PYX_ERR(0, 945, __pyx_L1_error))
  dtrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((double *)__pyx_v_wr->data), ((double *)__pyx_v_wi->data), (&__pyx_v_M), NULL, NULL, ((double *)__pyx_v_work->data), (&__pyx_v_lwork), ((int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":951
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(951,0,__PYX_ERR(0, 951, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":952
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrsen"
 */
    __Pyx_TraceLine(952,0,__PYX_ERR(0, 952, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 952, __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, 952, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":951
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":954
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in dtrsen"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  __Pyx_TraceLine(954,0,__PYX_ERR(0, 954, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtrsen);
      __PYX_ERR(0, 954, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":956
 *     assert info == 0, "Argument error in dtrsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __Pyx_TraceLine(956,0,__PYX_ERR(0, 956, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 956, __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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __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, 956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 956, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":957
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __Pyx_TraceLine(957,0,__PYX_ERR(0, 957, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_w = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":956
 *     assert info == 0, "Argument error in dtrsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
    goto __pyx_L5;
  }

  /* "kwant/linalg/lapack.pyx":959
 *         w = wr + 1j * wi
 *     else:
 *         w = wr             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))
 */
  __Pyx_TraceLine(959,0,__PYX_ERR(0, 959, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_wr));
    __pyx_v_w = ((PyObject *)__pyx_v_wr);
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":961
 *         w = wr
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(961,0,__PYX_ERR(0, 961, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 0, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(__pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_w);
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":906
 * 
 * 
 * def dtrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dtrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_wr.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_wr);
  __Pyx_XDECREF((PyObject *)__pyx_v_wi);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XDECREF(__pyx_v_w);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":964
 * 
 * 
 * def ctrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_51ctrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_51ctrsen = {"ctrsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_51ctrsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_51ctrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ctrsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_calc_ev,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":966
 * def ctrsen(np.ndarray[l_logical] select,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, info
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":967
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, info
 *     cdef char *compq
 */
    values[3] = ((PyObject *)Py_True);
    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_select)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctrsen", 0, 2, 4, 1); __PYX_ERR(0, 964, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_calc_ev);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ctrsen") < 0)) __PYX_ERR(0, 964, __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_select = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_calc_ev = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ctrsen", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 964, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ctrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 964, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 965, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 966, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_50ctrsen(__pyx_self, __pyx_v_select, __pyx_v_T, __pyx_v_Q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":964
 * 
 * 
 * def ctrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_50ctrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_compq;
  __pyx_t_float_complex __pyx_v_qwork;
  __pyx_t_float_complex *__pyx_v_q_ptr;
  PyArrayObject *__pyx_v_w = 0;
  PyArrayObject *__pyx_v_work = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_w;
  __Pyx_Buffer __pyx_pybuffer_w;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__55)
  __Pyx_RefNannySetupContext("ctrsen", 0);
  __Pyx_TraceCall("ctrsen", __pyx_f[0], 964, 0, __PYX_ERR(0, 964, __pyx_L1_error));
  __pyx_pybuffer_w.pybuffer.buf = NULL;
  __pyx_pybuffer_w.refcount = 0;
  __pyx_pybuffernd_w.data = NULL;
  __pyx_pybuffernd_w.rcbuffer = &__pyx_pybuffer_w;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 964, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 964, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 964, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":974
 *     cdef np.ndarray[np.complex64_t] w, work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(974,0,__PYX_ERR(0, 974, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 974, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 974, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 974, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 974, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 974, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":976
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     w = np.empty(N, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(976,0,__PYX_ERR(0, 976, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":977
 * 
 *     N = T.shape[0]
 *     w = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(977,0,__PYX_ERR(0, 977, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 977, __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, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 977, __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, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 977, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 977, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 977, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 977, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":979
 *     w = np.empty(N, dtype = np.complex64)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <float complex *>Q.data
 */
  __Pyx_TraceLine(979,0,__PYX_ERR(0, 979, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":980
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <float complex *>Q.data
 *     else:
 */
    __Pyx_TraceLine(980,0,__PYX_ERR(0, 980, __pyx_L1_error))
    __pyx_v_compq = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":981
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <float complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __Pyx_TraceLine(981,0,__PYX_ERR(0, 981, __pyx_L1_error))
    __pyx_v_q_ptr = ((__pyx_t_float_complex *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":979
 *     w = np.empty(N, dtype = np.complex64)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <float complex *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":983
 *         q_ptr = <float complex *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(983,0,__PYX_ERR(0, 983, __pyx_L1_error))
  /*else*/ {
    __pyx_v_compq = ((char *)"N");

    /* "kwant/linalg/lapack.pyx":984
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(984,0,__PYX_ERR(0, 984, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":987
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ctrsen_("N", compq, <l_logical *>select.data,
 *                      &N, <float complex *>T.data, &N, q_ptr, &N,
 */
  __Pyx_TraceLine(987,0,__PYX_ERR(0, 987, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":988
 *     # workspace query
 *     lwork = -1
 *     f_lapack.ctrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>T.data, &N, q_ptr, &N,
 *                      <float complex *>w.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(988,0,__PYX_ERR(0, 988, __pyx_L1_error))
  ctrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_w->data), (&__pyx_v_M), NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":993
 *                      &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in ctrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(993,0,__PYX_ERR(0, 993, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctrsen);
      __PYX_ERR(0, 993, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":995
 *     assert info == 0, "Argument error in ctrsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(995,0,__PYX_ERR(0, 995, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":996
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(996,0,__PYX_ERR(0, 996, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 996, __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, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 996, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 996, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 996, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 996, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":999
 * 
 *     # Now the real calculation
 *     f_lapack.ctrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>T.data, &N, q_ptr, &N,
 *                      <float complex *>w.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(999,0,__PYX_ERR(0, 999, __pyx_L1_error))
  ctrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_w->data), (&__pyx_v_M), NULL, NULL, ((__pyx_t_float_complex *)__pyx_v_work->data), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1004
 *                      <float complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(1004,0,__PYX_ERR(0, 1004, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":1005
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrsen"
 */
    __Pyx_TraceLine(1005,0,__PYX_ERR(0, 1005, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_ERR(0, 1005, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1004
 *                      <float complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1007
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in ctrsen"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))
 */
  __Pyx_TraceLine(1007,0,__PYX_ERR(0, 1007, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctrsen);
      __PYX_ERR(0, 1007, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1009
 *     assert info == 0, "Argument error in ctrsen"
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1009,0,__PYX_ERR(0, 1009, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 0, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_w));
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_5};
    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_5};
    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_t_5);
    __pyx_t_1 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":964
 * 
 * 
 * def ctrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ctrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_w);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1012
 * 
 * 
 * def ztrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_53ztrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_53ztrsen = {"ztrsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_53ztrsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_53ztrsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ztrsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_calc_ev,0};
    PyObject* values[4] = {0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1014
 * def ztrsen(np.ndarray[l_logical] select,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, MM, M, lwork, info
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1015
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, MM, M, lwork, info
 *     cdef char *compq
 */
    values[3] = ((PyObject *)Py_True);
    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_select)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztrsen", 0, 2, 4, 1); __PYX_ERR(0, 1012, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_calc_ev);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ztrsen") < 0)) __PYX_ERR(0, 1012, __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_select = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_calc_ev = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ztrsen", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1012, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ztrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1012, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1013, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1014, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_52ztrsen(__pyx_self, __pyx_v_select, __pyx_v_T, __pyx_v_Q, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1012
 * 
 * 
 * def ztrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_52ztrsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_compq;
  __pyx_t_double_complex __pyx_v_qwork;
  __pyx_t_double_complex *__pyx_v_q_ptr;
  PyArrayObject *__pyx_v_w = 0;
  PyArrayObject *__pyx_v_work = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_w;
  __Pyx_Buffer __pyx_pybuffer_w;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__57)
  __Pyx_RefNannySetupContext("ztrsen", 0);
  __Pyx_TraceCall("ztrsen", __pyx_f[0], 1012, 0, __PYX_ERR(0, 1012, __pyx_L1_error));
  __pyx_pybuffer_w.pybuffer.buf = NULL;
  __pyx_pybuffer_w.refcount = 0;
  __pyx_pybuffernd_w.data = NULL;
  __pyx_pybuffernd_w.rcbuffer = &__pyx_pybuffer_w;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1012, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1012, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1012, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1022
 *     cdef np.ndarray[np.complex128_t] w, work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(1022,0,__PYX_ERR(0, 1022, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1022, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1022, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1022, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1022, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1022, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1024
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     w = np.empty(N, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(1024,0,__PYX_ERR(0, 1024, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1025
 * 
 *     N = T.shape[0]
 *     w = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(1025,0,__PYX_ERR(0, 1025, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1025, __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, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1025, __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, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1025, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1025, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1027
 *     w = np.empty(N, dtype = np.complex128)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <double complex *>Q.data
 */
  __Pyx_TraceLine(1027,0,__PYX_ERR(0, 1027, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1028
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <double complex *>Q.data
 *     else:
 */
    __Pyx_TraceLine(1028,0,__PYX_ERR(0, 1028, __pyx_L1_error))
    __pyx_v_compq = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1029
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <double complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __Pyx_TraceLine(1029,0,__PYX_ERR(0, 1029, __pyx_L1_error))
    __pyx_v_q_ptr = ((__pyx_t_double_complex *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":1027
 *     w = np.empty(N, dtype = np.complex128)
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         compq = "V"
 *         q_ptr = <double complex *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1031
 *         q_ptr = <double complex *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1031,0,__PYX_ERR(0, 1031, __pyx_L1_error))
  /*else*/ {
    __pyx_v_compq = ((char *)"N");

    /* "kwant/linalg/lapack.pyx":1032
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1032,0,__PYX_ERR(0, 1032, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1035
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ztrsen_("N", compq, <l_logical *>select.data,
 *                      &N, <double complex *>T.data, &N, q_ptr, &N,
 */
  __Pyx_TraceLine(1035,0,__PYX_ERR(0, 1035, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1036
 *     # workspace query
 *     lwork = -1
 *     f_lapack.ztrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>T.data, &N, q_ptr, &N,
 *                      <double complex *>w.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(1036,0,__PYX_ERR(0, 1036, __pyx_L1_error))
  ztrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_w->data), (&__pyx_v_M), NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1041
 *                      &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in ztrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(1041,0,__PYX_ERR(0, 1041, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztrsen);
      __PYX_ERR(0, 1041, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1043
 *     assert info == 0, "Argument error in ztrsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(1043,0,__PYX_ERR(0, 1043, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1044
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1044,0,__PYX_ERR(0, 1044, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1044, __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, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1044, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1044, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1044, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1044, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1047
 * 
 *     # Now the real calculation
 *     f_lapack.ztrsen_("N", compq, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>T.data, &N, q_ptr, &N,
 *                      <double complex *>w.data, &M, NULL, NULL,
 */
  __Pyx_TraceLine(1047,0,__PYX_ERR(0, 1047, __pyx_L1_error))
  ztrsen_(((char *)"N"), __pyx_v_compq, ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_q_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_w->data), (&__pyx_v_M), NULL, NULL, ((__pyx_t_double_complex *)__pyx_v_work->data), (&__pyx_v_lwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1052
 *                      <double complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(1052,0,__PYX_ERR(0, 1052, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":1053
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrsen"
 */
    __Pyx_TraceLine(1053,0,__PYX_ERR(0, 1053, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __PYX_ERR(0, 1053, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1052
 *                      <double complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1055
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in ztrsen"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))
 */
  __Pyx_TraceLine(1055,0,__PYX_ERR(0, 1055, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztrsen);
      __PYX_ERR(0, 1055, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1057
 *     assert info == 0, "Argument error in ztrsen"
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1057,0,__PYX_ERR(0, 1057, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 0, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_w));
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_5};
    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1057, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_5};
    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1057, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_t_5);
    __pyx_t_1 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1012
 * 
 * 
 * def ztrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ztrsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_w);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1061
 * 
 * # Helper function for xTREVC and xTGEVC
 * def txevc_postprocess(dtype, T, vreal, np.ndarray[l_logical] select):             # <<<<<<<<<<<<<<
 *     cdef int N, M, i, m, indx
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_55txevc_postprocess(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_55txevc_postprocess = {"txevc_postprocess", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_55txevc_postprocess, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_55txevc_postprocess(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dtype = 0;
  PyObject *__pyx_v_T = 0;
  PyObject *__pyx_v_vreal = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("txevc_postprocess (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dtype,&__pyx_n_s_T,&__pyx_n_s_vreal,&__pyx_n_s_select,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 1); __PYX_ERR(0, 1061, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_vreal)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 2); __PYX_ERR(0, 1061, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_select)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 3); __PYX_ERR(0, 1061, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "txevc_postprocess") < 0)) __PYX_ERR(0, 1061, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_dtype = values[0];
    __pyx_v_T = values[1];
    __pyx_v_vreal = values[2];
    __pyx_v_select = ((PyArrayObject *)values[3]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1061, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.txevc_postprocess", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1061, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_54txevc_postprocess(__pyx_self, __pyx_v_dtype, __pyx_v_T, __pyx_v_vreal, __pyx_v_select);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_54txevc_postprocess(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dtype, PyObject *__pyx_v_T, PyObject *__pyx_v_vreal, PyArrayObject *__pyx_v_select) {
  int __pyx_v_N;
  int __pyx_v_M;
  int __pyx_v_m;
  int __pyx_v_indx;
  PyObject *__pyx_v_selindx = NULL;
  PyObject *__pyx_v_v = NULL;
  PyObject *__pyx_v_k = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  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;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyArrayObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  int __pyx_t_14;
  __Pyx_TraceFrameInit(__pyx_codeobj__59)
  __Pyx_RefNannySetupContext("txevc_postprocess", 0);
  __Pyx_TraceCall("txevc_postprocess", __pyx_f[0], 1061, 0, __PYX_ERR(0, 1061, __pyx_L1_error));
  __Pyx_INCREF((PyObject *)__pyx_v_select);
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1061, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":1064
 *     cdef int N, M, i, m, indx
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     if select is None:
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 */
  __Pyx_TraceLine(1064,0,__PYX_ERR(0, 1064, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_T, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1064, __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, 1064, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1064, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_N = __pyx_t_3;

  /* "kwant/linalg/lapack.pyx":1065
 * 
 *     N = T.shape[0]
 *     if select is None:             # <<<<<<<<<<<<<<
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 *     selindx = select.nonzero()[0]
 */
  __Pyx_TraceLine(1065,0,__PYX_ERR(0, 1065, __pyx_L1_error))
  __pyx_t_4 = (((PyObject *)__pyx_v_select) == Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "kwant/linalg/lapack.pyx":1066
 *     N = T.shape[0]
 *     if select is None:
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)             # <<<<<<<<<<<<<<
 *     selindx = select.nonzero()[0]
 *     M = selindx.size
 */
    __Pyx_TraceLine(1066,0,__PYX_ERR(0, 1066, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ones); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1066, __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); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1066, __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, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1066, __pyx_L1_error)
    __pyx_t_9 = ((PyArrayObject *)__pyx_t_8);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
      __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_3 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        }
        __pyx_t_10 = __pyx_t_11 = __pyx_t_12 = 0;
      }
      __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1066, __pyx_L1_error)
    }
    __pyx_t_9 = 0;
    __Pyx_DECREF_SET(__pyx_v_select, ((PyArrayObject *)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "kwant/linalg/lapack.pyx":1065
 * 
 *     N = T.shape[0]
 *     if select is None:             # <<<<<<<<<<<<<<
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 *     selindx = select.nonzero()[0]
 */
  }

  /* "kwant/linalg/lapack.pyx":1067
 *     if select is None:
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 *     selindx = select.nonzero()[0]             # <<<<<<<<<<<<<<
 *     M = selindx.size
 * 
 */
  __Pyx_TraceLine(1067,0,__PYX_ERR(0, 1067, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1067, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_6) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1067, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1067, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1067, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_selindx = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1068
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 *     selindx = select.nonzero()[0]
 *     M = selindx.size             # <<<<<<<<<<<<<<
 * 
 *     v = np.empty((N, M), dtype = dtype, order='F')
 */
  __Pyx_TraceLine(1068,0,__PYX_ERR(0, 1068, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_selindx, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1068, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1068, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_M = __pyx_t_3;

  /* "kwant/linalg/lapack.pyx":1070
 *     M = selindx.size
 * 
 *     v = np.empty((N, M), dtype = dtype, order='F')             # <<<<<<<<<<<<<<
 * 
 *     indx = 0
 */
  __Pyx_TraceLine(1070,0,__PYX_ERR(0, 1070, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_M); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1070, __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_6);
  PyTuple_SET_ITEM(__pyx_t_1, 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, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 1070, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1070, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_v = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1072
 *     v = np.empty((N, M), dtype = dtype, order='F')
 * 
 *     indx = 0             # <<<<<<<<<<<<<<
 *     for m in range(M):
 *         k = selindx[m]
 */
  __Pyx_TraceLine(1072,0,__PYX_ERR(0, 1072, __pyx_L1_error))
  __pyx_v_indx = 0;

  /* "kwant/linalg/lapack.pyx":1073
 * 
 *     indx = 0
 *     for m in range(M):             # <<<<<<<<<<<<<<
 *         k = selindx[m]
 * 
 */
  __Pyx_TraceLine(1073,0,__PYX_ERR(0, 1073, __pyx_L1_error))
  __pyx_t_3 = __pyx_v_M;
  __pyx_t_13 = __pyx_t_3;
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_m = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":1074
 *     indx = 0
 *     for m in range(M):
 *         k = selindx[m]             # <<<<<<<<<<<<<<
 * 
 *         if k < N-1 and T[k+1,k]:
 */
    __Pyx_TraceLine(1074,0,__PYX_ERR(0, 1074, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_selindx, __pyx_v_m, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1074, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1076
 *         k = selindx[m]
 * 
 *         if k < N-1 and T[k+1,k]:             # <<<<<<<<<<<<<<
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the positive imaginary part desired
 */
    __Pyx_TraceLine(1076,0,__PYX_ERR(0, 1076, __pyx_L1_error))
    __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_N - 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_k, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {
    } else {
      __pyx_t_5 = __pyx_t_4;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_k, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_INCREF(__pyx_v_k);
    __Pyx_GIVEREF(__pyx_v_k);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_k);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_T, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1076, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_5 = __pyx_t_4;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_5) {

      /* "kwant/linalg/lapack.pyx":1079
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the positive imaginary part desired
 *             v[:, m] = vreal[:, indx] + 1j * vreal[:, indx + 1]             # <<<<<<<<<<<<<<
 * 
 *             # Check if the eigenvalue with negative real part is also
 */
      __Pyx_TraceLine(1079,0,__PYX_ERR(0, 1079, __pyx_L1_error))
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_indx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_slice__60);
      __Pyx_GIVEREF(__pyx_slice__60);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__60);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_vreal, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_v_indx + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_slice__61);
      __Pyx_GIVEREF(__pyx_slice__61);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_slice__61);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_vreal, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Multiply(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_slice__62);
      __Pyx_GIVEREF(__pyx_slice__62);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__62);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8);
      __pyx_t_8 = 0;
      if (unlikely(PyObject_SetItem(__pyx_v_v, __pyx_t_1, __pyx_t_6) < 0)) __PYX_ERR(0, 1079, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":1083
 *             # Check if the eigenvalue with negative real part is also
 *             # selected, if it is, we need the same entries in vr
 *             if not select[k+1]:             # <<<<<<<<<<<<<<
 *                 indx += 2
 *         elif k > 0 and T[k,k-1]:
 */
      __Pyx_TraceLine(1083,0,__PYX_ERR(0, 1083, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_k, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1083, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1083, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1083, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_4 = ((!__pyx_t_5) != 0);
      if (__pyx_t_4) {

        /* "kwant/linalg/lapack.pyx":1084
 *             # selected, if it is, we need the same entries in vr
 *             if not select[k+1]:
 *                 indx += 2             # <<<<<<<<<<<<<<
 *         elif k > 0 and T[k,k-1]:
 *             # we have the situation of a 2x2 block, and
 */
        __Pyx_TraceLine(1084,0,__PYX_ERR(0, 1084, __pyx_L1_error))
        __pyx_v_indx = (__pyx_v_indx + 2);

        /* "kwant/linalg/lapack.pyx":1083
 *             # Check if the eigenvalue with negative real part is also
 *             # selected, if it is, we need the same entries in vr
 *             if not select[k+1]:             # <<<<<<<<<<<<<<
 *                 indx += 2
 *         elif k > 0 and T[k,k-1]:
 */
      }

      /* "kwant/linalg/lapack.pyx":1076
 *         k = selindx[m]
 * 
 *         if k < N-1 and T[k+1,k]:             # <<<<<<<<<<<<<<
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the positive imaginary part desired
 */
      goto __pyx_L6;
    }

    /* "kwant/linalg/lapack.pyx":1085
 *             if not select[k+1]:
 *                 indx += 2
 *         elif k > 0 and T[k,k-1]:             # <<<<<<<<<<<<<<
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the negative imaginary part desired
 */
    __Pyx_TraceLine(1085,0,__PYX_ERR(0, 1085, __pyx_L1_error))
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_k, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1085, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1085, __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_L10_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_k, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_k);
    __Pyx_GIVEREF(__pyx_v_k);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_k);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_T, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1085, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __pyx_t_5;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_4) {

      /* "kwant/linalg/lapack.pyx":1088
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the negative imaginary part desired
 *             v[:, m] = vreal[:, indx] - 1j * vreal[:, indx + 1]             # <<<<<<<<<<<<<<
 * 
 *             indx += 2
 */
      __Pyx_TraceLine(1088,0,__PYX_ERR(0, 1088, __pyx_L1_error))
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_indx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_slice__63);
      __Pyx_GIVEREF(__pyx_slice__63);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_slice__63);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_vreal, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_v_indx + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_slice__64);
      __Pyx_GIVEREF(__pyx_slice__64);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__64);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_vreal, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1088, __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_t_2 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_slice__65);
      __Pyx_GIVEREF(__pyx_slice__65);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__65);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __pyx_t_2 = 0;
      if (unlikely(PyObject_SetItem(__pyx_v_v, __pyx_t_1, __pyx_t_8) < 0)) __PYX_ERR(0, 1088, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "kwant/linalg/lapack.pyx":1090
 *             v[:, m] = vreal[:, indx] - 1j * vreal[:, indx + 1]
 * 
 *             indx += 2             # <<<<<<<<<<<<<<
 *         else:
 *             # real eigenvalue
 */
      __Pyx_TraceLine(1090,0,__PYX_ERR(0, 1090, __pyx_L1_error))
      __pyx_v_indx = (__pyx_v_indx + 2);

      /* "kwant/linalg/lapack.pyx":1085
 *             if not select[k+1]:
 *                 indx += 2
 *         elif k > 0 and T[k,k-1]:             # <<<<<<<<<<<<<<
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the negative imaginary part desired
 */
      goto __pyx_L6;
    }

    /* "kwant/linalg/lapack.pyx":1093
 *         else:
 *             # real eigenvalue
 *             v[:, m] = vreal[:, indx]             # <<<<<<<<<<<<<<
 * 
 *             indx += 1
 */
    __Pyx_TraceLine(1093,0,__PYX_ERR(0, 1093, __pyx_L1_error))
    /*else*/ {
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_indx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_slice__66);
      __Pyx_GIVEREF(__pyx_slice__66);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__66);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_vreal, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_slice__67);
      __Pyx_GIVEREF(__pyx_slice__67);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__67);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
      __pyx_t_1 = 0;
      if (unlikely(PyObject_SetItem(__pyx_v_v, __pyx_t_2, __pyx_t_8) < 0)) __PYX_ERR(0, 1093, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "kwant/linalg/lapack.pyx":1095
 *             v[:, m] = vreal[:, indx]
 * 
 *             indx += 1             # <<<<<<<<<<<<<<
 *     return v
 * 
 */
      __Pyx_TraceLine(1095,0,__PYX_ERR(0, 1095, __pyx_L1_error))
      __pyx_v_indx = (__pyx_v_indx + 1);
    }
    __pyx_L6:;
  }

  /* "kwant/linalg/lapack.pyx":1096
 * 
 *             indx += 1
 *     return v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1096,0,__PYX_ERR(0, 1096, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_v);
  __pyx_r = __pyx_v_v;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1061
 * 
 * # Helper function for xTREVC and xTGEVC
 * def txevc_postprocess(dtype, T, vreal, np.ndarray[l_logical] select):             # <<<<<<<<<<<<<<
 *     cdef int N, M, i, m, indx
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.txevc_postprocess", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_selindx);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_k);
  __Pyx_XDECREF((PyObject *)__pyx_v_select);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1100
 * 
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_57strevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_57strevc = {"strevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_57strevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_57strevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("strevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1101
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[1] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1102
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1103
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_True);
    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_T)) != 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_Q);
          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_select);
          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_left);
          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_right);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "strevc") < 0)) __PYX_ERR(0, 1100, __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);
        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_T = ((PyArrayObject *)values[0]);
    __pyx_v_Q = ((PyArrayObject *)values[1]);
    __pyx_v_select = ((PyArrayObject *)values[2]);
    __pyx_v_left = values[3];
    __pyx_v_right = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("strevc", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1100, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.strevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1100, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1101, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1102, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_56strevc(__pyx_self, __pyx_v_T, __pyx_v_Q, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":1100
 * 
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_56strevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  float *__pyx_v_vl_r_ptr;
  float *__pyx_v_vr_r_ptr;
  PyArrayObject *__pyx_v_select_cpy = 0;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_cmplxindx = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select_cpy;
  __Pyx_Buffer __pyx_pybuffer_select_cpy;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__68)
  __Pyx_RefNannySetupContext("strevc", 0);
  __Pyx_TraceCall("strevc", __pyx_f[0], 1100, 0, __PYX_ERR(0, 1100, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_select_cpy.pybuffer.buf = NULL;
  __pyx_pybuffer_select_cpy.refcount = 0;
  __pyx_pybuffernd_select_cpy.data = NULL;
  __pyx_pybuffernd_select_cpy.rcbuffer = &__pyx_pybuffer_select_cpy;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1100, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1100, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1100, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":1114
 *     cdef np.ndarray[np.float32_t] work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(1114,0,__PYX_ERR(0, 1114, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1114, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1116
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(4*N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(1116,0,__PYX_ERR(0, 1116, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1117
 * 
 *     N = T.shape[0]
 *     work = np.empty(4*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(1117,0,__PYX_ERR(0, 1117, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1117, __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, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((4 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1117, __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, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1117, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1117, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1119
 *     work = np.empty(4*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(1119,0,__PYX_ERR(0, 1119, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1119, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1119, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1120
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(1120,0,__PYX_ERR(0, 1120, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":1119
 *     work = np.empty(4*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1121
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(1121,0,__PYX_ERR(0, 1121, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1121, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1122
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(1122,0,__PYX_ERR(0, 1122, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":1121
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1123
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(1123,0,__PYX_ERR(0, 1123, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1123, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1124
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(1124,0,__PYX_ERR(0, 1124, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":1123
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1126
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(1126,0,__PYX_ERR(0, 1126, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1128
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(1128,0,__PYX_ERR(0, 1128, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1129
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __Pyx_TraceLine(1129,0,__PYX_ERR(0, 1129, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":1130
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         # Correct for possible additional storage if a single complex
 *         # eigenvalue is selected.
 */
    __Pyx_TraceLine(1130,0,__PYX_ERR(0, 1130, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1130, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1130, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1130, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_MM = __pyx_t_13;

    /* "kwant/linalg/lapack.pyx":1134
 *         # eigenvalue is selected.
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]             # <<<<<<<<<<<<<<
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 */
    __Pyx_TraceLine(1134,0,__PYX_ERR(0, 1134, __pyx_L1_error))
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_4 = 0;
    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 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1134, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1134, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1134, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
      __Pyx_INCREF(__pyx_int_neg_1);
      __Pyx_GIVEREF(__pyx_int_neg_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_int_neg_1);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1134, __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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1134, __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 && likely(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);
      }
    }
    if (__pyx_t_1) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1134, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1134, __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, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1134, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cmplxindx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1135
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
    __Pyx_TraceLine(1135,0,__PYX_ERR(0, 1135, __pyx_L1_error))
    if (likely(PyList_CheckExact(__pyx_v_cmplxindx)) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_2 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_2); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
    } else {
      __pyx_t_14 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1135, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_15 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1135, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_15)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1135, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1135, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_15(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1135, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":1136
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __Pyx_TraceLine(1136,0,__PYX_ERR(0, 1136, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_12) {

        /* "kwant/linalg/lapack.pyx":1137
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # Select is overwritten in strevc.
 */
        __Pyx_TraceLine(1137,0,__PYX_ERR(0, 1137, __pyx_L1_error))
        __pyx_v_MM = (__pyx_v_MM + 1);

        /* "kwant/linalg/lapack.pyx":1136
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      }

      /* "kwant/linalg/lapack.pyx":1135
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
      __Pyx_TraceLine(1135,0,__PYX_ERR(0, 1135, __pyx_L1_error))
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1140
 * 
 *         # Select is overwritten in strevc.
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,             # <<<<<<<<<<<<<<
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data
 */
    __Pyx_TraceLine(1140,0,__PYX_ERR(0, 1140, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1140, __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, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_select));
    __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1140, __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, 1140, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1140, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __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;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1140, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_v_select_cpy, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_select_cpy.diminfo[0].strides = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select_cpy.diminfo[0].shape = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1140, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "kwant/linalg/lapack.pyx":1142
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(1142,0,__PYX_ERR(0, 1142, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);

    /* "kwant/linalg/lapack.pyx":1128
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1144
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
  __Pyx_TraceLine(1144,0,__PYX_ERR(0, 1144, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1145
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __Pyx_TraceLine(1145,0,__PYX_ERR(0, 1145, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1146
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __Pyx_TraceLine(1146,0,__PYX_ERR(0, 1146, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_11 = (__pyx_t_12 != 0);
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1147
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(1147,0,__PYX_ERR(0, 1147, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":1146
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
      goto __pyx_L10;
    }

    /* "kwant/linalg/lapack.pyx":1149
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(1149,0,__PYX_ERR(0, 1149, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L10:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1151
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1151,0,__PYX_ERR(0, 1151, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1151, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1152
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1152,0,__PYX_ERR(0, 1152, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_12 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_11 = __pyx_t_17;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_12 = (__pyx_t_17 != 0);
    __pyx_t_11 = __pyx_t_12;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1153
 *     if left:
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      __Pyx_TraceLine(1153,0,__PYX_ERR(0, 1153, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1153, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1153, __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_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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __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;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1153, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1153, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1152
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L12;
    }

    /* "kwant/linalg/lapack.pyx":1155
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 */
    __Pyx_TraceLine(1155,0,__PYX_ERR(0, 1155, __pyx_L1_error))
    /*else*/ {
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1155, __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, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1155, __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_6);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1155, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1155, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1155, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1155, __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_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1155, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1155, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":1156
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')
 *         vl_r_ptr = <float *>vl_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r_ptr = NULL
 */
    __Pyx_TraceLine(1156,0,__PYX_ERR(0, 1156, __pyx_L1_error))
    __pyx_v_vl_r_ptr = ((float *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":1151
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
    goto __pyx_L11;
  }

  /* "kwant/linalg/lapack.pyx":1158
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(1158,0,__PYX_ERR(0, 1158, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":1160
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1160,0,__PYX_ERR(0, 1160, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1160, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1161
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1161,0,__PYX_ERR(0, 1161, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_12 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_11 = __pyx_t_17;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_12 = (__pyx_t_17 != 0);
    __pyx_t_11 = __pyx_t_12;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1162
 *     if right:
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      __Pyx_TraceLine(1162,0,__PYX_ERR(0, 1162, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1162, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1162, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1162, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __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;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1162, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1162, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1161
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L16;
    }

    /* "kwant/linalg/lapack.pyx":1164
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 */
    __Pyx_TraceLine(1164,0,__PYX_ERR(0, 1164, __pyx_L1_error))
    /*else*/ {
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1164, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1164, __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_5);
      PyTuple_SET_ITEM(__pyx_t_3, 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, 1164, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1164, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1164, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1164, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L16:;

    /* "kwant/linalg/lapack.pyx":1165
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')
 *         vr_r_ptr = <float *>vr_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r_ptr = NULL
 */
    __Pyx_TraceLine(1165,0,__PYX_ERR(0, 1165, __pyx_L1_error))
    __pyx_v_vr_r_ptr = ((float *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":1160
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
    goto __pyx_L15;
  }

  /* "kwant/linalg/lapack.pyx":1167
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.strevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(1167,0,__PYX_ERR(0, 1167, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L15:;

  /* "kwant/linalg/lapack.pyx":1169
 *         vr_r_ptr = NULL
 * 
 *     f_lapack.strevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <float *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 */
  __Pyx_TraceLine(1169,0,__PYX_ERR(0, 1169, __pyx_L1_error))
  strevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_r_ptr, (&__pyx_v_N), __pyx_v_vr_r_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((float *)__pyx_v_work->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1174
 *                      <float *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in strevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in strevc"
 * 
 */
  __Pyx_TraceLine(1174,0,__PYX_ERR(0, 1174, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_strevc);
      __PYX_ERR(0, 1174, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1175
 * 
 *     assert info == 0, "Argument error in strevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in strevc"             # <<<<<<<<<<<<<<
 * 
 *     if select is not None and Q is not None:
 */
  __Pyx_TraceLine(1175,0,__PYX_ERR(0, 1175, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector);
      __PYX_ERR(0, 1175, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1177
 *     assert MM == M, "Unexpected number of eigenvectors returned in strevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  __Pyx_TraceLine(1177,0,__PYX_ERR(0, 1177, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_17 = (__pyx_t_12 != 0);
  if (__pyx_t_17) {
  } else {
    __pyx_t_11 = __pyx_t_17;
    goto __pyx_L20_bool_binop_done;
  }
  __pyx_t_17 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_17 != 0);
  __pyx_t_11 = __pyx_t_12;
  __pyx_L20_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1178
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __Pyx_TraceLine(1178,0,__PYX_ERR(0, 1178, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1178, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1179
 *     if select is not None and Q is not None:
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 */
      __Pyx_TraceLine(1179,0,__PYX_ERR(0, 1179, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1179, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1179, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1179, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1179, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1179, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1179, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1179, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1179, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1179, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl_r, ((PyArrayObject *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1178
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1180
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    __Pyx_TraceLine(1180,0,__PYX_ERR(0, 1180, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1180, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1181
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))             # <<<<<<<<<<<<<<
 * 
 *     # If there are complex eigenvalues, we need to postprocess the
 */
      __Pyx_TraceLine(1181,0,__PYX_ERR(0, 1181, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1181, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1181, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1181, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1181, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_19);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_19, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1181, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1181, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1181, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1181, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5);
          __pyx_t_5 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1181, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1181, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1181, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr_r, ((PyArrayObject *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1180
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":1177
 *     assert MM == M, "Unexpected number of eigenvectors returned in strevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  }

  /* "kwant/linalg/lapack.pyx":1185
 *     # If there are complex eigenvalues, we need to postprocess the
 *     # eigenvectors.
 *     if np.diagonal(T, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 */
  __Pyx_TraceLine(1185,0,__PYX_ERR(0, 1185, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  {
    __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(__pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, __pyx_int_neg_1);
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(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);
    }
  }
  if (__pyx_t_19) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1185, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __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, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1186
 *     # eigenvectors.
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:
 */
    __Pyx_TraceLine(1186,0,__PYX_ERR(0, 1186, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1186, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1187
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 */
      __Pyx_TraceLine(1187,0,__PYX_ERR(0, 1187, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __pyx_t_19 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1187, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1187, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1187, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_19) {
          __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_19); __pyx_t_19 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, __pyx_t_1);
        __Pyx_INCREF(((PyObject *)__pyx_v_T));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1187, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_vl = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1186
 *     # eigenvectors.
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1188
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 */
    __Pyx_TraceLine(1188,0,__PYX_ERR(0, 1188, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1188, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1189
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __Pyx_TraceLine(1189,0,__PYX_ERR(0, 1189, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1189, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1189, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1189, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1189, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, __pyx_t_1);
        __Pyx_INCREF(((PyObject *)__pyx_v_T));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_19, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1189, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_vr = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1188
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 */
    }

    /* "kwant/linalg/lapack.pyx":1185
 *     # If there are complex eigenvalues, we need to postprocess the
 *     # eigenvectors.
 *     if np.diagonal(T, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 */
    goto __pyx_L24;
  }

  /* "kwant/linalg/lapack.pyx":1191
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
  __Pyx_TraceLine(1191,0,__PYX_ERR(0, 1191, __pyx_L1_error))
  /*else*/ {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1191, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1192
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_TraceLine(1192,0,__PYX_ERR(0, 1192, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);

      /* "kwant/linalg/lapack.pyx":1191
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1193
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __Pyx_TraceLine(1193,0,__PYX_ERR(0, 1193, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1193, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1194
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(1194,0,__PYX_ERR(0, 1194, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);

      /* "kwant/linalg/lapack.pyx":1193
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    }
  }
  __pyx_L24:;

  /* "kwant/linalg/lapack.pyx":1196
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(1196,0,__PYX_ERR(0, 1196, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1196, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L30_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1196, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L30_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1197
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(1197,0,__PYX_ERR(0, 1197, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 1197, __pyx_L1_error) }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 1197, __pyx_L1_error) }
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_vr);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1196
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":1198
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(1198,0,__PYX_ERR(0, 1198, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1198, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1199
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(1199,0,__PYX_ERR(0, 1199, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 1199, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1198
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":1201
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1201,0,__PYX_ERR(0, 1201, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 1201, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":1100
 * 
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_19);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.strevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_select_cpy);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_cmplxindx);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1204
 * 
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_59dtrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_59dtrevc = {"dtrevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_59dtrevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_59dtrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dtrevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1205
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[1] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1206
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1207
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_True);
    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_T)) != 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_Q);
          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_select);
          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_left);
          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_right);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dtrevc") < 0)) __PYX_ERR(0, 1204, __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);
        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_T = ((PyArrayObject *)values[0]);
    __pyx_v_Q = ((PyArrayObject *)values[1]);
    __pyx_v_select = ((PyArrayObject *)values[2]);
    __pyx_v_left = values[3];
    __pyx_v_right = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dtrevc", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1204, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dtrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1204, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1205, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1206, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_58dtrevc(__pyx_self, __pyx_v_T, __pyx_v_Q, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":1204
 * 
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_58dtrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  double *__pyx_v_vl_r_ptr;
  double *__pyx_v_vr_r_ptr;
  PyArrayObject *__pyx_v_select_cpy = 0;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_cmplxindx = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select_cpy;
  __Pyx_Buffer __pyx_pybuffer_select_cpy;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__69)
  __Pyx_RefNannySetupContext("dtrevc", 0);
  __Pyx_TraceCall("dtrevc", __pyx_f[0], 1204, 0, __PYX_ERR(0, 1204, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_select_cpy.pybuffer.buf = NULL;
  __pyx_pybuffer_select_cpy.refcount = 0;
  __pyx_pybuffernd_select_cpy.data = NULL;
  __pyx_pybuffernd_select_cpy.rcbuffer = &__pyx_pybuffer_select_cpy;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1204, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1204, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1204, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":1218
 *     cdef np.ndarray[np.float64_t] work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(1218,0,__PYX_ERR(0, 1218, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1218, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1220
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(4*N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(1220,0,__PYX_ERR(0, 1220, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1221
 * 
 *     N = T.shape[0]
 *     work = np.empty(4*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(1221,0,__PYX_ERR(0, 1221, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1221, __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, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((4 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1221, __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, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1221, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1221, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1223
 *     work = np.empty(4*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(1223,0,__PYX_ERR(0, 1223, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1223, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1223, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1224
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(1224,0,__PYX_ERR(0, 1224, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":1223
 *     work = np.empty(4*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1225
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(1225,0,__PYX_ERR(0, 1225, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1225, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1226
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(1226,0,__PYX_ERR(0, 1226, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":1225
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1227
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(1227,0,__PYX_ERR(0, 1227, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1227, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1228
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(1228,0,__PYX_ERR(0, 1228, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":1227
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1230
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(1230,0,__PYX_ERR(0, 1230, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1232
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(1232,0,__PYX_ERR(0, 1232, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1233
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __Pyx_TraceLine(1233,0,__PYX_ERR(0, 1233, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":1234
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         # Correct for possible additional storage if a single complex
 *         # eigenvalue is selected.
 */
    __Pyx_TraceLine(1234,0,__PYX_ERR(0, 1234, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1234, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1234, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1234, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1234, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_MM = __pyx_t_13;

    /* "kwant/linalg/lapack.pyx":1238
 *         # eigenvalue is selected.
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]             # <<<<<<<<<<<<<<
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 */
    __Pyx_TraceLine(1238,0,__PYX_ERR(0, 1238, __pyx_L1_error))
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_4 = 0;
    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 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1238, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1238, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1238, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
      __Pyx_INCREF(__pyx_int_neg_1);
      __Pyx_GIVEREF(__pyx_int_neg_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_int_neg_1);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1238, __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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __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 && likely(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);
      }
    }
    if (__pyx_t_1) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1238, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1238, __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, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cmplxindx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1239
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
    __Pyx_TraceLine(1239,0,__PYX_ERR(0, 1239, __pyx_L1_error))
    if (likely(PyList_CheckExact(__pyx_v_cmplxindx)) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_2 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_2); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
    } else {
      __pyx_t_14 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1239, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_15 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1239, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_15)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1239, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1239, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1239, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1239, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_15(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1239, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":1240
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __Pyx_TraceLine(1240,0,__PYX_ERR(0, 1240, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1240, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_12) {

        /* "kwant/linalg/lapack.pyx":1241
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # Select is overwritten in dtrevc.
 */
        __Pyx_TraceLine(1241,0,__PYX_ERR(0, 1241, __pyx_L1_error))
        __pyx_v_MM = (__pyx_v_MM + 1);

        /* "kwant/linalg/lapack.pyx":1240
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      }

      /* "kwant/linalg/lapack.pyx":1239
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
      __Pyx_TraceLine(1239,0,__PYX_ERR(0, 1239, __pyx_L1_error))
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1244
 * 
 *         # Select is overwritten in dtrevc.
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,             # <<<<<<<<<<<<<<
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data
 */
    __Pyx_TraceLine(1244,0,__PYX_ERR(0, 1244, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1244, __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, 1244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_select));
    __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1244, __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, 1244, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1244, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1244, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __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;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1244, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_v_select_cpy, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_select_cpy.diminfo[0].strides = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select_cpy.diminfo[0].shape = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1244, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "kwant/linalg/lapack.pyx":1246
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(1246,0,__PYX_ERR(0, 1246, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);

    /* "kwant/linalg/lapack.pyx":1232
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1248
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
  __Pyx_TraceLine(1248,0,__PYX_ERR(0, 1248, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1249
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __Pyx_TraceLine(1249,0,__PYX_ERR(0, 1249, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1250
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __Pyx_TraceLine(1250,0,__PYX_ERR(0, 1250, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_11 = (__pyx_t_12 != 0);
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1251
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(1251,0,__PYX_ERR(0, 1251, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":1250
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
      goto __pyx_L10;
    }

    /* "kwant/linalg/lapack.pyx":1253
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(1253,0,__PYX_ERR(0, 1253, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L10:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1255
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1255,0,__PYX_ERR(0, 1255, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1255, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1256
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1256,0,__PYX_ERR(0, 1256, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_12 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_11 = __pyx_t_17;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_12 = (__pyx_t_17 != 0);
    __pyx_t_11 = __pyx_t_12;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1257
 *     if left:
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      __Pyx_TraceLine(1257,0,__PYX_ERR(0, 1257, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1257, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1257, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1257, __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_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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1257, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1257, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1257, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1257, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1257, __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;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1257, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1257, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1256
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L12;
    }

    /* "kwant/linalg/lapack.pyx":1259
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 */
    __Pyx_TraceLine(1259,0,__PYX_ERR(0, 1259, __pyx_L1_error))
    /*else*/ {
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1259, __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, 1259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1259, __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_6);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1259, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1259, __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, 1259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1259, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1259, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1259, __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_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1259, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1259, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":1260
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')
 *         vl_r_ptr = <double *>vl_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r_ptr = NULL
 */
    __Pyx_TraceLine(1260,0,__PYX_ERR(0, 1260, __pyx_L1_error))
    __pyx_v_vl_r_ptr = ((double *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":1255
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
    goto __pyx_L11;
  }

  /* "kwant/linalg/lapack.pyx":1262
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(1262,0,__PYX_ERR(0, 1262, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":1264
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1264,0,__PYX_ERR(0, 1264, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1264, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1265
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1265,0,__PYX_ERR(0, 1265, __pyx_L1_error))
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_12 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_11 = __pyx_t_17;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_12 = (__pyx_t_17 != 0);
    __pyx_t_11 = __pyx_t_12;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1266
 *     if right:
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      __Pyx_TraceLine(1266,0,__PYX_ERR(0, 1266, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1266, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1266, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1266, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1266, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1266, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1266, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1266, __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;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1266, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1266, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1265
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L16;
    }

    /* "kwant/linalg/lapack.pyx":1268
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 */
    __Pyx_TraceLine(1268,0,__PYX_ERR(0, 1268, __pyx_L1_error))
    /*else*/ {
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1268, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1268, __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_5);
      PyTuple_SET_ITEM(__pyx_t_3, 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, 1268, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1268, __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, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1268, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1268, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1268, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L16:;

    /* "kwant/linalg/lapack.pyx":1269
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')
 *         vr_r_ptr = <double *>vr_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r_ptr = NULL
 */
    __Pyx_TraceLine(1269,0,__PYX_ERR(0, 1269, __pyx_L1_error))
    __pyx_v_vr_r_ptr = ((double *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":1264
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
    goto __pyx_L15;
  }

  /* "kwant/linalg/lapack.pyx":1271
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dtrevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(1271,0,__PYX_ERR(0, 1271, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L15:;

  /* "kwant/linalg/lapack.pyx":1273
 *         vr_r_ptr = NULL
 * 
 *     f_lapack.dtrevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <double *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 */
  __Pyx_TraceLine(1273,0,__PYX_ERR(0, 1273, __pyx_L1_error))
  dtrevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_r_ptr, (&__pyx_v_N), __pyx_v_vr_r_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((double *)__pyx_v_work->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1278
 *                      <double *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in dtrevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtrevc"
 * 
 */
  __Pyx_TraceLine(1278,0,__PYX_ERR(0, 1278, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtrevc);
      __PYX_ERR(0, 1278, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1279
 * 
 *     assert info == 0, "Argument error in dtrevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtrevc"             # <<<<<<<<<<<<<<
 * 
 *     if select is not None and Q is not None:
 */
  __Pyx_TraceLine(1279,0,__PYX_ERR(0, 1279, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_2);
      __PYX_ERR(0, 1279, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1281
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  __Pyx_TraceLine(1281,0,__PYX_ERR(0, 1281, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_17 = (__pyx_t_12 != 0);
  if (__pyx_t_17) {
  } else {
    __pyx_t_11 = __pyx_t_17;
    goto __pyx_L20_bool_binop_done;
  }
  __pyx_t_17 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_17 != 0);
  __pyx_t_11 = __pyx_t_12;
  __pyx_L20_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1282
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __Pyx_TraceLine(1282,0,__PYX_ERR(0, 1282, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1282, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1283
 *     if select is not None and Q is not None:
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 */
      __Pyx_TraceLine(1283,0,__PYX_ERR(0, 1283, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1283, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1283, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1283, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1283, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1283, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1283, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1283, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1283, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1283, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1283, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1283, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl_r, ((PyArrayObject *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1282
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1284
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    __Pyx_TraceLine(1284,0,__PYX_ERR(0, 1284, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1284, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1285
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))             # <<<<<<<<<<<<<<
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 */
      __Pyx_TraceLine(1285,0,__PYX_ERR(0, 1285, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1285, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1285, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1285, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1285, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_19);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_19, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1285, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1285, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1285, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1285, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5);
          __pyx_t_5 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1285, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1285, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1285, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr_r, ((PyArrayObject *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1284
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":1281
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  }

  /* "kwant/linalg/lapack.pyx":1288
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(T, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 */
  __Pyx_TraceLine(1288,0,__PYX_ERR(0, 1288, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1288, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_T), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1288, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  {
    __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(__pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, __pyx_int_neg_1);
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1288, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(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);
    }
  }
  if (__pyx_t_19) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_19); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1288, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1288, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __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, 1288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1288, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1289
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:
 */
    __Pyx_TraceLine(1289,0,__PYX_ERR(0, 1289, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1289, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1290
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 */
      __Pyx_TraceLine(1290,0,__PYX_ERR(0, 1290, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1290, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1290, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1290, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __pyx_t_19 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1290, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1290, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_19) {
          __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_19); __pyx_t_19 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, __pyx_t_1);
        __Pyx_INCREF(((PyObject *)__pyx_v_T));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_vl = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1289
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1291
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 */
    __Pyx_TraceLine(1291,0,__PYX_ERR(0, 1291, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1291, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1292
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __Pyx_TraceLine(1292,0,__PYX_ERR(0, 1292, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1292, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1292, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 1292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, __pyx_t_1);
        __Pyx_INCREF(((PyObject *)__pyx_v_T));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_19, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_vr = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1291
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 */
    }

    /* "kwant/linalg/lapack.pyx":1288
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(T, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 */
    goto __pyx_L24;
  }

  /* "kwant/linalg/lapack.pyx":1294
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
  __Pyx_TraceLine(1294,0,__PYX_ERR(0, 1294, __pyx_L1_error))
  /*else*/ {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1294, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1295
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_TraceLine(1295,0,__PYX_ERR(0, 1295, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);

      /* "kwant/linalg/lapack.pyx":1294
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1296
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __Pyx_TraceLine(1296,0,__PYX_ERR(0, 1296, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1296, __pyx_L1_error)
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1297
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(1297,0,__PYX_ERR(0, 1297, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);

      /* "kwant/linalg/lapack.pyx":1296
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    }
  }
  __pyx_L24:;

  /* "kwant/linalg/lapack.pyx":1299
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(1299,0,__PYX_ERR(0, 1299, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1299, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L30_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1299, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L30_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1300
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(1300,0,__PYX_ERR(0, 1300, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 1300, __pyx_L1_error) }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 1300, __pyx_L1_error) }
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1300, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_vr);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1299
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":1301
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(1301,0,__PYX_ERR(0, 1301, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1301, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1302
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(1302,0,__PYX_ERR(0, 1302, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 1302, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1301
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":1304
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1304,0,__PYX_ERR(0, 1304, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 1304, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":1204
 * 
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_19);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dtrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_select_cpy);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_cmplxindx);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1307
 * 
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_61ctrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_61ctrevc = {"ctrevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_61ctrevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_61ctrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ctrevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1308
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[1] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1309
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1310
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_True);
    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_T)) != 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_Q);
          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_select);
          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_left);
          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_right);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ctrevc") < 0)) __PYX_ERR(0, 1307, __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);
        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_T = ((PyArrayObject *)values[0]);
    __pyx_v_Q = ((PyArrayObject *)values[1]);
    __pyx_v_select = ((PyArrayObject *)values[2]);
    __pyx_v_left = values[3];
    __pyx_v_right = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ctrevc", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1307, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ctrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1307, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1308, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1309, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_60ctrevc(__pyx_self, __pyx_v_T, __pyx_v_Q, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":1307
 * 
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_60ctrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_float_complex *__pyx_v_vl_ptr;
  __pyx_t_float_complex *__pyx_v_vr_ptr;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__70)
  __Pyx_RefNannySetupContext("ctrevc", 0);
  __Pyx_TraceCall("ctrevc", __pyx_f[0], 1307, 0, __PYX_ERR(0, 1307, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1307, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1307, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1307, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":1321
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(1321,0,__PYX_ERR(0, 1321, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1321, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1321, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1321, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1321, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1323
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(1323,0,__PYX_ERR(0, 1323, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1324
 * 
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(1324,0,__PYX_ERR(0, 1324, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1324, __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, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1324, __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, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1324, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1324, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1324, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1324, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1325
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(1325,0,__PYX_ERR(0, 1325, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1325, __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, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1325, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1325, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1325, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1325, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1327
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(1327,0,__PYX_ERR(0, 1327, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1327, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1327, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1328
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(1328,0,__PYX_ERR(0, 1328, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":1327
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1329
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(1329,0,__PYX_ERR(0, 1329, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1329, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1330
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(1330,0,__PYX_ERR(0, 1330, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":1329
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1331
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(1331,0,__PYX_ERR(0, 1331, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1331, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1332
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(1332,0,__PYX_ERR(0, 1332, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":1331
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1334
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(1334,0,__PYX_ERR(0, 1334, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1336
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(1336,0,__PYX_ERR(0, 1336, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_13 = (__pyx_t_12 != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1337
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __Pyx_TraceLine(1337,0,__PYX_ERR(0, 1337, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":1338
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __Pyx_TraceLine(1338,0,__PYX_ERR(0, 1338, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1338, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1338, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1338, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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, 1338, __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_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1338, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1338, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":1339
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(1339,0,__PYX_ERR(0, 1339, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);

    /* "kwant/linalg/lapack.pyx":1336
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1341
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
  __Pyx_TraceLine(1341,0,__PYX_ERR(0, 1341, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1342
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __Pyx_TraceLine(1342,0,__PYX_ERR(0, 1342, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1343
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __Pyx_TraceLine(1343,0,__PYX_ERR(0, 1343, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_12 = (__pyx_t_13 != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1344
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(1344,0,__PYX_ERR(0, 1344, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":1343
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
      goto __pyx_L7;
    }

    /* "kwant/linalg/lapack.pyx":1346
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(1346,0,__PYX_ERR(0, 1346, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1348
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1348,0,__PYX_ERR(0, 1348, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1348, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1349
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1349,0,__PYX_ERR(0, 1349, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_13 != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_12 = __pyx_t_15;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_13 = (__pyx_t_15 != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1350
 *     if left:
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      __Pyx_TraceLine(1350,0,__PYX_ERR(0, 1350, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_2) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1350, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1350, __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_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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1350, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1350, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __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[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1350, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1350, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1350, __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;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1350, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1350, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":1349
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L9;
    }

    /* "kwant/linalg/lapack.pyx":1352
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *     else:
 */
    __Pyx_TraceLine(1352,0,__PYX_ERR(0, 1352, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1352, __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, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1352, __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_2);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1352, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1352, __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_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1352, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1352, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":1353
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(1353,0,__PYX_ERR(0, 1353, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_float_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":1348
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
    goto __pyx_L8;
  }

  /* "kwant/linalg/lapack.pyx":1355
 *         vl_ptr = <float complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(1355,0,__PYX_ERR(0, 1355, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":1357
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1357,0,__PYX_ERR(0, 1357, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1357, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1358
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1358,0,__PYX_ERR(0, 1358, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_13 != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_12 = __pyx_t_15;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_13 = (__pyx_t_15 != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1359
 *     if right:
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      __Pyx_TraceLine(1359,0,__PYX_ERR(0, 1359, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1359, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1359, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1359, __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);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1359, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1359, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_6);
      __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);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1359, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1359, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 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_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1359, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1359, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1359, __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;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1359, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1359, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1358
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L13;
    }

    /* "kwant/linalg/lapack.pyx":1361
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *     else:
 */
    __Pyx_TraceLine(1361,0,__PYX_ERR(0, 1361, __pyx_L1_error))
    /*else*/ {
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1361, __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, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1361, __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_3);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 1361, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1361, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1361, __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_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1361, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1361, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L13:;

    /* "kwant/linalg/lapack.pyx":1362
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(1362,0,__PYX_ERR(0, 1362, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_float_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":1357
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
    goto __pyx_L12;
  }

  /* "kwant/linalg/lapack.pyx":1364
 *         vr_ptr = <float complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ctrevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(1364,0,__PYX_ERR(0, 1364, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L12:;

  /* "kwant/linalg/lapack.pyx":1366
 *         vr_ptr = NULL
 * 
 *     f_lapack.ctrevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 */
  __Pyx_TraceLine(1366,0,__PYX_ERR(0, 1366, __pyx_L1_error))
  ctrevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((__pyx_t_float_complex *)__pyx_v_work->data), ((float *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1371
 *                      <float complex *>work.data, <float *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in ctrevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctrevc"
 * 
 */
  __Pyx_TraceLine(1371,0,__PYX_ERR(0, 1371, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctrevc);
      __PYX_ERR(0, 1371, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1372
 * 
 *     assert info == 0, "Argument error in ctrevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctrevc"             # <<<<<<<<<<<<<<
 * 
 *     if select is not None and Q is not None:
 */
  __Pyx_TraceLine(1372,0,__PYX_ERR(0, 1372, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_3);
      __PYX_ERR(0, 1372, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1374
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __Pyx_TraceLine(1374,0,__PYX_ERR(0, 1374, __pyx_L1_error))
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_15 = (__pyx_t_13 != 0);
  if (__pyx_t_15) {
  } else {
    __pyx_t_12 = __pyx_t_15;
    goto __pyx_L17_bool_binop_done;
  }
  __pyx_t_15 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_13 = (__pyx_t_15 != 0);
  __pyx_t_12 = __pyx_t_13;
  __pyx_L17_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1375
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __Pyx_TraceLine(1375,0,__PYX_ERR(0, 1375, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1375, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1376
 *     if select is not None and Q is not None:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))
 */
      __Pyx_TraceLine(1376,0,__PYX_ERR(0, 1376, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1376, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1376, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_2) {
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2); __pyx_t_2 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1376, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1376, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1376, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1375
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1377
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    __Pyx_TraceLine(1377,0,__PYX_ERR(0, 1377, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1377, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1378
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(1378,0,__PYX_ERR(0, 1378, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1378, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1378, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1378, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1378, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1378, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1378, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1378, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_17))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_17);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_17, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1378, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1378, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1378, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1377
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":1374
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  }

  /* "kwant/linalg/lapack.pyx":1380
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(1380,0,__PYX_ERR(0, 1380, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1380, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L22_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1380, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L22_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1381
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(1381,0,__PYX_ERR(0, 1381, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1381, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vr));
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1380
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":1382
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(1382,0,__PYX_ERR(0, 1382, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1382, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1383
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(1383,0,__PYX_ERR(0, 1383, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1382
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":1385
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1385,0,__PYX_ERR(0, 1385, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":1307
 * 
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_17);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ctrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1388
 * 
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_63ztrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_63ztrevc = {"ztrevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_63ztrevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_63ztrevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ztrevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1389
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[1] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1390
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1391
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_True);
    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_T)) != 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_Q);
          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_select);
          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_left);
          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_right);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ztrevc") < 0)) __PYX_ERR(0, 1388, __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);
        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_T = ((PyArrayObject *)values[0]);
    __pyx_v_Q = ((PyArrayObject *)values[1]);
    __pyx_v_select = ((PyArrayObject *)values[2]);
    __pyx_v_left = values[3];
    __pyx_v_right = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ztrevc", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1388, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ztrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1388, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1389, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1390, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_62ztrevc(__pyx_self, __pyx_v_T, __pyx_v_Q, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":1388
 * 
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_62ztrevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_double_complex *__pyx_v_vl_ptr;
  __pyx_t_double_complex *__pyx_v_vr_ptr;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__71)
  __Pyx_RefNannySetupContext("ztrevc", 0);
  __Pyx_TraceCall("ztrevc", __pyx_f[0], 1388, 0, __PYX_ERR(0, 1388, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1388, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1388, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1388, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":1402
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __Pyx_TraceLine(1402,0,__PYX_ERR(0, 1402, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1402, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1402, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1402, __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(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1402, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1404
 *     assert_fortran_mat(T, Q)
 * 
 *     N = T.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(1404,0,__PYX_ERR(0, 1404, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1405
 * 
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(1405,0,__PYX_ERR(0, 1405, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1405, __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, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1405, __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, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1405, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1405, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1405, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1405, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1406
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(1406,0,__PYX_ERR(0, 1406, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1406, __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, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1406, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1406, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1406, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1406, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1406, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1408
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(1408,0,__PYX_ERR(0, 1408, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1408, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1408, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1409
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(1409,0,__PYX_ERR(0, 1409, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":1408
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1410
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(1410,0,__PYX_ERR(0, 1410, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1410, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1411
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(1411,0,__PYX_ERR(0, 1411, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":1410
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1412
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(1412,0,__PYX_ERR(0, 1412, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1412, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1413
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(1413,0,__PYX_ERR(0, 1413, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":1412
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1415
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(1415,0,__PYX_ERR(0, 1415, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1417
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(1417,0,__PYX_ERR(0, 1417, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_13 = (__pyx_t_12 != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1418
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __Pyx_TraceLine(1418,0,__PYX_ERR(0, 1418, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":1419
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __Pyx_TraceLine(1419,0,__PYX_ERR(0, 1419, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1419, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1419, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1419, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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, 1419, __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_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1419, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":1420
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(1420,0,__PYX_ERR(0, 1420, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);

    /* "kwant/linalg/lapack.pyx":1417
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1422
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
  __Pyx_TraceLine(1422,0,__PYX_ERR(0, 1422, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1423
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __Pyx_TraceLine(1423,0,__PYX_ERR(0, 1423, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1424
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __Pyx_TraceLine(1424,0,__PYX_ERR(0, 1424, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_12 = (__pyx_t_13 != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1425
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(1425,0,__PYX_ERR(0, 1425, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":1424
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
      goto __pyx_L7;
    }

    /* "kwant/linalg/lapack.pyx":1427
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(1427,0,__PYX_ERR(0, 1427, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1429
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1429,0,__PYX_ERR(0, 1429, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1429, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1430
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1430,0,__PYX_ERR(0, 1430, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_13 != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_12 = __pyx_t_15;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_13 = (__pyx_t_15 != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1431
 *     if left:
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      __Pyx_TraceLine(1431,0,__PYX_ERR(0, 1431, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1431, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1431, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1431, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(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);
        }
      }
      if (__pyx_t_2) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1431, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1431, __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_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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1431, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1431, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __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[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1431, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1431, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1431, __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;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1431, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1431, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":1430
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L9;
    }

    /* "kwant/linalg/lapack.pyx":1433
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *     else:
 */
    __Pyx_TraceLine(1433,0,__PYX_ERR(0, 1433, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1433, __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, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1433, __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_2);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1433, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1433, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1433, __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_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1433, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1433, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":1434
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(1434,0,__PYX_ERR(0, 1434, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_double_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":1429
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
    goto __pyx_L8;
  }

  /* "kwant/linalg/lapack.pyx":1436
 *         vl_ptr = <double complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(1436,0,__PYX_ERR(0, 1436, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":1438
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
  __Pyx_TraceLine(1438,0,__PYX_ERR(0, 1438, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1438, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1439
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
    __Pyx_TraceLine(1439,0,__PYX_ERR(0, 1439, __pyx_L1_error))
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_13 != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_12 = __pyx_t_15;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_select) == Py_None);
    __pyx_t_13 = (__pyx_t_15 != 0);
    __pyx_t_12 = __pyx_t_13;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1440
 *     if right:
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      __Pyx_TraceLine(1440,0,__PYX_ERR(0, 1440, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1440, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s_copy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1440, __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);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1440, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1440, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_6);
      __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);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1440, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1440, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 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_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1440, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1440, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1440, __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;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1440, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1440, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1439
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
      goto __pyx_L13;
    }

    /* "kwant/linalg/lapack.pyx":1442
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *     else:
 */
    __Pyx_TraceLine(1442,0,__PYX_ERR(0, 1442, __pyx_L1_error))
    /*else*/ {
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1442, __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, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1442, __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_3);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex128); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 1442, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1442, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1442, __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_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1442, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1442, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L13:;

    /* "kwant/linalg/lapack.pyx":1443
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(1443,0,__PYX_ERR(0, 1443, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_double_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":1438
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
    goto __pyx_L12;
  }

  /* "kwant/linalg/lapack.pyx":1445
 *         vr_ptr = <double complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ztrevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(1445,0,__PYX_ERR(0, 1445, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L12:;

  /* "kwant/linalg/lapack.pyx":1447
 *         vr_ptr = NULL
 * 
 *     f_lapack.ztrevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 */
  __Pyx_TraceLine(1447,0,__PYX_ERR(0, 1447, __pyx_L1_error))
  ztrevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((__pyx_t_double_complex *)__pyx_v_work->data), ((double *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1452
 *                      <double complex *>work.data, <double *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in ztrevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztrevc"
 * 
 */
  __Pyx_TraceLine(1452,0,__PYX_ERR(0, 1452, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztrevc);
      __PYX_ERR(0, 1452, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1453
 * 
 *     assert info == 0, "Argument error in ztrevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztrevc"             # <<<<<<<<<<<<<<
 * 
 *     if select is not None and Q is not None:
 */
  __Pyx_TraceLine(1453,0,__PYX_ERR(0, 1453, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_4);
      __PYX_ERR(0, 1453, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1455
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __Pyx_TraceLine(1455,0,__PYX_ERR(0, 1455, __pyx_L1_error))
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_15 = (__pyx_t_13 != 0);
  if (__pyx_t_15) {
  } else {
    __pyx_t_12 = __pyx_t_15;
    goto __pyx_L17_bool_binop_done;
  }
  __pyx_t_15 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_13 = (__pyx_t_15 != 0);
  __pyx_t_12 = __pyx_t_13;
  __pyx_L17_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1456
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __Pyx_TraceLine(1456,0,__PYX_ERR(0, 1456, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1456, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1457
 *     if select is not None and Q is not None:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))
 */
      __Pyx_TraceLine(1457,0,__PYX_ERR(0, 1457, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1457, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      __pyx_t_4 = 0;
      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_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1457, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1457, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1457, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_2) {
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2); __pyx_t_2 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1457, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __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);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1457, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1457, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_6};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1457, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1457, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1457, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1457, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1457, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1456
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":1458
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    __Pyx_TraceLine(1458,0,__PYX_ERR(0, 1458, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1458, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1459
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(1459,0,__PYX_ERR(0, 1459, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1459, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vr)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1459, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1459, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1459, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_17))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_17);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_17, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1459, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1459, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1459, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1459, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1459, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1459, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1459, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1458
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":1455
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztrevc"
 * 
 *     if select is not None and Q is not None:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  }

  /* "kwant/linalg/lapack.pyx":1461
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(1461,0,__PYX_ERR(0, 1461, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L22_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L22_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1462
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(1462,0,__PYX_ERR(0, 1462, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vr));
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1461
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":1463
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(1463,0,__PYX_ERR(0, 1463, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1463, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1464
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(1464,0,__PYX_ERR(0, 1464, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":1463
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":1466
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1466,0,__PYX_ERR(0, 1466, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":1388
 * 
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_17);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ztrevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1470
 * 
 * # wrappers for xGGES
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_65sgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_65sgges = {"sgges", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_65sgges, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_65sgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sgges (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_calc_q,&__pyx_n_s_calc_z,&__pyx_n_s_calc_ev,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1472
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvsl
 */
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgges", 0, 2, 5, 1); __PYX_ERR(0, 1470, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_q);
          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_calc_z);
          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_calc_ev);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sgges") < 0)) __PYX_ERR(0, 1470, __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);
        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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_calc_q = values[2];
    __pyx_v_calc_z = values[3];
    __pyx_v_calc_ev = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sgges", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1470, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.sgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 1470, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 1471, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_64sgges(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_calc_q, __pyx_v_calc_z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1470
 * 
 * # wrappers for xGGES
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_64sgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvsl;
  char *__pyx_v_jobvsr;
  float *__pyx_v_vsl_ptr;
  float *__pyx_v_vsr_ptr;
  float __pyx_v_qwork;
  PyArrayObject *__pyx_v_vsl = 0;
  PyArrayObject *__pyx_v_vsr = 0;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_alpha = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsl;
  __Pyx_Buffer __pyx_pybuffer_vsl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsr;
  __Pyx_Buffer __pyx_pybuffer_vsr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__72)
  __Pyx_RefNannySetupContext("sgges", 0);
  __Pyx_TraceCall("sgges", __pyx_f[0], 1470, 0, __PYX_ERR(0, 1470, __pyx_L1_error));
  __pyx_pybuffer_vsl.pybuffer.buf = NULL;
  __pyx_pybuffer_vsl.refcount = 0;
  __pyx_pybuffernd_vsl.data = NULL;
  __pyx_pybuffernd_vsl.rcbuffer = &__pyx_pybuffer_vsl;
  __pyx_pybuffer_vsr.pybuffer.buf = NULL;
  __pyx_pybuffer_vsr.refcount = 0;
  __pyx_pybuffernd_vsr.data = NULL;
  __pyx_pybuffernd_vsr.rcbuffer = &__pyx_pybuffer_vsr;
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1470, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1470, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1482
 *     cdef np.ndarray[np.float32_t] alphar, alphai, beta, work
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(1482,0,__PYX_ERR(0, 1482, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1482, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1482, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1482, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1482, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1484
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(1484,0,__PYX_ERR(0, 1484, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1485
 * 
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(1485,0,__PYX_ERR(0, 1485, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1485, __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, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1485, __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, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1485, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1485, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1485, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1486
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(1486,0,__PYX_ERR(0, 1486, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1486, __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, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1486, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1486, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1486, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1486, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1487
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(1487,0,__PYX_ERR(0, 1487, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1487, __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, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1487, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1487, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1489
 *     beta = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data
 */
  __Pyx_TraceLine(1489,0,__PYX_ERR(0, 1489, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1489, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1490
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <float *>vsl.data
 *         jobvsl = "V"
 */
    __Pyx_TraceLine(1490,0,__PYX_ERR(0, 1490, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1490, __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, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1490, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1490, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1490, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1490, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1490, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1490, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1490, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1491
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __Pyx_TraceLine(1491,0,__PYX_ERR(0, 1491, __pyx_L1_error))
    __pyx_v_vsl_ptr = ((float *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1492
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __Pyx_TraceLine(1492,0,__PYX_ERR(0, 1492, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1489
 *     beta = np.empty(N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1494
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
  __Pyx_TraceLine(1494,0,__PYX_ERR(0, 1494, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1494, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1495
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __Pyx_TraceLine(1495,0,__PYX_ERR(0, 1495, __pyx_L1_error))
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1496
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __Pyx_TraceLine(1496,0,__PYX_ERR(0, 1496, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1498
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data
 */
  __Pyx_TraceLine(1498,0,__PYX_ERR(0, 1498, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1498, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1499
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <float *>vsr.data
 *         jobvsr = "V"
 */
    __Pyx_TraceLine(1499,0,__PYX_ERR(0, 1499, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1499, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1499, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 1499, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1499, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1499, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1499, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1500
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __Pyx_TraceLine(1500,0,__PYX_ERR(0, 1500, __pyx_L1_error))
    __pyx_v_vsr_ptr = ((float *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1501
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __Pyx_TraceLine(1501,0,__PYX_ERR(0, 1501, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1498
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1503
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
  __Pyx_TraceLine(1503,0,__PYX_ERR(0, 1503, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1503, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1504
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __Pyx_TraceLine(1504,0,__PYX_ERR(0, 1504, __pyx_L1_error))
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1505
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1505,0,__PYX_ERR(0, 1505, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1508
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.sgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <float *>A.data, &N,
 */
  __Pyx_TraceLine(1508,0,__PYX_ERR(0, 1508, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1509
 *     # workspace query
 *     lwork = -1
 *     f_lapack.sgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <float *>A.data, &N,
 *                     <float *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1509,0,__PYX_ERR(0, 1509, __pyx_L1_error))
  sgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), ((float *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1517
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(1517,0,__PYX_ERR(0, 1517, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1517, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1519
 *     assert info == 0, "Argument error in zgees"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(1519,0,__PYX_ERR(0, 1519, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":1520
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1520,0,__PYX_ERR(0, 1520, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1520, __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, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1520, __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, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1520, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1520, __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, 1520, __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, 1520, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1520, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1520, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1523
 * 
 *     # Now the real calculation
 *     f_lapack.sgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <float *>A.data, &N,
 *                     <float *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1523,0,__PYX_ERR(0, 1523, __pyx_L1_error))
  sgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((float *)__pyx_v_A->data), (&__pyx_v_N), ((float *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), ((float *)__pyx_v_work->data), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1531
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sgges")
 * 
 */
  __Pyx_TraceLine(1531,0,__PYX_ERR(0, 1531, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":1532
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __Pyx_TraceLine(1532,0,__PYX_ERR(0, 1532, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1532, __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, 1532, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1531
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sgges")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1534
 *         raise LinAlgError("QZ iteration failed to converge in sgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  __Pyx_TraceLine(1534,0,__PYX_ERR(0, 1534, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1534, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1536
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __Pyx_TraceLine(1536,0,__PYX_ERR(0, 1536, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1536, __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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1536, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1536, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __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, 1536, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1536, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1536, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1537
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __Pyx_TraceLine(1537,0,__PYX_ERR(0, 1537, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_alpha = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1536
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1539
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
  __Pyx_TraceLine(1539,0,__PYX_ERR(0, 1539, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1541
 *         alpha = alphar
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1541,0,__PYX_ERR(0, 1541, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 1, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1542
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1542,0,__PYX_ERR(0, 1542, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1541, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1541, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1541, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1541, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1470
 * 
 * # wrappers for xGGES
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.sgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vsl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vsr);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1545
 * 
 * 
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_67dgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_67dgges = {"dgges", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_67dgges, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_67dgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dgges (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_calc_q,&__pyx_n_s_calc_z,&__pyx_n_s_calc_ev,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1547
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvsl
 */
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgges", 0, 2, 5, 1); __PYX_ERR(0, 1545, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_q);
          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_calc_z);
          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_calc_ev);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dgges") < 0)) __PYX_ERR(0, 1545, __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);
        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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_calc_q = values[2];
    __pyx_v_calc_z = values[3];
    __pyx_v_calc_ev = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dgges", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1545, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 1545, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 1546, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_66dgges(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_calc_q, __pyx_v_calc_z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1545
 * 
 * 
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_66dgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvsl;
  char *__pyx_v_jobvsr;
  double *__pyx_v_vsl_ptr;
  double *__pyx_v_vsr_ptr;
  double __pyx_v_qwork;
  PyArrayObject *__pyx_v_vsl = 0;
  PyArrayObject *__pyx_v_vsr = 0;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyObject *__pyx_v_alpha = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsl;
  __Pyx_Buffer __pyx_pybuffer_vsl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsr;
  __Pyx_Buffer __pyx_pybuffer_vsr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__74)
  __Pyx_RefNannySetupContext("dgges", 0);
  __Pyx_TraceCall("dgges", __pyx_f[0], 1545, 0, __PYX_ERR(0, 1545, __pyx_L1_error));
  __pyx_pybuffer_vsl.pybuffer.buf = NULL;
  __pyx_pybuffer_vsl.refcount = 0;
  __pyx_pybuffernd_vsl.data = NULL;
  __pyx_pybuffernd_vsl.rcbuffer = &__pyx_pybuffer_vsl;
  __pyx_pybuffer_vsr.pybuffer.buf = NULL;
  __pyx_pybuffer_vsr.refcount = 0;
  __pyx_pybuffernd_vsr.data = NULL;
  __pyx_pybuffernd_vsr.rcbuffer = &__pyx_pybuffer_vsr;
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1545, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1545, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1557
 *     cdef np.ndarray[np.float64_t] alphar, alphai, beta, work
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(1557,0,__PYX_ERR(0, 1557, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1557, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1557, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1557, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1557, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1559
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(1559,0,__PYX_ERR(0, 1559, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1560
 * 
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(1560,0,__PYX_ERR(0, 1560, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1560, __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, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1560, __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, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1560, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1560, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1561
 *     N = A.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(1561,0,__PYX_ERR(0, 1561, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1561, __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, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1561, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1561, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1561, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1561, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1562
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(1562,0,__PYX_ERR(0, 1562, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1562, __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, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1562, __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, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1562, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1562, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1562, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1564
 *     beta = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data
 */
  __Pyx_TraceLine(1564,0,__PYX_ERR(0, 1564, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1564, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1565
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <double *>vsl.data
 *         jobvsl = "V"
 */
    __Pyx_TraceLine(1565,0,__PYX_ERR(0, 1565, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1565, __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, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1565, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1565, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1565, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1565, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1565, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1565, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1565, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1566
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __Pyx_TraceLine(1566,0,__PYX_ERR(0, 1566, __pyx_L1_error))
    __pyx_v_vsl_ptr = ((double *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1567
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __Pyx_TraceLine(1567,0,__PYX_ERR(0, 1567, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1564
 *     beta = np.empty(N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1569
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
  __Pyx_TraceLine(1569,0,__PYX_ERR(0, 1569, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1569, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1570
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __Pyx_TraceLine(1570,0,__PYX_ERR(0, 1570, __pyx_L1_error))
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1571
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __Pyx_TraceLine(1571,0,__PYX_ERR(0, 1571, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1573
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data
 */
  __Pyx_TraceLine(1573,0,__PYX_ERR(0, 1573, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1573, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1574
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <double *>vsr.data
 *         jobvsr = "V"
 */
    __Pyx_TraceLine(1574,0,__PYX_ERR(0, 1574, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1574, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1574, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 1574, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1574, __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, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1574, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1574, __pyx_L1_error)
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1574, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1575
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __Pyx_TraceLine(1575,0,__PYX_ERR(0, 1575, __pyx_L1_error))
    __pyx_v_vsr_ptr = ((double *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1576
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __Pyx_TraceLine(1576,0,__PYX_ERR(0, 1576, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1573
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1578
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
  __Pyx_TraceLine(1578,0,__PYX_ERR(0, 1578, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1578, __pyx_L1_error)
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1579
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __Pyx_TraceLine(1579,0,__PYX_ERR(0, 1579, __pyx_L1_error))
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1580
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1580,0,__PYX_ERR(0, 1580, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1583
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <double *>A.data, &N,
 */
  __Pyx_TraceLine(1583,0,__PYX_ERR(0, 1583, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1584
 *     # workspace query
 *     lwork = -1
 *     f_lapack.dgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <double *>A.data, &N,
 *                     <double *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1584,0,__PYX_ERR(0, 1584, __pyx_L1_error))
  dgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), ((double *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1592
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(1592,0,__PYX_ERR(0, 1592, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1592, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1594
 *     assert info == 0, "Argument error in zgees"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(1594,0,__PYX_ERR(0, 1594, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":1595
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1595,0,__PYX_ERR(0, 1595, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1595, __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, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1595, __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, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __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, 1595, __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, 1595, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1595, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1595, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1598
 * 
 *     # Now the real calculation
 *     f_lapack.dgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <double *>A.data, &N,
 *                     <double *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1598,0,__PYX_ERR(0, 1598, __pyx_L1_error))
  dgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((double *)__pyx_v_A->data), (&__pyx_v_N), ((double *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), ((double *)__pyx_v_work->data), (&__pyx_v_lwork), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1606
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dgges")
 * 
 */
  __Pyx_TraceLine(1606,0,__PYX_ERR(0, 1606, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":1607
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __Pyx_TraceLine(1607,0,__PYX_ERR(0, 1607, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1607, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1607, __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, 1607, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1606
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dgges")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1609
 *         raise LinAlgError("QZ iteration failed to converge in dgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  __Pyx_TraceLine(1609,0,__PYX_ERR(0, 1609, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1609, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1611
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __Pyx_TraceLine(1611,0,__PYX_ERR(0, 1611, __pyx_L1_error))
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1611, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1611, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __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, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1612
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __Pyx_TraceLine(1612,0,__PYX_ERR(0, 1612, __pyx_L1_error))
    __pyx_t_2 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_alpha = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1611
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1614
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
  __Pyx_TraceLine(1614,0,__PYX_ERR(0, 1614, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1616
 *         alpha = alphar
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1616,0,__PYX_ERR(0, 1616, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 1, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1617
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1617,0,__PYX_ERR(0, 1617, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_13 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1616, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1545
 * 
 * 
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vsl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vsr);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1620
 * 
 * 
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_69cgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_69cgges = {"cgges", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_69cgges, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_69cgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cgges (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_calc_q,&__pyx_n_s_calc_z,&__pyx_n_s_calc_ev,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1622
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvsl
 */
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgges", 0, 2, 5, 1); __PYX_ERR(0, 1620, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_q);
          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_calc_z);
          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_calc_ev);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cgges") < 0)) __PYX_ERR(0, 1620, __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);
        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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_calc_q = values[2];
    __pyx_v_calc_z = values[3];
    __pyx_v_calc_ev = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cgges", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1620, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.cgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 1620, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 1621, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_68cgges(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_calc_q, __pyx_v_calc_z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1620
 * 
 * 
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_68cgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvsl;
  char *__pyx_v_jobvsr;
  __pyx_t_float_complex *__pyx_v_vsl_ptr;
  __pyx_t_float_complex *__pyx_v_vsr_ptr;
  __pyx_t_float_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_vsl = 0;
  PyArrayObject *__pyx_v_vsr = 0;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsl;
  __Pyx_Buffer __pyx_pybuffer_vsl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsr;
  __Pyx_Buffer __pyx_pybuffer_vsr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__76)
  __Pyx_RefNannySetupContext("cgges", 0);
  __Pyx_TraceCall("cgges", __pyx_f[0], 1620, 0, __PYX_ERR(0, 1620, __pyx_L1_error));
  __pyx_pybuffer_vsl.pybuffer.buf = NULL;
  __pyx_pybuffer_vsl.refcount = 0;
  __pyx_pybuffernd_vsl.data = NULL;
  __pyx_pybuffernd_vsl.rcbuffer = &__pyx_pybuffer_vsl;
  __pyx_pybuffer_vsr.pybuffer.buf = NULL;
  __pyx_pybuffer_vsr.refcount = 0;
  __pyx_pybuffernd_vsr.data = NULL;
  __pyx_pybuffernd_vsr.rcbuffer = &__pyx_pybuffer_vsr;
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1620, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1620, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1633
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(1633,0,__PYX_ERR(0, 1633, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1633, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1633, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1633, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1633, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1635
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 */
  __Pyx_TraceLine(1635,0,__PYX_ERR(0, 1635, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1636
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex64)
 *     rwork = np.empty(8*N, dtype = np.float32)
 */
  __Pyx_TraceLine(1636,0,__PYX_ERR(0, 1636, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1636, __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, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1636, __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, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1636, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1636, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1636, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1636, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1637
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(8*N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(1637,0,__PYX_ERR(0, 1637, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1637, __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, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1637, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1637, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1637, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1637, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1638
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 *     rwork = np.empty(8*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(1638,0,__PYX_ERR(0, 1638, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((8 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1638, __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, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1638, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1638, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1640
 *     rwork = np.empty(8*N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data
 */
  __Pyx_TraceLine(1640,0,__PYX_ERR(0, 1640, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1640, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1641
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <float complex *>vsl.data
 *         jobvsl = "V"
 */
    __Pyx_TraceLine(1641,0,__PYX_ERR(0, 1641, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1641, __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, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1641, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1641, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1641, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1641, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1641, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1641, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1641, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1642
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __Pyx_TraceLine(1642,0,__PYX_ERR(0, 1642, __pyx_L1_error))
    __pyx_v_vsl_ptr = ((__pyx_t_float_complex *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1643
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __Pyx_TraceLine(1643,0,__PYX_ERR(0, 1643, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1640
 *     rwork = np.empty(8*N, dtype = np.float32)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1645
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
  __Pyx_TraceLine(1645,0,__PYX_ERR(0, 1645, __pyx_L1_error))
  /*else*/ {
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1645, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1646
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __Pyx_TraceLine(1646,0,__PYX_ERR(0, 1646, __pyx_L1_error))
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1647
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __Pyx_TraceLine(1647,0,__PYX_ERR(0, 1647, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1649
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data
 */
  __Pyx_TraceLine(1649,0,__PYX_ERR(0, 1649, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1649, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1650
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <float complex *>vsr.data
 *         jobvsr = "V"
 */
    __Pyx_TraceLine(1650,0,__PYX_ERR(0, 1650, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1650, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1650, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 1650, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1650, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1650, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1651
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __Pyx_TraceLine(1651,0,__PYX_ERR(0, 1651, __pyx_L1_error))
    __pyx_v_vsr_ptr = ((__pyx_t_float_complex *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1652
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __Pyx_TraceLine(1652,0,__PYX_ERR(0, 1652, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1649
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1654
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
  __Pyx_TraceLine(1654,0,__PYX_ERR(0, 1654, __pyx_L1_error))
  /*else*/ {
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1654, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1655
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __Pyx_TraceLine(1655,0,__PYX_ERR(0, 1655, __pyx_L1_error))
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1656
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1656,0,__PYX_ERR(0, 1656, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1659
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.cgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <float complex *>A.data, &N,
 */
  __Pyx_TraceLine(1659,0,__PYX_ERR(0, 1659, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1660
 *     # workspace query
 *     lwork = -1
 *     f_lapack.cgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <float complex *>A.data, &N,
 *                     <float complex *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1660,0,__PYX_ERR(0, 1660, __pyx_L1_error))
  cgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1667
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(1667,0,__PYX_ERR(0, 1667, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1667, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1669
 *     assert info == 0, "Argument error in zgees"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex64)
 * 
 */
  __Pyx_TraceLine(1669,0,__PYX_ERR(0, 1669, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1670
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1670,0,__PYX_ERR(0, 1670, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1670, __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, 1670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1670, __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, 1670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1670, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_complex64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1670, __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, 1670, __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, 1670, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1670, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1670, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1673
 * 
 *     # Now the real calculation
 *     f_lapack.cgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <float complex *>A.data, &N,
 *                     <float complex *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1673,0,__PYX_ERR(0, 1673, __pyx_L1_error))
  cgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((float *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1681
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cgges")
 * 
 */
  __Pyx_TraceLine(1681,0,__PYX_ERR(0, 1681, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":1682
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __Pyx_TraceLine(1682,0,__PYX_ERR(0, 1682, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1682, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1682, __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, 1682, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1681
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cgges")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1684
 *         raise LinAlgError("QZ iteration failed to converge in cgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
  __Pyx_TraceLine(1684,0,__PYX_ERR(0, 1684, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1684, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1686
 *     assert info == 0, "Argument error in zgees"
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1686,0,__PYX_ERR(0, 1686, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 1, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1687
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1687,0,__PYX_ERR(0, 1687, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1687, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1686, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1686, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1620
 * 
 * 
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.cgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vsl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vsr);
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1690
 * 
 * 
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_71zgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_71zgges = {"zgges", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_71zgges, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_71zgges(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_A = 0;
  PyArrayObject *__pyx_v_B = 0;
  PyObject *__pyx_v_calc_q = 0;
  PyObject *__pyx_v_calc_z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zgges (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_A,&__pyx_n_s_B,&__pyx_n_s_calc_q,&__pyx_n_s_calc_z,&__pyx_n_s_calc_ev,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1692
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, lwork, sdim, info
 *     cdef char *jobvsl
 */
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_True);
    values[4] = ((PyObject *)Py_True);
    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_A)) != 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_B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgges", 0, 2, 5, 1); __PYX_ERR(0, 1690, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_q);
          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_calc_z);
          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_calc_ev);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zgges") < 0)) __PYX_ERR(0, 1690, __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);
        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_A = ((PyArrayObject *)values[0]);
    __pyx_v_B = ((PyArrayObject *)values[1]);
    __pyx_v_calc_q = values[2];
    __pyx_v_calc_z = values[3];
    __pyx_v_calc_ev = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zgges", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1690, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.zgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_A), __pyx_ptype_5numpy_ndarray, 1, "A", 0))) __PYX_ERR(0, 1690, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) __PYX_ERR(0, 1691, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_70zgges(__pyx_self, __pyx_v_A, __pyx_v_B, __pyx_v_calc_q, __pyx_v_calc_z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1690
 * 
 * 
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_70zgges(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_A, PyArrayObject *__pyx_v_B, PyObject *__pyx_v_calc_q, PyObject *__pyx_v_calc_z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_sdim;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  char *__pyx_v_jobvsl;
  char *__pyx_v_jobvsr;
  __pyx_t_double_complex *__pyx_v_vsl_ptr;
  __pyx_t_double_complex *__pyx_v_vsr_ptr;
  __pyx_t_double_complex __pyx_v_qwork;
  PyArrayObject *__pyx_v_vsl = 0;
  PyArrayObject *__pyx_v_vsr = 0;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_A;
  __Pyx_Buffer __pyx_pybuffer_A;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_B;
  __Pyx_Buffer __pyx_pybuffer_B;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsl;
  __Pyx_Buffer __pyx_pybuffer_vsl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vsr;
  __Pyx_Buffer __pyx_pybuffer_vsr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__78)
  __Pyx_RefNannySetupContext("zgges", 0);
  __Pyx_TraceCall("zgges", __pyx_f[0], 1690, 0, __PYX_ERR(0, 1690, __pyx_L1_error));
  __pyx_pybuffer_vsl.pybuffer.buf = NULL;
  __pyx_pybuffer_vsl.refcount = 0;
  __pyx_pybuffernd_vsl.data = NULL;
  __pyx_pybuffernd_vsl.rcbuffer = &__pyx_pybuffer_vsl;
  __pyx_pybuffer_vsr.pybuffer.buf = NULL;
  __pyx_pybuffer_vsr.refcount = 0;
  __pyx_pybuffernd_vsr.data = NULL;
  __pyx_pybuffernd_vsr.rcbuffer = &__pyx_pybuffer_vsr;
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_A.pybuffer.buf = NULL;
  __pyx_pybuffer_A.refcount = 0;
  __pyx_pybuffernd_A.data = NULL;
  __pyx_pybuffernd_A.rcbuffer = &__pyx_pybuffer_A;
  __pyx_pybuffer_B.pybuffer.buf = NULL;
  __pyx_pybuffer_B.refcount = 0;
  __pyx_pybuffernd_B.data = NULL;
  __pyx_pybuffernd_B.rcbuffer = &__pyx_pybuffer_B;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_A.rcbuffer->pybuffer, (PyObject*)__pyx_v_A, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1690, __pyx_L1_error)
  }
  __pyx_pybuffernd_A.diminfo[0].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_A.diminfo[0].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_A.diminfo[1].strides = __pyx_pybuffernd_A.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_A.diminfo[1].shape = __pyx_pybuffernd_A.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_B.rcbuffer->pybuffer, (PyObject*)__pyx_v_B, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1690, __pyx_L1_error)
  }
  __pyx_pybuffernd_B.diminfo[0].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_B.diminfo[0].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_B.diminfo[1].strides = __pyx_pybuffernd_B.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_B.diminfo[1].shape = __pyx_pybuffernd_B.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1703
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __Pyx_TraceLine(1703,0,__PYX_ERR(0, 1703, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1703, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_A), ((PyObject *)__pyx_v_B)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1703, __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(((PyObject *)__pyx_v_A));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_A));
    __Pyx_INCREF(((PyObject *)__pyx_v_B));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_B));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1705
 *     assert_fortran_mat(A, B)
 * 
 *     N = A.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 */
  __Pyx_TraceLine(1705,0,__PYX_ERR(0, 1705, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_A->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1706
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex128)
 *     rwork = np.empty(8*N, dtype = np.float64)
 */
  __Pyx_TraceLine(1706,0,__PYX_ERR(0, 1706, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1706, __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, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1706, __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, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1706, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1706, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1707
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(8*N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(1707,0,__PYX_ERR(0, 1707, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1707, __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, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1707, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1707, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1707, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1708
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 *     rwork = np.empty(8*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __Pyx_TraceLine(1708,0,__PYX_ERR(0, 1708, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_long((8 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1708, __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, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1708, __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, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1708, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1708, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1708, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1708, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1710
 *     rwork = np.empty(8*N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data
 */
  __Pyx_TraceLine(1710,0,__PYX_ERR(0, 1710, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1710, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1711
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <double complex *>vsl.data
 *         jobvsl = "V"
 */
    __Pyx_TraceLine(1711,0,__PYX_ERR(0, 1711, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1711, __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, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1711, __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_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1711, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1711, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __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_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1711, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1711, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1712
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __Pyx_TraceLine(1712,0,__PYX_ERR(0, 1712, __pyx_L1_error))
    __pyx_v_vsl_ptr = ((__pyx_t_double_complex *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1713
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __Pyx_TraceLine(1713,0,__PYX_ERR(0, 1713, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1710
 *     rwork = np.empty(8*N, dtype = np.float64)
 * 
 *     if calc_q:             # <<<<<<<<<<<<<<
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1715
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
  __Pyx_TraceLine(1715,0,__PYX_ERR(0, 1715, __pyx_L1_error))
  /*else*/ {
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsl.diminfo[0].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsl.diminfo[0].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsl.diminfo[1].strides = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsl.diminfo[1].shape = __pyx_pybuffernd_vsl.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1715, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1716
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __Pyx_TraceLine(1716,0,__PYX_ERR(0, 1716, __pyx_L1_error))
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1717
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __Pyx_TraceLine(1717,0,__PYX_ERR(0, 1717, __pyx_L1_error))
    __pyx_v_jobvsl = ((char *)"N");
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1719
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data
 */
  __Pyx_TraceLine(1719,0,__PYX_ERR(0, 1719, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1719, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1720
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <double complex *>vsr.data
 *         jobvsr = "V"
 */
    __Pyx_TraceLine(1720,0,__PYX_ERR(0, 1720, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1720, __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); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1720, __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_5);
    PyTuple_SET_ITEM(__pyx_t_3, 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, 1720, __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(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex128); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 1720, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1720, __pyx_L1_error)
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1720, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1721
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __Pyx_TraceLine(1721,0,__PYX_ERR(0, 1721, __pyx_L1_error))
    __pyx_v_vsr_ptr = ((__pyx_t_double_complex *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1722
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __Pyx_TraceLine(1722,0,__PYX_ERR(0, 1722, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"V");

    /* "kwant/linalg/lapack.pyx":1719
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1724
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
  __Pyx_TraceLine(1724,0,__PYX_ERR(0, 1724, __pyx_L1_error))
  /*else*/ {
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vsr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
        __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
      }
      __pyx_pybuffernd_vsr.diminfo[0].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vsr.diminfo[0].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vsr.diminfo[1].strides = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vsr.diminfo[1].shape = __pyx_pybuffernd_vsr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1724, __pyx_L1_error)
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1725
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __Pyx_TraceLine(1725,0,__PYX_ERR(0, 1725, __pyx_L1_error))
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1726
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1726,0,__PYX_ERR(0, 1726, __pyx_L1_error))
    __pyx_v_jobvsr = ((char *)"N");
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1729
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.zgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <double complex *>A.data, &N,
 */
  __Pyx_TraceLine(1729,0,__PYX_ERR(0, 1729, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1730
 *     # workspace query
 *     lwork = -1
 *     f_lapack.zgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <double complex *>A.data, &N,
 *                     <double complex *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1730,0,__PYX_ERR(0, 1730, __pyx_L1_error))
  zgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), (&__pyx_v_qwork), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1737
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(1737,0,__PYX_ERR(0, 1737, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1737, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1739
 *     assert info == 0, "Argument error in zgees"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 * 
 */
  __Pyx_TraceLine(1739,0,__PYX_ERR(0, 1739, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1740
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1740,0,__PYX_ERR(0, 1740, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1740, __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, 1740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1740, __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, 1740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_complex128); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1740, __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, 1740, __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, 1740, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1740, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1740, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1743
 * 
 *     # Now the real calculation
 *     f_lapack.zgges_(jobvsl, jobvsr, "N", NULL,             # <<<<<<<<<<<<<<
 *                     &N, <double complex *>A.data, &N,
 *                     <double complex *>B.data, &N, &sdim,
 */
  __Pyx_TraceLine(1743,0,__PYX_ERR(0, 1743, __pyx_L1_error))
  zgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, ((char *)"N"), NULL, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_A->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_B->data), (&__pyx_v_N), (&__pyx_v_sdim), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_vsl_ptr, (&__pyx_v_N), __pyx_v_vsr_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((double *)__pyx_v_rwork->data), NULL, (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1751
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zgges")
 * 
 */
  __Pyx_TraceLine(1751,0,__PYX_ERR(0, 1751, __pyx_L1_error))
  __pyx_t_12 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_12)) {

    /* "kwant/linalg/lapack.pyx":1752
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __Pyx_TraceLine(1752,0,__PYX_ERR(0, 1752, __pyx_L1_error))
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1752, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1752, __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, 1752, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1751
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zgges")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1754
 *         raise LinAlgError("QZ iteration failed to converge in zgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
  __Pyx_TraceLine(1754,0,__PYX_ERR(0, 1754, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_zgees);
      __PYX_ERR(0, 1754, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1756
 *     assert info == 0, "Argument error in zgees"
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1756,0,__PYX_ERR(0, 1756, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_5, 1, Py_True);
  __Pyx_INCREF(__pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1757
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1757,0,__PYX_ERR(0, 1757, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_6 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1690
 * 
 * 
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.zgges", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_A.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_B.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vsl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vsr);
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1761
 * 
 * # wrappers for xTGSEN
 * def stgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_73stgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_73stgsen = {"stgsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_73stgsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_73stgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stgsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_calc_ev,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1764
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Z=None,
 *            calc_ev=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1765
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[np.float32_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1766
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[np.float32_t, ndim=2] Z=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 *     cdef l_logical wantq, wantz
 */
    values[5] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_select)) != 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_S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgsen", 0, 3, 6, 1); __PYX_ERR(0, 1761, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgsen", 0, 3, 6, 2); __PYX_ERR(0, 1761, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_ev);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "stgsen") < 0)) __PYX_ERR(0, 1761, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_select = ((PyArrayObject *)values[0]);
    __pyx_v_S = ((PyArrayObject *)values[1]);
    __pyx_v_T = ((PyArrayObject *)values[2]);
    __pyx_v_Q = ((PyArrayObject *)values[3]);
    __pyx_v_Z = ((PyArrayObject *)values[4]);
    __pyx_v_calc_ev = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stgsen", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1761, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.stgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1761, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 1762, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1763, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1764, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 1765, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_72stgsen(__pyx_self, __pyx_v_select, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1761
 * 
 * # wrappers for xTGSEN
 * def stgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_72stgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_ijob;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantq;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantz;
  float __pyx_v_qwork;
  float *__pyx_v_q_ptr;
  float *__pyx_v_z_ptr;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  PyObject *__pyx_v_alpha = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__80)
  __Pyx_RefNannySetupContext("stgsen", 0);
  __Pyx_TraceCall("stgsen", __pyx_f[0], 1761, 0, __PYX_ERR(0, 1761, __pyx_L1_error));
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1775
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(1775,0,__PYX_ERR(0, 1775, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1775, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1775, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1775, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1775, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1777
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(1777,0,__PYX_ERR(0, 1777, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1778
 * 
 *     N = S.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)
 */
  __Pyx_TraceLine(1778,0,__PYX_ERR(0, 1778, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1778, __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, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1778, __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, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1778, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1778, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1778, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1779
 *     N = S.shape[0]
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float32)
 *     ijob = 0
 */
  __Pyx_TraceLine(1779,0,__PYX_ERR(0, 1779, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1779, __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, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1779, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1779, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1779, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1779, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1780
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __Pyx_TraceLine(1780,0,__PYX_ERR(0, 1780, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1780, __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, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1780, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1780, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1781
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(1781,0,__PYX_ERR(0, 1781, __pyx_L1_error))
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1783
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float *>Q.data
 */
  __Pyx_TraceLine(1783,0,__PYX_ERR(0, 1783, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1784
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <float *>Q.data
 *     else:
 */
    __Pyx_TraceLine(1784,0,__PYX_ERR(0, 1784, __pyx_L1_error))
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1785
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <float *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __Pyx_TraceLine(1785,0,__PYX_ERR(0, 1785, __pyx_L1_error))
    __pyx_v_q_ptr = ((float *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":1783
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1787
 *         q_ptr = <float *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1787,0,__PYX_ERR(0, 1787, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1788
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __Pyx_TraceLine(1788,0,__PYX_ERR(0, 1788, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1790
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float *>Z.data
 */
  __Pyx_TraceLine(1790,0,__PYX_ERR(0, 1790, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_11 = (__pyx_t_12 != 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1791
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <float *>Z.data
 *     else:
 */
    __Pyx_TraceLine(1791,0,__PYX_ERR(0, 1791, __pyx_L1_error))
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1792
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <float *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __Pyx_TraceLine(1792,0,__PYX_ERR(0, 1792, __pyx_L1_error))
    __pyx_v_z_ptr = ((float *)__pyx_v_Z->data);

    /* "kwant/linalg/lapack.pyx":1790
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float *>Z.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1794
 *         z_ptr = <float *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1794,0,__PYX_ERR(0, 1794, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1795
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1795,0,__PYX_ERR(0, 1795, __pyx_L1_error))
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1798
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __Pyx_TraceLine(1798,0,__PYX_ERR(0, 1798, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1799
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <float *>S.data, &N,
 */
  __Pyx_TraceLine(1799,0,__PYX_ERR(0, 1799, __pyx_L1_error))
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1800
 *     lwork = -1
 *     liwork = -1
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float *>S.data, &N,
 *                      <float *>T.data, &N,
 */
  __Pyx_TraceLine(1800,0,__PYX_ERR(0, 1800, __pyx_L1_error))
  stgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((float *)__pyx_v_S->data), (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1808
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in stgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(1808,0,__PYX_ERR(0, 1808, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_stgsen);
      __PYX_ERR(0, 1808, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1810
 *     assert info == 0, "Argument error in stgsen"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(1810,0,__PYX_ERR(0, 1810, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":1811
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __Pyx_TraceLine(1811,0,__PYX_ERR(0, 1811, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1811, __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, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1811, __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, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1811, __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, 1811, __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, 1811, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1811, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1811, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1812
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __Pyx_TraceLine(1812,0,__PYX_ERR(0, 1812, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1813
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1813,0,__PYX_ERR(0, 1813, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __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, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1813, __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, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1813, __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_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __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_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1813, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1813, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1816
 * 
 *     # Now the real calculation
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float *>S.data, &N,
 *                      <float *>T.data, &N,
 */
  __Pyx_TraceLine(1816,0,__PYX_ERR(0, 1816, __pyx_L1_error))
  stgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((float *)__pyx_v_S->data), (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), ((float *)__pyx_v_alphar->data), ((float *)__pyx_v_alphai->data), ((float *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, ((float *)__pyx_v_work->data), (&__pyx_v_lwork), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1825
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(1825,0,__PYX_ERR(0, 1825, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":1826
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgsen"
 */
    __Pyx_TraceLine(1826,0,__PYX_ERR(0, 1826, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1826, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1826, __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(0, 1826, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1825
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1828
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in stgsen"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  __Pyx_TraceLine(1828,0,__PYX_ERR(0, 1828, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_stgsen);
      __PYX_ERR(0, 1828, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1830
 *     assert info == 0, "Argument error in stgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __Pyx_TraceLine(1830,0,__PYX_ERR(0, 1830, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1830, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1830, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1830, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1831
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __Pyx_TraceLine(1831,0,__PYX_ERR(0, 1831, __pyx_L1_error))
    __pyx_t_1 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_alpha = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1830
 *     assert info == 0, "Argument error in stgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1833
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
  __Pyx_TraceLine(1833,0,__PYX_ERR(0, 1833, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1835
 *         alpha = alphar
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,             # <<<<<<<<<<<<<<
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))
 */
  __Pyx_TraceLine(1835,0,__PYX_ERR(0, 1835, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1835, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1835, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1835, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "kwant/linalg/lapack.pyx":1836
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1836,0,__PYX_ERR(0, 1836, __pyx_L1_error))
  __pyx_t_6 = PyTuple_New(6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1835, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 1, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_6, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_6, 5, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1837
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1837,0,__PYX_ERR(0, 1837, __pyx_L1_error))
  __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1837, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_2);
    __pyx_t_6 = 0;
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1761
 * 
 * # wrappers for xTGSEN
 * def stgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.stgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1840
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_75dtgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_75dtgsen = {"dtgsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_75dtgsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_75dtgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dtgsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_calc_ev,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1843
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Z=None,
 *            calc_ev=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1844
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[np.float64_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1845
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[np.float64_t, ndim=2] Z=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 *     cdef l_logical wantq, wantz
 */
    values[5] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_select)) != 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_S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgsen", 0, 3, 6, 1); __PYX_ERR(0, 1840, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgsen", 0, 3, 6, 2); __PYX_ERR(0, 1840, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_ev);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dtgsen") < 0)) __PYX_ERR(0, 1840, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_select = ((PyArrayObject *)values[0]);
    __pyx_v_S = ((PyArrayObject *)values[1]);
    __pyx_v_T = ((PyArrayObject *)values[2]);
    __pyx_v_Q = ((PyArrayObject *)values[3]);
    __pyx_v_Z = ((PyArrayObject *)values[4]);
    __pyx_v_calc_ev = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dtgsen", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1840, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dtgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1840, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 1841, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1842, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1843, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 1844, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_74dtgsen(__pyx_self, __pyx_v_select, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1840
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_74dtgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_ijob;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantq;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantz;
  double __pyx_v_qwork;
  double *__pyx_v_q_ptr;
  double *__pyx_v_z_ptr;
  PyArrayObject *__pyx_v_alphar = 0;
  PyArrayObject *__pyx_v_alphai = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  PyObject *__pyx_v_alpha = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphai;
  __Pyx_Buffer __pyx_pybuffer_alphai;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alphar;
  __Pyx_Buffer __pyx_pybuffer_alphar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__82)
  __Pyx_RefNannySetupContext("dtgsen", 0);
  __Pyx_TraceCall("dtgsen", __pyx_f[0], 1840, 0, __PYX_ERR(0, 1840, __pyx_L1_error));
  __pyx_pybuffer_alphar.pybuffer.buf = NULL;
  __pyx_pybuffer_alphar.refcount = 0;
  __pyx_pybuffernd_alphar.data = NULL;
  __pyx_pybuffernd_alphar.rcbuffer = &__pyx_pybuffer_alphar;
  __pyx_pybuffer_alphai.pybuffer.buf = NULL;
  __pyx_pybuffer_alphai.refcount = 0;
  __pyx_pybuffernd_alphai.data = NULL;
  __pyx_pybuffernd_alphai.rcbuffer = &__pyx_pybuffer_alphai;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1840, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1840, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1840, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1840, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1840, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1854
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(1854,0,__PYX_ERR(0, 1854, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1854, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1854, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1854, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1854, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1854, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1856
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(1856,0,__PYX_ERR(0, 1856, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1857
 * 
 *     N = S.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)
 */
  __Pyx_TraceLine(1857,0,__PYX_ERR(0, 1857, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1857, __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, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1857, __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, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1857, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphar, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alphar.diminfo[0].strides = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphar.diminfo[0].shape = __pyx_pybuffernd_alphar.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1857, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1858
 *     N = S.shape[0]
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.float64)
 *     ijob = 0
 */
  __Pyx_TraceLine(1858,0,__PYX_ERR(0, 1858, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1858, __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, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1858, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1858, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1858, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1858, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer, (PyObject*)__pyx_v_alphai, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_alphai.diminfo[0].strides = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alphai.diminfo[0].shape = __pyx_pybuffernd_alphai.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1858, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1859
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __Pyx_TraceLine(1859,0,__PYX_ERR(0, 1859, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1859, __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, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1859, __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, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1859, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1859, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1860
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(1860,0,__PYX_ERR(0, 1860, __pyx_L1_error))
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1862
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double *>Q.data
 */
  __Pyx_TraceLine(1862,0,__PYX_ERR(0, 1862, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1863
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <double *>Q.data
 *     else:
 */
    __Pyx_TraceLine(1863,0,__PYX_ERR(0, 1863, __pyx_L1_error))
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1864
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <double *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __Pyx_TraceLine(1864,0,__PYX_ERR(0, 1864, __pyx_L1_error))
    __pyx_v_q_ptr = ((double *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":1862
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1866
 *         q_ptr = <double *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1866,0,__PYX_ERR(0, 1866, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1867
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __Pyx_TraceLine(1867,0,__PYX_ERR(0, 1867, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1869
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double *>Z.data
 */
  __Pyx_TraceLine(1869,0,__PYX_ERR(0, 1869, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_11 = (__pyx_t_12 != 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1870
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <double *>Z.data
 *     else:
 */
    __Pyx_TraceLine(1870,0,__PYX_ERR(0, 1870, __pyx_L1_error))
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1871
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <double *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __Pyx_TraceLine(1871,0,__PYX_ERR(0, 1871, __pyx_L1_error))
    __pyx_v_z_ptr = ((double *)__pyx_v_Z->data);

    /* "kwant/linalg/lapack.pyx":1869
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double *>Z.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1873
 *         z_ptr = <double *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1873,0,__PYX_ERR(0, 1873, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1874
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1874,0,__PYX_ERR(0, 1874, __pyx_L1_error))
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1877
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __Pyx_TraceLine(1877,0,__PYX_ERR(0, 1877, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1878
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <double *>S.data, &N,
 */
  __Pyx_TraceLine(1878,0,__PYX_ERR(0, 1878, __pyx_L1_error))
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1879
 *     lwork = -1
 *     liwork = -1
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double *>S.data, &N,
 *                      <double *>T.data, &N,
 */
  __Pyx_TraceLine(1879,0,__PYX_ERR(0, 1879, __pyx_L1_error))
  dtgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((double *)__pyx_v_S->data), (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1887
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in dtgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  __Pyx_TraceLine(1887,0,__PYX_ERR(0, 1887, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtgsen);
      __PYX_ERR(0, 1887, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1889
 *     assert info == 0, "Argument error in dtgsen"
 * 
 *     lwork = <int>qwork             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(1889,0,__PYX_ERR(0, 1889, __pyx_L1_error))
  __pyx_v_lwork = ((int)__pyx_v_qwork);

  /* "kwant/linalg/lapack.pyx":1890
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __Pyx_TraceLine(1890,0,__PYX_ERR(0, 1890, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1890, __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, 1890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1890, __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, 1890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1890, __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, 1890, __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, 1890, __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1890, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1890, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1891
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __Pyx_TraceLine(1891,0,__PYX_ERR(0, 1891, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1892
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1892,0,__PYX_ERR(0, 1892, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1892, __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, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1892, __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, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1892, __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_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1892, __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_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1892, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1892, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1895
 * 
 *     # Now the real calculation
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double *>S.data, &N,
 *                      <double *>T.data, &N,
 */
  __Pyx_TraceLine(1895,0,__PYX_ERR(0, 1895, __pyx_L1_error))
  dtgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((double *)__pyx_v_S->data), (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), ((double *)__pyx_v_alphar->data), ((double *)__pyx_v_alphai->data), ((double *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, ((double *)__pyx_v_work->data), (&__pyx_v_lwork), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1904
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(1904,0,__PYX_ERR(0, 1904, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":1905
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgsen"
 */
    __Pyx_TraceLine(1905,0,__PYX_ERR(0, 1905, __pyx_L1_error))
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1905, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1905, __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(0, 1905, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1904
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1907
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in dtgsen"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  __Pyx_TraceLine(1907,0,__PYX_ERR(0, 1907, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtgsen);
      __PYX_ERR(0, 1907, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1909
 *     assert info == 0, "Argument error in dtgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __Pyx_TraceLine(1909,0,__PYX_ERR(0, 1909, __pyx_L1_error))
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1909, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1909, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1909, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1909, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1910
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __Pyx_TraceLine(1910,0,__PYX_ERR(0, 1910, __pyx_L1_error))
    __pyx_t_1 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_alpha = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":1909
 *     assert info == 0, "Argument error in dtgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":1912
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
  __Pyx_TraceLine(1912,0,__PYX_ERR(0, 1912, __pyx_L1_error))
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1914
 *         alpha = alphar
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,             # <<<<<<<<<<<<<<
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))
 */
  __Pyx_TraceLine(1914,0,__PYX_ERR(0, 1914, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "kwant/linalg/lapack.pyx":1915
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1915,0,__PYX_ERR(0, 1915, __pyx_L1_error))
  __pyx_t_6 = PyTuple_New(6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_6, 1, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_6, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_6, 5, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1916
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1916,0,__PYX_ERR(0, 1916, __pyx_L1_error))
  __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1916, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(__pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1914, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1914, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_2);
    __pyx_t_6 = 0;
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1840
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dtgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_alphar);
  __Pyx_XDECREF((PyObject *)__pyx_v_alphai);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XDECREF(__pyx_v_alpha);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1919
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_77ctgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_77ctgsen = {"ctgsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_77ctgsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_77ctgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ctgsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_calc_ev,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1922
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,
 *            calc_ev=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1923
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1924
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 *     cdef l_logical wantq, wantz
 */
    values[5] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_select)) != 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_S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgsen", 0, 3, 6, 1); __PYX_ERR(0, 1919, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgsen", 0, 3, 6, 2); __PYX_ERR(0, 1919, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_ev);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ctgsen") < 0)) __PYX_ERR(0, 1919, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_select = ((PyArrayObject *)values[0]);
    __pyx_v_S = ((PyArrayObject *)values[1]);
    __pyx_v_T = ((PyArrayObject *)values[2]);
    __pyx_v_Q = ((PyArrayObject *)values[3]);
    __pyx_v_Z = ((PyArrayObject *)values[4]);
    __pyx_v_calc_ev = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ctgsen", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1919, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ctgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1919, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 1920, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1921, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1922, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 1923, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_76ctgsen(__pyx_self, __pyx_v_select, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1919
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_76ctgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_ijob;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantq;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantz;
  __pyx_t_float_complex __pyx_v_qwork;
  __pyx_t_float_complex *__pyx_v_q_ptr;
  __pyx_t_float_complex *__pyx_v_z_ptr;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__84)
  __Pyx_RefNannySetupContext("ctgsen", 0);
  __Pyx_TraceCall("ctgsen", __pyx_f[0], 1919, 0, __PYX_ERR(0, 1919, __pyx_L1_error));
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1919, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1919, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1919, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1919, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1919, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":1933
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(1933,0,__PYX_ERR(0, 1933, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1933, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1935
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 */
  __Pyx_TraceLine(1935,0,__PYX_ERR(0, 1935, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1936
 * 
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex64)
 *     ijob = 0
 */
  __Pyx_TraceLine(1936,0,__PYX_ERR(0, 1936, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1936, __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, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1936, __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, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1936, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1936, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1937
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __Pyx_TraceLine(1937,0,__PYX_ERR(0, 1937, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1937, __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, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1937, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1937, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1937, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1937, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1937, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1938
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(1938,0,__PYX_ERR(0, 1938, __pyx_L1_error))
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1940
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float complex *>Q.data
 */
  __Pyx_TraceLine(1940,0,__PYX_ERR(0, 1940, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1941
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <float complex *>Q.data
 *     else:
 */
    __Pyx_TraceLine(1941,0,__PYX_ERR(0, 1941, __pyx_L1_error))
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1942
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <float complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __Pyx_TraceLine(1942,0,__PYX_ERR(0, 1942, __pyx_L1_error))
    __pyx_v_q_ptr = ((__pyx_t_float_complex *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":1940
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float complex *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1944
 *         q_ptr = <float complex *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1944,0,__PYX_ERR(0, 1944, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1945
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __Pyx_TraceLine(1945,0,__PYX_ERR(0, 1945, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1947
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float complex *>Z.data
 */
  __Pyx_TraceLine(1947,0,__PYX_ERR(0, 1947, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_11 = (__pyx_t_12 != 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1948
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <float complex *>Z.data
 *     else:
 */
    __Pyx_TraceLine(1948,0,__PYX_ERR(0, 1948, __pyx_L1_error))
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1949
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <float complex *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __Pyx_TraceLine(1949,0,__PYX_ERR(0, 1949, __pyx_L1_error))
    __pyx_v_z_ptr = ((__pyx_t_float_complex *)__pyx_v_Z->data);

    /* "kwant/linalg/lapack.pyx":1947
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float complex *>Z.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":1951
 *         z_ptr = <float complex *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
  __Pyx_TraceLine(1951,0,__PYX_ERR(0, 1951, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1952
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(1952,0,__PYX_ERR(0, 1952, __pyx_L1_error))
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1955
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __Pyx_TraceLine(1955,0,__PYX_ERR(0, 1955, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1956
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <float complex *>S.data, &N,
 */
  __Pyx_TraceLine(1956,0,__PYX_ERR(0, 1956, __pyx_L1_error))
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1957
 *     lwork = -1
 *     liwork = -1
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>S.data, &N,
 *                      <float complex *>T.data, &N,
 */
  __Pyx_TraceLine(1957,0,__PYX_ERR(0, 1957, __pyx_L1_error))
  ctgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1964
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in ctgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(1964,0,__PYX_ERR(0, 1964, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctgsen);
      __PYX_ERR(0, 1964, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1966
 *     assert info == 0, "Argument error in ctgsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(1966,0,__PYX_ERR(0, 1966, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1967
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __Pyx_TraceLine(1967,0,__PYX_ERR(0, 1967, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1967, __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, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1967, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1967, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1968
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __Pyx_TraceLine(1968,0,__PYX_ERR(0, 1968, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1969
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(1969,0,__PYX_ERR(0, 1969, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1969, __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, 1969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1969, __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, 1969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1969, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 1969, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1969, __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_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1969, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1969, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":1972
 * 
 *     # Now the real calculation
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>S.data, &N,
 *                      <float complex *>T.data, &N,
 */
  __Pyx_TraceLine(1972,0,__PYX_ERR(0, 1972, __pyx_L1_error))
  ctgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_alpha->data), ((__pyx_t_float_complex *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, ((__pyx_t_float_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":1980
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(1980,0,__PYX_ERR(0, 1980, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":1981
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgsen"
 */
    __Pyx_TraceLine(1981,0,__PYX_ERR(0, 1981, __pyx_L1_error))
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1981, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__85, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1981, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1981, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":1980
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":1983
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in ctgsen"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
  __Pyx_TraceLine(1983,0,__PYX_ERR(0, 1983, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctgsen);
      __PYX_ERR(0, 1983, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1985
 *     assert info == 0, "Argument error in ctgsen"
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,             # <<<<<<<<<<<<<<
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))
 */
  __Pyx_TraceLine(1985,0,__PYX_ERR(0, 1985, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "kwant/linalg/lapack.pyx":1986
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __Pyx_TraceLine(1986,0,__PYX_ERR(0, 1986, __pyx_L1_error))
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 1, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1987
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(1987,0,__PYX_ERR(0, 1987, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1987, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1985, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1985, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1985, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1985, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1919
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ctgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1990
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_79ztgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_79ztgsen = {"ztgsen", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_79ztgsen, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_79ztgsen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_select = 0;
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyObject *__pyx_v_calc_ev = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ztgsen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_select,&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_calc_ev,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":1993
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,
 *            calc_ev=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1994
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            calc_ev=True):
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1995
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,
 *            calc_ev=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, M, lwork, liwork, qiwork, info, ijob
 *     cdef l_logical wantq, wantz
 */
    values[5] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_select)) != 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_S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgsen", 0, 3, 6, 1); __PYX_ERR(0, 1990, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgsen", 0, 3, 6, 2); __PYX_ERR(0, 1990, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_calc_ev);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ztgsen") < 0)) __PYX_ERR(0, 1990, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_select = ((PyArrayObject *)values[0]);
    __pyx_v_S = ((PyArrayObject *)values[1]);
    __pyx_v_T = ((PyArrayObject *)values[2]);
    __pyx_v_Q = ((PyArrayObject *)values[3]);
    __pyx_v_Z = ((PyArrayObject *)values[4]);
    __pyx_v_calc_ev = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ztgsen", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1990, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ztgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 1990, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 1991, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 1992, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 1993, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 1994, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_78ztgsen(__pyx_self, __pyx_v_select, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_calc_ev);

  /* "kwant/linalg/lapack.pyx":1990
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_78ztgsen(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_select, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyObject *__pyx_v_calc_ev) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_lwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_liwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_qiwork;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_ijob;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantq;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical __pyx_v_wantz;
  __pyx_t_double_complex __pyx_v_qwork;
  __pyx_t_double_complex *__pyx_v_q_ptr;
  __pyx_t_double_complex *__pyx_v_z_ptr;
  PyArrayObject *__pyx_v_alpha = 0;
  PyArrayObject *__pyx_v_beta = 0;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_iwork = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_alpha;
  __Pyx_Buffer __pyx_pybuffer_alpha;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_beta;
  __Pyx_Buffer __pyx_pybuffer_beta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_iwork;
  __Pyx_Buffer __pyx_pybuffer_iwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyArrayObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__86)
  __Pyx_RefNannySetupContext("ztgsen", 0);
  __Pyx_TraceCall("ztgsen", __pyx_f[0], 1990, 0, __PYX_ERR(0, 1990, __pyx_L1_error));
  __pyx_pybuffer_alpha.pybuffer.buf = NULL;
  __pyx_pybuffer_alpha.refcount = 0;
  __pyx_pybuffernd_alpha.data = NULL;
  __pyx_pybuffernd_alpha.rcbuffer = &__pyx_pybuffer_alpha;
  __pyx_pybuffer_beta.pybuffer.buf = NULL;
  __pyx_pybuffer_beta.refcount = 0;
  __pyx_pybuffernd_beta.data = NULL;
  __pyx_pybuffernd_beta.rcbuffer = &__pyx_pybuffer_beta;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_iwork.pybuffer.buf = NULL;
  __pyx_pybuffer_iwork.refcount = 0;
  __pyx_pybuffernd_iwork.data = NULL;
  __pyx_pybuffernd_iwork.rcbuffer = &__pyx_pybuffer_iwork;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1990, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1990, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1990, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1990, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 1990, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];

  /* "kwant/linalg/lapack.pyx":2004
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(2004,0,__PYX_ERR(0, 2004, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2004, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2004, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2004, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2004, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2006
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 */
  __Pyx_TraceLine(2006,0,__PYX_ERR(0, 2006, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2007
 * 
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex128)
 *     ijob = 0
 */
  __Pyx_TraceLine(2007,0,__PYX_ERR(0, 2007, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2007, __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, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2007, __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, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2007, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2007, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer, (PyObject*)__pyx_v_alpha, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_alpha.diminfo[0].strides = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_alpha.diminfo[0].shape = __pyx_pybuffernd_alpha.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2007, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2008
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __Pyx_TraceLine(2008,0,__PYX_ERR(0, 2008, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2008, __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, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2008, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2008, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2008, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.rcbuffer->pybuffer, (PyObject*)__pyx_v_beta, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_beta.diminfo[0].strides = __pyx_pybuffernd_beta.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_beta.diminfo[0].shape = __pyx_pybuffernd_beta.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2008, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2009
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __Pyx_TraceLine(2009,0,__PYX_ERR(0, 2009, __pyx_L1_error))
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":2011
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double complex *>Q.data
 */
  __Pyx_TraceLine(2011,0,__PYX_ERR(0, 2011, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2012
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <double complex *>Q.data
 *     else:
 */
    __Pyx_TraceLine(2012,0,__PYX_ERR(0, 2012, __pyx_L1_error))
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":2013
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <double complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __Pyx_TraceLine(2013,0,__PYX_ERR(0, 2013, __pyx_L1_error))
    __pyx_v_q_ptr = ((__pyx_t_double_complex *)__pyx_v_Q->data);

    /* "kwant/linalg/lapack.pyx":2011
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double complex *>Q.data
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2015
 *         q_ptr = <double complex *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
  __Pyx_TraceLine(2015,0,__PYX_ERR(0, 2015, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":2016
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __Pyx_TraceLine(2016,0,__PYX_ERR(0, 2016, __pyx_L1_error))
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2018
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double complex *>Z.data
 */
  __Pyx_TraceLine(2018,0,__PYX_ERR(0, 2018, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_11 = (__pyx_t_12 != 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2019
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <double complex *>Z.data
 *     else:
 */
    __Pyx_TraceLine(2019,0,__PYX_ERR(0, 2019, __pyx_L1_error))
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":2020
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <double complex *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __Pyx_TraceLine(2020,0,__PYX_ERR(0, 2020, __pyx_L1_error))
    __pyx_v_z_ptr = ((__pyx_t_double_complex *)__pyx_v_Z->data);

    /* "kwant/linalg/lapack.pyx":2018
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double complex *>Z.data
 */
    goto __pyx_L4;
  }

  /* "kwant/linalg/lapack.pyx":2022
 *         z_ptr = <double complex *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
  __Pyx_TraceLine(2022,0,__PYX_ERR(0, 2022, __pyx_L1_error))
  /*else*/ {
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":2023
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __Pyx_TraceLine(2023,0,__PYX_ERR(0, 2023, __pyx_L1_error))
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":2026
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __Pyx_TraceLine(2026,0,__PYX_ERR(0, 2026, __pyx_L1_error))
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":2027
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <double complex *>S.data, &N,
 */
  __Pyx_TraceLine(2027,0,__PYX_ERR(0, 2027, __pyx_L1_error))
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":2028
 *     lwork = -1
 *     liwork = -1
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>S.data, &N,
 *                      <double complex *>T.data, &N,
 */
  __Pyx_TraceLine(2028,0,__PYX_ERR(0, 2028, __pyx_L1_error))
  ztgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, (&__pyx_v_qwork), (&__pyx_v_lwork), (&__pyx_v_qiwork), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2035
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in ztgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  __Pyx_TraceLine(2035,0,__PYX_ERR(0, 2035, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztgsen);
      __PYX_ERR(0, 2035, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2037
 *     assert info == 0, "Argument error in ztgsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork
 */
  __Pyx_TraceLine(2037,0,__PYX_ERR(0, 2037, __pyx_L1_error))
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":2038
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __Pyx_TraceLine(2038,0,__PYX_ERR(0, 2038, __pyx_L1_error))
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_lwork); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2038, __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, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex128); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2038, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2038, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2039
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __Pyx_TraceLine(2039,0,__PYX_ERR(0, 2039, __pyx_L1_error))
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":2040
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __Pyx_TraceLine(2040,0,__PYX_ERR(0, 2040, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2040, __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, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2040, __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, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2040, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2040, __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_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2040, __pyx_L1_error)
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_iwork, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_iwork.diminfo[0].strides = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_iwork.diminfo[0].shape = __pyx_pybuffernd_iwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2040, __pyx_L1_error)
  }
  __pyx_t_13 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2043
 * 
 *     # Now the real calculation
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>S.data, &N,
 *                      <double complex *>T.data, &N,
 */
  __Pyx_TraceLine(2043,0,__PYX_ERR(0, 2043, __pyx_L1_error))
  ztgsen_((&__pyx_v_ijob), (&__pyx_v_wantq), (&__pyx_v_wantz), ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_alpha->data), ((__pyx_t_double_complex *)__pyx_v_beta->data), __pyx_v_q_ptr, (&__pyx_v_N), __pyx_v_z_ptr, (&__pyx_v_N), (&__pyx_v_M), NULL, NULL, NULL, ((__pyx_t_double_complex *)__pyx_v_work->data), (&__pyx_v_lwork), ((__pyx_t_5kwant_6linalg_8f_lapack_l_int *)__pyx_v_iwork->data), (&__pyx_v_liwork), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2051
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __Pyx_TraceLine(2051,0,__PYX_ERR(0, 2051, __pyx_L1_error))
  __pyx_t_11 = ((__pyx_v_info > 0) != 0);
  if (unlikely(__pyx_t_11)) {

    /* "kwant/linalg/lapack.pyx":2052
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgsen"
 */
    __Pyx_TraceLine(2052,0,__PYX_ERR(0, 2052, __pyx_L1_error))
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_LinAlgError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2052, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__87, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2052, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2052, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":2051
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  }

  /* "kwant/linalg/lapack.pyx":2054
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in ztgsen"             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
  __Pyx_TraceLine(2054,0,__PYX_ERR(0, 2054, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztgsen);
      __PYX_ERR(0, 2054, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2056
 *     assert info == 0, "Argument error in ztgsen"
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,             # <<<<<<<<<<<<<<
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))
 */
  __Pyx_TraceLine(2056,0,__PYX_ERR(0, 2056, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_filter_args); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "kwant/linalg/lapack.pyx":2057
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __Pyx_TraceLine(2057,0,__PYX_ERR(0, 2057, __pyx_L1_error))
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 0, Py_True);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_1, 1, Py_True);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2058
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(2058,0,__PYX_ERR(0, 2058, __pyx_L1_error))
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_t_3};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_3};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_14 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2056, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_4, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_4, __pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":1990
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_14);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ztgsen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_iwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_alpha);
  __Pyx_XDECREF((PyObject *)__pyx_v_beta);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_iwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2062
 * 
 * # xTGEVC
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_81stgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_81stgevc = {"stgevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_81stgevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_81stgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stgevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":2064
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2065
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[np.float32_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2066
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[np.float32_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2067
 *            np.ndarray[np.float32_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[5] = ((PyObject *)Py_False);
    values[6] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_S)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgevc", 0, 2, 7, 1); __PYX_ERR(0, 2062, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          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_select);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_right);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "stgevc") < 0)) __PYX_ERR(0, 2062, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_S = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_Z = ((PyArrayObject *)values[3]);
    __pyx_v_select = ((PyArrayObject *)values[4]);
    __pyx_v_left = values[5];
    __pyx_v_right = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stgevc", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2062, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.stgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 2062, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 2063, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 2064, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 2065, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 2066, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_80stgevc(__pyx_self, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":2062
 * 
 * # xTGEVC
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_80stgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  float *__pyx_v_vl_r_ptr;
  float *__pyx_v_vr_r_ptr;
  PyArrayObject *__pyx_v_select_cpy = 0;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  int __pyx_v_backtr;
  PyObject *__pyx_v_cmplxindx = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select_cpy;
  __Pyx_Buffer __pyx_pybuffer_select_cpy;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__88)
  __Pyx_RefNannySetupContext("stgevc", 0);
  __Pyx_TraceCall("stgevc", __pyx_f[0], 2062, 0, __PYX_ERR(0, 2062, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_select_cpy.pybuffer.buf = NULL;
  __pyx_pybuffer_select_cpy.refcount = 0;
  __pyx_pybuffernd_select_cpy.data = NULL;
  __pyx_pybuffernd_select_cpy.rcbuffer = &__pyx_pybuffer_select_cpy;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2062, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2062, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2062, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2062, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2062, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":2078
 *     cdef np.ndarray[np.float32_t] work
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(2078,0,__PYX_ERR(0, 2078, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2078, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2078, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2078, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2078, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2080
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(6*N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(2080,0,__PYX_ERR(0, 2080, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2081
 * 
 *     N = S.shape[0]
 *     work = np.empty(6*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(2081,0,__PYX_ERR(0, 2081, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2081, __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, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((6 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2081, __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, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2081, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2081, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2081, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2083
 *     work = np.empty(6*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(2083,0,__PYX_ERR(0, 2083, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2084
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(2084,0,__PYX_ERR(0, 2084, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":2083
 *     work = np.empty(6*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2085
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(2085,0,__PYX_ERR(0, 2085, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2085, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2086
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(2086,0,__PYX_ERR(0, 2086, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":2085
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2087
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(2087,0,__PYX_ERR(0, 2087, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2087, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2088
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(2088,0,__PYX_ERR(0, 2088, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":2087
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2090
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
  __Pyx_TraceLine(2090,0,__PYX_ERR(0, 2090, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2092
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(2092,0,__PYX_ERR(0, 2092, __pyx_L1_error))
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2094
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(2094,0,__PYX_ERR(0, 2094, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2095
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __Pyx_TraceLine(2095,0,__PYX_ERR(0, 2095, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":2096
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         # Correct for possible additional storage if a single complex
 *         # eigenvalue is selected.
 */
    __Pyx_TraceLine(2096,0,__PYX_ERR(0, 2096, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2096, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2096, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2096, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2096, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2096, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2096, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_MM = __pyx_t_13;

    /* "kwant/linalg/lapack.pyx":2100
 *         # eigenvalue is selected.
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]             # <<<<<<<<<<<<<<
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 */
    __Pyx_TraceLine(2100,0,__PYX_ERR(0, 2100, __pyx_L1_error))
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2100, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2100, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_4 = 0;
    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 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2100, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2100, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2100, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
      __Pyx_INCREF(__pyx_int_neg_1);
      __Pyx_GIVEREF(__pyx_int_neg_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_int_neg_1);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2100, __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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2100, __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 && likely(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);
      }
    }
    if (__pyx_t_1) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2100, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2100, __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, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2100, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cmplxindx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":2101
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
    __Pyx_TraceLine(2101,0,__PYX_ERR(0, 2101, __pyx_L1_error))
    if (likely(PyList_CheckExact(__pyx_v_cmplxindx)) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_2 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_2); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
    } else {
      __pyx_t_14 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2101, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_15 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2101, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_15)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2101, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2101, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2101, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2101, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_15(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 2101, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":2102
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __Pyx_TraceLine(2102,0,__PYX_ERR(0, 2102, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_12) {

        /* "kwant/linalg/lapack.pyx":2103
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # select is overwritten in stgevc
 */
        __Pyx_TraceLine(2103,0,__PYX_ERR(0, 2103, __pyx_L1_error))
        __pyx_v_MM = (__pyx_v_MM + 1);

        /* "kwant/linalg/lapack.pyx":2102
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      }

      /* "kwant/linalg/lapack.pyx":2101
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
      __Pyx_TraceLine(2101,0,__PYX_ERR(0, 2101, __pyx_L1_error))
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":2106
 * 
 *         # select is overwritten in stgevc
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,             # <<<<<<<<<<<<<<
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data
 */
    __Pyx_TraceLine(2106,0,__PYX_ERR(0, 2106, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2106, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2106, __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, 2106, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_select));
    __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2106, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2106, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2106, __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, 2106, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2106, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2106, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __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;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2106, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_v_select_cpy, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_select_cpy.diminfo[0].strides = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select_cpy.diminfo[0].shape = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2106, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "kwant/linalg/lapack.pyx":2108
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(2108,0,__PYX_ERR(0, 2108, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);

    /* "kwant/linalg/lapack.pyx":2094
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":2110
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 */
  __Pyx_TraceLine(2110,0,__PYX_ERR(0, 2110, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2111
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 */
    __Pyx_TraceLine(2111,0,__PYX_ERR(0, 2111, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2112
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2112,0,__PYX_ERR(0, 2112, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2112, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2112, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_11 != 0);
    if (!__pyx_t_17) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    if (!__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_L12_next_or:;

    /* "kwant/linalg/lapack.pyx":2113
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or             # <<<<<<<<<<<<<<
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 */
    __Pyx_TraceLine(2113,0,__PYX_ERR(0, 2113, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2113, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L16_next_or;
    } else {
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2113, __pyx_L1_error)
    __pyx_t_17 = ((!__pyx_t_11) != 0);
    if (!__pyx_t_17) {
      goto __pyx_L16_next_or;
    } else {
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    if (!__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_L16_next_or:;

    /* "kwant/linalg/lapack.pyx":2114
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *             backtr = True
 */
    __Pyx_TraceLine(2114,0,__PYX_ERR(0, 2114, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2114, __pyx_L1_error)
    if (__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2114, __pyx_L1_error)
    __pyx_t_17 = ((!__pyx_t_11) != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_12 = __pyx_t_17;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    __pyx_t_12 = __pyx_t_11;
    __pyx_L11_bool_binop_done:;

    /* "kwant/linalg/lapack.pyx":2112
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2112,0,__PYX_ERR(0, 2112, __pyx_L1_error))
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2115
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *             backtr = True
 *         else:
 */
      __Pyx_TraceLine(2115,0,__PYX_ERR(0, 2115, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":2116
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(2116,0,__PYX_ERR(0, 2116, __pyx_L1_error))
      __pyx_v_backtr = 1;

      /* "kwant/linalg/lapack.pyx":2112
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
      goto __pyx_L10;
    }

    /* "kwant/linalg/lapack.pyx":2118
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(2118,0,__PYX_ERR(0, 2118, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L10:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2120
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
  __Pyx_TraceLine(2120,0,__PYX_ERR(0, 2120, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2120, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2121
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
    __Pyx_TraceLine(2121,0,__PYX_ERR(0, 2121, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_backtr != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2122
 *     if left:
 *         if backtr:
 *             vl_r = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      __Pyx_TraceLine(2122,0,__PYX_ERR(0, 2122, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Q), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2122, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_v_Q);

      /* "kwant/linalg/lapack.pyx":2121
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
      goto __pyx_L22;
    }

    /* "kwant/linalg/lapack.pyx":2124
 *             vl_r = Q
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 */
    __Pyx_TraceLine(2124,0,__PYX_ERR(0, 2124, __pyx_L1_error))
    /*else*/ {
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2124, __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, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2124, __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_2);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __pyx_t_5 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2124, __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_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2124, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2124, __pyx_L1_error)
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2124, __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_1); __pyx_t_1 = 0;
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2124, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_6);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2124, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_6);
      __pyx_t_6 = 0;
    }
    __pyx_L22:;

    /* "kwant/linalg/lapack.pyx":2125
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')
 *         vl_r_ptr = <float *>vl_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r_ptr = NULL
 */
    __Pyx_TraceLine(2125,0,__PYX_ERR(0, 2125, __pyx_L1_error))
    __pyx_v_vl_r_ptr = ((float *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":2120
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":2127
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(2127,0,__PYX_ERR(0, 2127, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L21:;

  /* "kwant/linalg/lapack.pyx":2129
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
  __Pyx_TraceLine(2129,0,__PYX_ERR(0, 2129, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2129, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2130
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
    __Pyx_TraceLine(2130,0,__PYX_ERR(0, 2130, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_backtr != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2131
 *     if right:
 *         if backtr:
 *             vr_r = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      __Pyx_TraceLine(2131,0,__PYX_ERR(0, 2131, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Z), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2131, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_v_Z);

      /* "kwant/linalg/lapack.pyx":2130
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
      goto __pyx_L24;
    }

    /* "kwant/linalg/lapack.pyx":2133
 *             vr_r = Z
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 */
    __Pyx_TraceLine(2133,0,__PYX_ERR(0, 2133, __pyx_L1_error))
    /*else*/ {
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2133, __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 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2133, __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, 2133, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2133, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __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;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2133, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2133, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L24:;

    /* "kwant/linalg/lapack.pyx":2134
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')
 *         vr_r_ptr = <float *>vr_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r_ptr = NULL
 */
    __Pyx_TraceLine(2134,0,__PYX_ERR(0, 2134, __pyx_L1_error))
    __pyx_v_vr_r_ptr = ((float *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":2129
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
    goto __pyx_L23;
  }

  /* "kwant/linalg/lapack.pyx":2136
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.stgevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(2136,0,__PYX_ERR(0, 2136, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L23:;

  /* "kwant/linalg/lapack.pyx":2138
 *         vr_r_ptr = NULL
 * 
 *     f_lapack.stgevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <float *>S.data, &N,
 *                      <float *>T.data, &N,
 */
  __Pyx_TraceLine(2138,0,__PYX_ERR(0, 2138, __pyx_L1_error))
  stgevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((float *)__pyx_v_S->data), (&__pyx_v_N), ((float *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_r_ptr, (&__pyx_v_N), __pyx_v_vr_r_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((float *)__pyx_v_work->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2144
 *                      <float *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in stgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"
 * 
 */
  __Pyx_TraceLine(2144,0,__PYX_ERR(0, 2144, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_stgevc);
      __PYX_ERR(0, 2144, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2145
 * 
 *     assert info == 0, "Argument error in stgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  __Pyx_TraceLine(2145,0,__PYX_ERR(0, 2145, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_5);
      __PYX_ERR(0, 2145, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2147
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  __Pyx_TraceLine(2147,0,__PYX_ERR(0, 2147, __pyx_L1_error))
  __pyx_t_12 = ((!(__pyx_v_backtr != 0)) != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2148
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __Pyx_TraceLine(2148,0,__PYX_ERR(0, 2148, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2148, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2149
 *     if not backtr:
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 */
      __Pyx_TraceLine(2149,0,__PYX_ERR(0, 2149, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2149, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2149, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2149, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2149, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2149, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2149, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2149, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2149, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2149, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl_r, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2148
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2150
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    __Pyx_TraceLine(2150,0,__PYX_ERR(0, 2150, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2150, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2151
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))             # <<<<<<<<<<<<<<
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 */
      __Pyx_TraceLine(2151,0,__PYX_ERR(0, 2151, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2151, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2151, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2151, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dot); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2151, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2151, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2151, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Z));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_Z));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2151, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_19);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_19, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2151, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_2};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2151, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_2};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2151, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2151, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2151, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2151, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr_r, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2150
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":2147
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  }

  /* "kwant/linalg/lapack.pyx":2154
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(S, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 */
  __Pyx_TraceLine(2154,0,__PYX_ERR(0, 2154, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2154, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2154, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2154, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(__pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, __pyx_int_neg_1);
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2154, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_19)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_19) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_19); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2154, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2154, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __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, 2154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2154, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2155
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:
 */
    __Pyx_TraceLine(2155,0,__PYX_ERR(0, 2155, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2155, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2156
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 */
      __Pyx_TraceLine(2156,0,__PYX_ERR(0, 2156, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2156, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2156, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2156, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __pyx_t_19 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_19)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_19);
          __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[5] = {__pyx_t_19, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2156, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2156, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_19) {
          __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_19); __pyx_t_19 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, __pyx_t_6);
        __Pyx_INCREF(((PyObject *)__pyx_v_S));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_S));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2156, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_vl = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2155
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2157
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 */
    __Pyx_TraceLine(2157,0,__PYX_ERR(0, 2157, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2157, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2158
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __Pyx_TraceLine(2158,0,__PYX_ERR(0, 2158, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2158, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2158, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2158, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, __pyx_t_6);
        __Pyx_INCREF(((PyObject *)__pyx_v_S));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_S));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_19, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2158, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_vr = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2157
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 */
    }

    /* "kwant/linalg/lapack.pyx":2154
 * 
 *     # If there are complex eigenvalues, we need to postprocess the eigenvectors
 *     if np.diagonal(S, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 */
    goto __pyx_L28;
  }

  /* "kwant/linalg/lapack.pyx":2160
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
  __Pyx_TraceLine(2160,0,__PYX_ERR(0, 2160, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2160, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2161
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_TraceLine(2161,0,__PYX_ERR(0, 2161, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);

      /* "kwant/linalg/lapack.pyx":2160
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2162
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __Pyx_TraceLine(2162,0,__PYX_ERR(0, 2162, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2162, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2163
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(2163,0,__PYX_ERR(0, 2163, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);

      /* "kwant/linalg/lapack.pyx":2162
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    }
  }
  __pyx_L28:;

  /* "kwant/linalg/lapack.pyx":2165
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(2165,0,__PYX_ERR(0, 2165, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2165, __pyx_L1_error)
  if (__pyx_t_11) {
  } else {
    __pyx_t_12 = __pyx_t_11;
    goto __pyx_L34_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2165, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_11;
  __pyx_L34_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2166
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(2166,0,__PYX_ERR(0, 2166, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 2166, __pyx_L1_error) }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 2166, __pyx_L1_error) }
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_vr);
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2165
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":2167
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(2167,0,__PYX_ERR(0, 2167, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2167, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2168
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(2168,0,__PYX_ERR(0, 2168, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 2168, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2167
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":2170
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(2170,0,__PYX_ERR(0, 2170, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 2170, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":2062
 * 
 * # xTGEVC
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_19);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.stgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_select_cpy);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_cmplxindx);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2173
 * 
 * 
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_83dtgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_83dtgevc = {"dtgevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_83dtgevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_83dtgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("dtgevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":2175
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2176
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[np.float64_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2177
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[np.float64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2178
 *            np.ndarray[np.float64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[5] = ((PyObject *)Py_False);
    values[6] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_S)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgevc", 0, 2, 7, 1); __PYX_ERR(0, 2173, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          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_select);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_right);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dtgevc") < 0)) __PYX_ERR(0, 2173, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_S = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_Z = ((PyArrayObject *)values[3]);
    __pyx_v_select = ((PyArrayObject *)values[4]);
    __pyx_v_left = values[5];
    __pyx_v_right = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dtgevc", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2173, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.dtgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 2173, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 2174, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 2175, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 2176, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 2177, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_82dtgevc(__pyx_self, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":2173
 * 
 * 
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_82dtgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl_r = 0;
  PyArrayObject *__pyx_v_vr_r = 0;
  double *__pyx_v_vl_r_ptr;
  double *__pyx_v_vr_r_ptr;
  PyArrayObject *__pyx_v_select_cpy = 0;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  int __pyx_v_backtr;
  PyObject *__pyx_v_cmplxindx = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_vl = NULL;
  PyObject *__pyx_v_vr = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select_cpy;
  __Pyx_Buffer __pyx_pybuffer_select_cpy;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl_r;
  __Pyx_Buffer __pyx_pybuffer_vl_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr_r;
  __Pyx_Buffer __pyx_pybuffer_vr_r;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyArrayObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__89)
  __Pyx_RefNannySetupContext("dtgevc", 0);
  __Pyx_TraceCall("dtgevc", __pyx_f[0], 2173, 0, __PYX_ERR(0, 2173, __pyx_L1_error));
  __pyx_pybuffer_vl_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vl_r.refcount = 0;
  __pyx_pybuffernd_vl_r.data = NULL;
  __pyx_pybuffernd_vl_r.rcbuffer = &__pyx_pybuffer_vl_r;
  __pyx_pybuffer_vr_r.pybuffer.buf = NULL;
  __pyx_pybuffer_vr_r.refcount = 0;
  __pyx_pybuffernd_vr_r.data = NULL;
  __pyx_pybuffernd_vr_r.rcbuffer = &__pyx_pybuffer_vr_r;
  __pyx_pybuffer_select_cpy.pybuffer.buf = NULL;
  __pyx_pybuffer_select_cpy.refcount = 0;
  __pyx_pybuffernd_select_cpy.data = NULL;
  __pyx_pybuffernd_select_cpy.rcbuffer = &__pyx_pybuffer_select_cpy;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":2189
 *     cdef np.ndarray[np.float64_t] work
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(2189,0,__PYX_ERR(0, 2189, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2189, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2189, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2189, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2189, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2191
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(6*N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(2191,0,__PYX_ERR(0, 2191, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2192
 * 
 *     N = S.shape[0]
 *     work = np.empty(6*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(2192,0,__PYX_ERR(0, 2192, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2192, __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, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((6 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2192, __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, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2192, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2192, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2194
 *     work = np.empty(6*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(2194,0,__PYX_ERR(0, 2194, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2194, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_11 = __pyx_t_12;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2194, __pyx_L1_error)
  __pyx_t_11 = __pyx_t_12;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2195
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(2195,0,__PYX_ERR(0, 2195, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":2194
 *     work = np.empty(6*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2196
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(2196,0,__PYX_ERR(0, 2196, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2196, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2197
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(2197,0,__PYX_ERR(0, 2197, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":2196
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2198
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(2198,0,__PYX_ERR(0, 2198, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2198, __pyx_L1_error)
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2199
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(2199,0,__PYX_ERR(0, 2199, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":2198
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2201
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
  __Pyx_TraceLine(2201,0,__PYX_ERR(0, 2201, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2203
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(2203,0,__PYX_ERR(0, 2203, __pyx_L1_error))
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2205
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(2205,0,__PYX_ERR(0, 2205, __pyx_L1_error))
  __pyx_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_12 = (__pyx_t_11 != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2206
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __Pyx_TraceLine(2206,0,__PYX_ERR(0, 2206, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":2207
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         # Correct for possible additional storage if a single complex
 *         # eigenvalue is selected.
 */
    __Pyx_TraceLine(2207,0,__PYX_ERR(0, 2207, __pyx_L1_error))
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2207, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2207, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2207, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2207, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_MM = __pyx_t_13;

    /* "kwant/linalg/lapack.pyx":2211
 *         # eigenvalue is selected.
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]             # <<<<<<<<<<<<<<
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 */
    __Pyx_TraceLine(2211,0,__PYX_ERR(0, 2211, __pyx_L1_error))
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_4 = 0;
    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 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
      __Pyx_INCREF(__pyx_int_neg_1);
      __Pyx_GIVEREF(__pyx_int_neg_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_int_neg_1);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __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_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __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 && likely(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);
      }
    }
    if (__pyx_t_1) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2211, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2211, __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, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_cmplxindx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":2212
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
    __Pyx_TraceLine(2212,0,__PYX_ERR(0, 2212, __pyx_L1_error))
    if (likely(PyList_CheckExact(__pyx_v_cmplxindx)) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_2 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_2); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
    } else {
      __pyx_t_14 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2212, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_15 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2212, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_15)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2212, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2212, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_15(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 2212, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "kwant/linalg/lapack.pyx":2213
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __Pyx_TraceLine(2213,0,__PYX_ERR(0, 2213, __pyx_L1_error))
      __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyBool_FromLong((!(!__pyx_t_12))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_12) {

        /* "kwant/linalg/lapack.pyx":2214
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # select is overwritten in dtgevc
 */
        __Pyx_TraceLine(2214,0,__PYX_ERR(0, 2214, __pyx_L1_error))
        __pyx_v_MM = (__pyx_v_MM + 1);

        /* "kwant/linalg/lapack.pyx":2213
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      }

      /* "kwant/linalg/lapack.pyx":2212
 *         # For that: Figure out the positions of the 2x2 blocks.
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:             # <<<<<<<<<<<<<<
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1
 */
      __Pyx_TraceLine(2212,0,__PYX_ERR(0, 2212, __pyx_L1_error))
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":2217
 * 
 *         # select is overwritten in dtgevc
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,             # <<<<<<<<<<<<<<
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data
 */
    __Pyx_TraceLine(2217,0,__PYX_ERR(0, 2217, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2217, __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, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_select));
    __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2217, __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, 2217, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2217, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __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;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2217, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_4 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_v_select_cpy, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
        __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
      }
      __pyx_pybuffernd_select_cpy.diminfo[0].strides = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select_cpy.diminfo[0].shape = __pyx_pybuffernd_select_cpy.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "kwant/linalg/lapack.pyx":2219
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(2219,0,__PYX_ERR(0, 2219, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);

    /* "kwant/linalg/lapack.pyx":2205
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":2221
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 */
  __Pyx_TraceLine(2221,0,__PYX_ERR(0, 2221, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2222
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 */
    __Pyx_TraceLine(2222,0,__PYX_ERR(0, 2222, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2223
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2223,0,__PYX_ERR(0, 2223, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2223, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2223, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_17 = (__pyx_t_11 != 0);
    if (!__pyx_t_17) {
      goto __pyx_L12_next_or;
    } else {
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    if (!__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_L12_next_or:;

    /* "kwant/linalg/lapack.pyx":2224
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or             # <<<<<<<<<<<<<<
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 */
    __Pyx_TraceLine(2224,0,__PYX_ERR(0, 2224, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2224, __pyx_L1_error)
    if (!__pyx_t_11) {
      goto __pyx_L16_next_or;
    } else {
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2224, __pyx_L1_error)
    __pyx_t_17 = ((!__pyx_t_11) != 0);
    if (!__pyx_t_17) {
      goto __pyx_L16_next_or;
    } else {
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    if (!__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_L16_next_or:;

    /* "kwant/linalg/lapack.pyx":2225
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *             backtr = True
 */
    __Pyx_TraceLine(2225,0,__PYX_ERR(0, 2225, __pyx_L1_error))
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2225, __pyx_L1_error)
    if (__pyx_t_11) {
    } else {
      __pyx_t_12 = __pyx_t_11;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2225, __pyx_L1_error)
    __pyx_t_17 = ((!__pyx_t_11) != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_12 = __pyx_t_17;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_17 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_11 = (__pyx_t_17 != 0);
    __pyx_t_12 = __pyx_t_11;
    __pyx_L11_bool_binop_done:;

    /* "kwant/linalg/lapack.pyx":2223
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2223,0,__PYX_ERR(0, 2223, __pyx_L1_error))
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2226
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *             backtr = True
 *         else:
 */
      __Pyx_TraceLine(2226,0,__PYX_ERR(0, 2226, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":2227
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(2227,0,__PYX_ERR(0, 2227, __pyx_L1_error))
      __pyx_v_backtr = 1;

      /* "kwant/linalg/lapack.pyx":2223
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
      goto __pyx_L10;
    }

    /* "kwant/linalg/lapack.pyx":2229
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(2229,0,__PYX_ERR(0, 2229, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L10:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2231
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
  __Pyx_TraceLine(2231,0,__PYX_ERR(0, 2231, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2231, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2232
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
    __Pyx_TraceLine(2232,0,__PYX_ERR(0, 2232, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_backtr != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2233
 *     if left:
 *         if backtr:
 *             vl_r = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      __Pyx_TraceLine(2233,0,__PYX_ERR(0, 2233, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Q), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2233, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_v_Q);

      /* "kwant/linalg/lapack.pyx":2232
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
      goto __pyx_L22;
    }

    /* "kwant/linalg/lapack.pyx":2235
 *             vl_r = Q
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 */
    __Pyx_TraceLine(2235,0,__PYX_ERR(0, 2235, __pyx_L1_error))
    /*else*/ {
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2235, __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, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2235, __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_2);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __pyx_t_5 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2235, __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_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2235, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2235, __pyx_L1_error)
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2235, __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_1); __pyx_t_1 = 0;
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2235, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_6);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2235, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_6);
      __pyx_t_6 = 0;
    }
    __pyx_L22:;

    /* "kwant/linalg/lapack.pyx":2236
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')
 *         vl_r_ptr = <double *>vl_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r_ptr = NULL
 */
    __Pyx_TraceLine(2236,0,__PYX_ERR(0, 2236, __pyx_L1_error))
    __pyx_v_vl_r_ptr = ((double *)__pyx_v_vl_r->data);

    /* "kwant/linalg/lapack.pyx":2231
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":2238
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(2238,0,__PYX_ERR(0, 2238, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L21:;

  /* "kwant/linalg/lapack.pyx":2240
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
  __Pyx_TraceLine(2240,0,__PYX_ERR(0, 2240, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2240, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2241
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
    __Pyx_TraceLine(2241,0,__PYX_ERR(0, 2241, __pyx_L1_error))
    __pyx_t_12 = (__pyx_v_backtr != 0);
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2242
 *     if right:
 *         if backtr:
 *             vr_r = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      __Pyx_TraceLine(2242,0,__PYX_ERR(0, 2242, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Z), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2242, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_v_Z);

      /* "kwant/linalg/lapack.pyx":2241
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
      goto __pyx_L24;
    }

    /* "kwant/linalg/lapack.pyx":2244
 *             vr_r = Z
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 */
    __Pyx_TraceLine(2244,0,__PYX_ERR(0, 2244, __pyx_L1_error))
    /*else*/ {
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2244, __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 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2244, __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, 2244, __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, 2244, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2244, __pyx_L1_error)
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __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;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2244, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2244, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L24:;

    /* "kwant/linalg/lapack.pyx":2245
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')
 *         vr_r_ptr = <double *>vr_r.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r_ptr = NULL
 */
    __Pyx_TraceLine(2245,0,__PYX_ERR(0, 2245, __pyx_L1_error))
    __pyx_v_vr_r_ptr = ((double *)__pyx_v_vr_r->data);

    /* "kwant/linalg/lapack.pyx":2240
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
    goto __pyx_L23;
  }

  /* "kwant/linalg/lapack.pyx":2247
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dtgevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(2247,0,__PYX_ERR(0, 2247, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L23:;

  /* "kwant/linalg/lapack.pyx":2249
 *         vr_r_ptr = NULL
 * 
 *     f_lapack.dtgevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <double *>S.data, &N,
 *                      <double *>T.data, &N,
 */
  __Pyx_TraceLine(2249,0,__PYX_ERR(0, 2249, __pyx_L1_error))
  dtgevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((double *)__pyx_v_S->data), (&__pyx_v_N), ((double *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_r_ptr, (&__pyx_v_N), __pyx_v_vr_r_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((double *)__pyx_v_work->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2255
 *                      <double *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in dtgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"
 * 
 */
  __Pyx_TraceLine(2255,0,__PYX_ERR(0, 2255, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_dtgevc);
      __PYX_ERR(0, 2255, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2256
 * 
 *     assert info == 0, "Argument error in dtgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  __Pyx_TraceLine(2256,0,__PYX_ERR(0, 2256, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_6);
      __PYX_ERR(0, 2256, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2258
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  __Pyx_TraceLine(2258,0,__PYX_ERR(0, 2258, __pyx_L1_error))
  __pyx_t_12 = ((!(__pyx_v_backtr != 0)) != 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2259
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __Pyx_TraceLine(2259,0,__PYX_ERR(0, 2259, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2259, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2260
 *     if not backtr:
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 */
      __Pyx_TraceLine(2260,0,__PYX_ERR(0, 2260, __pyx_L1_error))
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2260, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl_r)};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2260, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2260, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2260, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2260, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2260, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2260, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2260, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6); __pyx_t_6 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2260, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2260, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl_r.diminfo[0].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl_r.diminfo[0].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl_r.diminfo[1].strides = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl_r.diminfo[1].shape = __pyx_pybuffernd_vl_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2260, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl_r, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2259
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2261
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    __Pyx_TraceLine(2261,0,__PYX_ERR(0, 2261, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2261, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2262
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))             # <<<<<<<<<<<<<<
 * 
 *     # If there are complex eigenvalues, we need to postprocess the
 */
      __Pyx_TraceLine(2262,0,__PYX_ERR(0, 2262, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dot); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr_r)};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Z));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_Z));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_19);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_19, function);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_2};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2262, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_2};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2262, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2262, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2262, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2262, __pyx_L1_error)
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr_r, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr_r.diminfo[0].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr_r.diminfo[0].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr_r.diminfo[1].strides = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr_r.diminfo[1].shape = __pyx_pybuffernd_vr_r.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2262, __pyx_L1_error)
      }
      __pyx_t_18 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr_r, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2261
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":2258
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 */
  }

  /* "kwant/linalg/lapack.pyx":2266
 *     # If there are complex eigenvalues, we need to postprocess the
 *     # eigenvectors.
 *     if np.diagonal(S, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 */
  __Pyx_TraceLine(2266,0,__PYX_ERR(0, 2266, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_diagonal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_4 = 0;
  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 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2266, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_S), __pyx_int_neg_1};
    __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2266, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_19);
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(__pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_4, __pyx_int_neg_1);
    __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2266, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_t_19 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_19)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_19);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_19) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_19); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2266, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2266, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __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, 2266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2266, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2266, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2267
 *     # eigenvectors.
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:
 */
    __Pyx_TraceLine(2267,0,__PYX_ERR(0, 2267, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2267, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2268
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 */
      __Pyx_TraceLine(2268,0,__PYX_ERR(0, 2268, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_19, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __pyx_t_19 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_19)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_19);
          __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[5] = {__pyx_t_19, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2268, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_19, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vl_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2268, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2268, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_19) {
          __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_19); __pyx_t_19 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, __pyx_t_6);
        __Pyx_INCREF(((PyObject *)__pyx_v_S));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_S));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
        PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_4, ((PyObject *)__pyx_v_vl_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2268, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_vl = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2267
 *     # eigenvectors.
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2269
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 */
    __Pyx_TraceLine(2269,0,__PYX_ERR(0, 2269, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2269, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2270
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __Pyx_TraceLine(2270,0,__PYX_ERR(0, 2270, __pyx_L1_error))
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_txevc_postprocess); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2270, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_6, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_vr_r), ((PyObject *)__pyx_v_select)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2270, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 2270, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_4, __pyx_t_6);
        __Pyx_INCREF(((PyObject *)__pyx_v_S));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_4, ((PyObject *)__pyx_v_S));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
        PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_4, ((PyObject *)__pyx_v_vr_r));
        __Pyx_INCREF(((PyObject *)__pyx_v_select));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
        PyTuple_SET_ITEM(__pyx_t_19, 3+__pyx_t_4, ((PyObject *)__pyx_v_select));
        __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2270, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_vr = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":2269
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 */
    }

    /* "kwant/linalg/lapack.pyx":2266
 *     # If there are complex eigenvalues, we need to postprocess the
 *     # eigenvectors.
 *     if np.diagonal(S, -1).nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 */
    goto __pyx_L28;
  }

  /* "kwant/linalg/lapack.pyx":2272
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
  __Pyx_TraceLine(2272,0,__PYX_ERR(0, 2272, __pyx_L1_error))
  /*else*/ {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2272, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2273
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_TraceLine(2273,0,__PYX_ERR(0, 2273, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);

      /* "kwant/linalg/lapack.pyx":2272
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2274
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __Pyx_TraceLine(2274,0,__PYX_ERR(0, 2274, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2274, __pyx_L1_error)
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2275
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(2275,0,__PYX_ERR(0, 2275, __pyx_L1_error))
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);

      /* "kwant/linalg/lapack.pyx":2274
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    }
  }
  __pyx_L28:;

  /* "kwant/linalg/lapack.pyx":2277
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(2277,0,__PYX_ERR(0, 2277, __pyx_L1_error))
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2277, __pyx_L1_error)
  if (__pyx_t_11) {
  } else {
    __pyx_t_12 = __pyx_t_11;
    goto __pyx_L34_bool_binop_done;
  }
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2277, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_11;
  __pyx_L34_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2278
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(2278,0,__PYX_ERR(0, 2278, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 2278, __pyx_L1_error) }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 2278, __pyx_L1_error) }
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_vr);
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2277
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":2279
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(2279,0,__PYX_ERR(0, 2279, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2279, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2280
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(2280,0,__PYX_ERR(0, 2280, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); __PYX_ERR(0, 2280, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2279
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":2282
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(2282,0,__PYX_ERR(0, 2282, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); __PYX_ERR(0, 2282, __pyx_L1_error) }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":2173
 * 
 * 
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_19);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.dtgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr_r);
  __Pyx_XDECREF((PyObject *)__pyx_v_select_cpy);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF(__pyx_v_cmplxindx);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_vl);
  __Pyx_XDECREF(__pyx_v_vr);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2285
 * 
 * 
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_85ctgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_85ctgevc = {"ctgevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_85ctgevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_85ctgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ctgevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":2287
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2288
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2289
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2290
 *            np.ndarray[np.complex64_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[5] = ((PyObject *)Py_False);
    values[6] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_S)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgevc", 0, 2, 7, 1); __PYX_ERR(0, 2285, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          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_select);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_right);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ctgevc") < 0)) __PYX_ERR(0, 2285, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_S = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_Z = ((PyArrayObject *)values[3]);
    __pyx_v_select = ((PyArrayObject *)values[4]);
    __pyx_v_left = values[5];
    __pyx_v_right = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ctgevc", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2285, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ctgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 2285, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 2286, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 2287, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 2288, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 2289, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_84ctgevc(__pyx_self, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":2285
 * 
 * 
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_84ctgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_float_complex *__pyx_v_vl_ptr;
  __pyx_t_float_complex *__pyx_v_vr_ptr;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  int __pyx_v_backtr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__90)
  __Pyx_RefNannySetupContext("ctgevc", 0);
  __Pyx_TraceCall("ctgevc", __pyx_f[0], 2285, 0, __PYX_ERR(0, 2285, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":2301
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(2301,0,__PYX_ERR(0, 2301, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2301, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2301, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2301, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2301, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2301, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2303
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(2*N, dtype = np.float32)
 */
  __Pyx_TraceLine(2303,0,__PYX_ERR(0, 2303, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2304
 * 
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 */
  __Pyx_TraceLine(2304,0,__PYX_ERR(0, 2304, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2304, __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, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2304, __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, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2304, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2304, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2304, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2305
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(2*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(2305,0,__PYX_ERR(0, 2305, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2305, __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, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2305, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2305, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2305, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2305, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2307
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(2307,0,__PYX_ERR(0, 2307, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2307, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2308
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(2308,0,__PYX_ERR(0, 2308, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":2307
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2309
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(2309,0,__PYX_ERR(0, 2309, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2309, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2310
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(2310,0,__PYX_ERR(0, 2310, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":2309
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2311
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(2311,0,__PYX_ERR(0, 2311, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2311, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2312
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(2312,0,__PYX_ERR(0, 2312, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":2311
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2314
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
  __Pyx_TraceLine(2314,0,__PYX_ERR(0, 2314, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2316
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(2316,0,__PYX_ERR(0, 2316, __pyx_L1_error))
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2318
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(2318,0,__PYX_ERR(0, 2318, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_13 = (__pyx_t_12 != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2319
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __Pyx_TraceLine(2319,0,__PYX_ERR(0, 2319, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":2320
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __Pyx_TraceLine(2320,0,__PYX_ERR(0, 2320, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2320, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2320, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2320, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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, 2320, __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_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2320, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":2321
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(2321,0,__PYX_ERR(0, 2321, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);

    /* "kwant/linalg/lapack.pyx":2318
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":2323
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 */
  __Pyx_TraceLine(2323,0,__PYX_ERR(0, 2323, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2324
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 */
    __Pyx_TraceLine(2324,0,__PYX_ERR(0, 2324, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2325
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2325,0,__PYX_ERR(0, 2325, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2325, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2325, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_12 != 0);
    if (!__pyx_t_15) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L9_next_or:;

    /* "kwant/linalg/lapack.pyx":2326
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or             # <<<<<<<<<<<<<<
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 */
    __Pyx_TraceLine(2326,0,__PYX_ERR(0, 2326, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2326, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L13_next_or;
    } else {
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2326, __pyx_L1_error)
    __pyx_t_15 = ((!__pyx_t_12) != 0);
    if (!__pyx_t_15) {
      goto __pyx_L13_next_or;
    } else {
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L13_next_or:;

    /* "kwant/linalg/lapack.pyx":2327
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *             backtr = True
 */
    __Pyx_TraceLine(2327,0,__PYX_ERR(0, 2327, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2327, __pyx_L1_error)
    if (__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2327, __pyx_L1_error)
    __pyx_t_15 = ((!__pyx_t_12) != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_13 = __pyx_t_15;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    __pyx_t_13 = __pyx_t_12;
    __pyx_L8_bool_binop_done:;

    /* "kwant/linalg/lapack.pyx":2325
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2325,0,__PYX_ERR(0, 2325, __pyx_L1_error))
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2328
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *             backtr = True
 *         else:
 */
      __Pyx_TraceLine(2328,0,__PYX_ERR(0, 2328, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":2329
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(2329,0,__PYX_ERR(0, 2329, __pyx_L1_error))
      __pyx_v_backtr = 1;

      /* "kwant/linalg/lapack.pyx":2325
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
      goto __pyx_L7;
    }

    /* "kwant/linalg/lapack.pyx":2331
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(2331,0,__PYX_ERR(0, 2331, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2333
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
  __Pyx_TraceLine(2333,0,__PYX_ERR(0, 2333, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2333, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2334
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
    __Pyx_TraceLine(2334,0,__PYX_ERR(0, 2334, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_backtr != 0);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2335
 *     if left:
 *         if backtr:
 *             vl = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      __Pyx_TraceLine(2335,0,__PYX_ERR(0, 2335, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Q), &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2335, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl = ((PyArrayObject *)__pyx_v_Q);

      /* "kwant/linalg/lapack.pyx":2334
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
      goto __pyx_L19;
    }

    /* "kwant/linalg/lapack.pyx":2337
 *             vl = Q
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *     else:
 */
    __Pyx_TraceLine(2337,0,__PYX_ERR(0, 2337, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2337, __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_5);
      PyTuple_SET_ITEM(__pyx_t_1, 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, 2337, __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(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2337, __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, 2337, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2337, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __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;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2337, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2337, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":2338
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(2338,0,__PYX_ERR(0, 2338, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_float_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":2333
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2340
 *         vl_ptr = <float complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(2340,0,__PYX_ERR(0, 2340, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L18:;

  /* "kwant/linalg/lapack.pyx":2342
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
  __Pyx_TraceLine(2342,0,__PYX_ERR(0, 2342, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2342, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2343
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
    __Pyx_TraceLine(2343,0,__PYX_ERR(0, 2343, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_backtr != 0);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2344
 *     if right:
 *         if backtr:
 *             vr = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      __Pyx_TraceLine(2344,0,__PYX_ERR(0, 2344, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Z), &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2344, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr = ((PyArrayObject *)__pyx_v_Z);

      /* "kwant/linalg/lapack.pyx":2343
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
      goto __pyx_L21;
    }

    /* "kwant/linalg/lapack.pyx":2346
 *             vr = Z
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *     else:
 */
    __Pyx_TraceLine(2346,0,__PYX_ERR(0, 2346, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2346, __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); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2346, __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_5);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2346, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2346, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2346, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2346, __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_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2346, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2346, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L21:;

    /* "kwant/linalg/lapack.pyx":2347
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(2347,0,__PYX_ERR(0, 2347, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_float_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":2342
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
    goto __pyx_L20;
  }

  /* "kwant/linalg/lapack.pyx":2349
 *         vr_ptr = <float complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ctgevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(2349,0,__PYX_ERR(0, 2349, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L20:;

  /* "kwant/linalg/lapack.pyx":2351
 *         vr_ptr = NULL
 * 
 *     f_lapack.ctgevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <float complex *>S.data, &N,
 *                      <float complex *>T.data, &N,
 */
  __Pyx_TraceLine(2351,0,__PYX_ERR(0, 2351, __pyx_L1_error))
  ctgevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_float_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((__pyx_t_float_complex *)__pyx_v_work->data), ((float *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2357
 *                      <float complex *>work.data, <float *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in ctgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"
 * 
 */
  __Pyx_TraceLine(2357,0,__PYX_ERR(0, 2357, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ctgevc);
      __PYX_ERR(0, 2357, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2358
 * 
 *     assert info == 0, "Argument error in ctgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  __Pyx_TraceLine(2358,0,__PYX_ERR(0, 2358, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_7);
      __PYX_ERR(0, 2358, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2360
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __Pyx_TraceLine(2360,0,__PYX_ERR(0, 2360, __pyx_L1_error))
  __pyx_t_13 = ((!(__pyx_v_backtr != 0)) != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2361
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __Pyx_TraceLine(2361,0,__PYX_ERR(0, 2361, __pyx_L1_error))
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2361, __pyx_L1_error)
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2362
 *     if not backtr:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))
 */
      __Pyx_TraceLine(2362,0,__PYX_ERR(0, 2362, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2362, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2362, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2362, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2362, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2362, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2362, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __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);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2362, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2362, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __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[2] = {__pyx_t_2, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2362, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2362, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2362, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2362, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2362, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":2361
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2363
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    __Pyx_TraceLine(2363,0,__PYX_ERR(0, 2363, __pyx_L1_error))
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2363, __pyx_L1_error)
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2364
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(2364,0,__PYX_ERR(0, 2364, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __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[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2364, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2364, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2364, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Z));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_Z));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr));
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2364, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __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_17))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_17);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_17, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2364, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_5);
          __pyx_t_5 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2364, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2364, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":2363
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":2360
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  }

  /* "kwant/linalg/lapack.pyx":2366
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(2366,0,__PYX_ERR(0, 2366, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2366, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_13 = __pyx_t_12;
    goto __pyx_L26_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2366, __pyx_L1_error)
  __pyx_t_13 = __pyx_t_12;
  __pyx_L26_bool_binop_done:;
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2367
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(2367,0,__PYX_ERR(0, 2367, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2366
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":2368
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(2368,0,__PYX_ERR(0, 2368, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2368, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2369
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(2369,0,__PYX_ERR(0, 2369, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2368
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":2371
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(2371,0,__PYX_ERR(0, 2371, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":2285
 * 
 * 
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_17);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ctgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2374
 * 
 * 
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_87ztgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_87ztgevc = {"ztgevc", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_87ztgevc, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_87ztgevc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_S = 0;
  PyArrayObject *__pyx_v_T = 0;
  PyArrayObject *__pyx_v_Q = 0;
  PyArrayObject *__pyx_v_Z = 0;
  PyArrayObject *__pyx_v_select = 0;
  PyObject *__pyx_v_left = 0;
  PyObject *__pyx_v_right = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ztgevc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_S,&__pyx_n_s_T,&__pyx_n_s_Q,&__pyx_n_s_Z,&__pyx_n_s_select,&__pyx_n_s_left,&__pyx_n_s_right,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};

    /* "kwant/linalg/lapack.pyx":2376
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 */
    values[2] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2377
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):
 */
    values[3] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2378
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,             # <<<<<<<<<<<<<<
 *            left=False, right=True):
 *     cdef l_int N, info, M, MM
 */
    values[4] = (PyObject *)((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":2379
 *            np.ndarray[np.complex128_t, ndim=2] Z=None,
 *            np.ndarray[l_logical] select=None,
 *            left=False, right=True):             # <<<<<<<<<<<<<<
 *     cdef l_int N, info, M, MM
 *     cdef char *side
 */
    values[5] = ((PyObject *)Py_False);
    values[6] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_S)) != 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_T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgevc", 0, 2, 7, 1); __PYX_ERR(0, 2374, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_Q);
          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_Z);
          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_select);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_left);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_right);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ztgevc") < 0)) __PYX_ERR(0, 2374, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_S = ((PyArrayObject *)values[0]);
    __pyx_v_T = ((PyArrayObject *)values[1]);
    __pyx_v_Q = ((PyArrayObject *)values[2]);
    __pyx_v_Z = ((PyArrayObject *)values[3]);
    __pyx_v_select = ((PyArrayObject *)values[4]);
    __pyx_v_left = values[5];
    __pyx_v_right = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ztgevc", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2374, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("kwant.linalg.lapack.ztgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) __PYX_ERR(0, 2374, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) __PYX_ERR(0, 2375, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) __PYX_ERR(0, 2376, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) __PYX_ERR(0, 2377, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) __PYX_ERR(0, 2378, __pyx_L1_error)
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_86ztgevc(__pyx_self, __pyx_v_S, __pyx_v_T, __pyx_v_Q, __pyx_v_Z, __pyx_v_select, __pyx_v_left, __pyx_v_right);

  /* "kwant/linalg/lapack.pyx":2374
 * 
 * 
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_86ztgevc(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_S, PyArrayObject *__pyx_v_T, PyArrayObject *__pyx_v_Q, PyArrayObject *__pyx_v_Z, PyArrayObject *__pyx_v_select, PyObject *__pyx_v_left, PyObject *__pyx_v_right) {
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_N;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_info;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_M;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_v_MM;
  char *__pyx_v_side;
  char *__pyx_v_howmny;
  PyArrayObject *__pyx_v_vl = 0;
  PyArrayObject *__pyx_v_vr = 0;
  __pyx_t_double_complex *__pyx_v_vl_ptr;
  __pyx_t_double_complex *__pyx_v_vr_ptr;
  __pyx_t_5kwant_6linalg_8f_lapack_l_logical *__pyx_v_select_ptr;
  PyArrayObject *__pyx_v_work = 0;
  PyArrayObject *__pyx_v_rwork = 0;
  int __pyx_v_backtr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Q;
  __Pyx_Buffer __pyx_pybuffer_Q;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_S;
  __Pyx_Buffer __pyx_pybuffer_S;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_T;
  __Pyx_Buffer __pyx_pybuffer_T;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_Z;
  __Pyx_Buffer __pyx_pybuffer_Z;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_rwork;
  __Pyx_Buffer __pyx_pybuffer_rwork;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_select;
  __Pyx_Buffer __pyx_pybuffer_select;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vl;
  __Pyx_Buffer __pyx_pybuffer_vl;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vr;
  __Pyx_Buffer __pyx_pybuffer_vr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_work;
  __Pyx_Buffer __pyx_pybuffer_work;
  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;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  __Pyx_TraceFrameInit(__pyx_codeobj__91)
  __Pyx_RefNannySetupContext("ztgevc", 0);
  __Pyx_TraceCall("ztgevc", __pyx_f[0], 2374, 0, __PYX_ERR(0, 2374, __pyx_L1_error));
  __pyx_pybuffer_vl.pybuffer.buf = NULL;
  __pyx_pybuffer_vl.refcount = 0;
  __pyx_pybuffernd_vl.data = NULL;
  __pyx_pybuffernd_vl.rcbuffer = &__pyx_pybuffer_vl;
  __pyx_pybuffer_vr.pybuffer.buf = NULL;
  __pyx_pybuffer_vr.refcount = 0;
  __pyx_pybuffernd_vr.data = NULL;
  __pyx_pybuffernd_vr.rcbuffer = &__pyx_pybuffer_vr;
  __pyx_pybuffer_work.pybuffer.buf = NULL;
  __pyx_pybuffer_work.refcount = 0;
  __pyx_pybuffernd_work.data = NULL;
  __pyx_pybuffernd_work.rcbuffer = &__pyx_pybuffer_work;
  __pyx_pybuffer_rwork.pybuffer.buf = NULL;
  __pyx_pybuffer_rwork.refcount = 0;
  __pyx_pybuffernd_rwork.data = NULL;
  __pyx_pybuffernd_rwork.rcbuffer = &__pyx_pybuffer_rwork;
  __pyx_pybuffer_S.pybuffer.buf = NULL;
  __pyx_pybuffer_S.refcount = 0;
  __pyx_pybuffernd_S.data = NULL;
  __pyx_pybuffernd_S.rcbuffer = &__pyx_pybuffer_S;
  __pyx_pybuffer_T.pybuffer.buf = NULL;
  __pyx_pybuffer_T.refcount = 0;
  __pyx_pybuffernd_T.data = NULL;
  __pyx_pybuffernd_T.rcbuffer = &__pyx_pybuffer_T;
  __pyx_pybuffer_Q.pybuffer.buf = NULL;
  __pyx_pybuffer_Q.refcount = 0;
  __pyx_pybuffernd_Q.data = NULL;
  __pyx_pybuffernd_Q.rcbuffer = &__pyx_pybuffer_Q;
  __pyx_pybuffer_Z.pybuffer.buf = NULL;
  __pyx_pybuffer_Z.refcount = 0;
  __pyx_pybuffernd_Z.data = NULL;
  __pyx_pybuffernd_Z.rcbuffer = &__pyx_pybuffer_Z;
  __pyx_pybuffer_select.pybuffer.buf = NULL;
  __pyx_pybuffer_select.refcount = 0;
  __pyx_pybuffernd_select.data = NULL;
  __pyx_pybuffernd_select.rcbuffer = &__pyx_pybuffer_select;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_S.rcbuffer->pybuffer, (PyObject*)__pyx_v_S, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2374, __pyx_L1_error)
  }
  __pyx_pybuffernd_S.diminfo[0].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_S.diminfo[0].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_S.diminfo[1].strides = __pyx_pybuffernd_S.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_S.diminfo[1].shape = __pyx_pybuffernd_S.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_T.rcbuffer->pybuffer, (PyObject*)__pyx_v_T, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2374, __pyx_L1_error)
  }
  __pyx_pybuffernd_T.diminfo[0].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_T.diminfo[0].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_T.diminfo[1].strides = __pyx_pybuffernd_T.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_T.diminfo[1].shape = __pyx_pybuffernd_T.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Q.rcbuffer->pybuffer, (PyObject*)__pyx_v_Q, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2374, __pyx_L1_error)
  }
  __pyx_pybuffernd_Q.diminfo[0].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Q.diminfo[0].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Q.diminfo[1].strides = __pyx_pybuffernd_Q.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Q.diminfo[1].shape = __pyx_pybuffernd_Q.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_Z.rcbuffer->pybuffer, (PyObject*)__pyx_v_Z, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2374, __pyx_L1_error)
  }
  __pyx_pybuffernd_Z.diminfo[0].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_Z.diminfo[0].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_Z.diminfo[1].strides = __pyx_pybuffernd_Z.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_Z.diminfo[1].shape = __pyx_pybuffernd_Z.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select.rcbuffer->pybuffer, (PyObject*)__pyx_v_select, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 2374, __pyx_L1_error)
  }
  __pyx_pybuffernd_select.diminfo[0].strides = __pyx_pybuffernd_select.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_select.diminfo[0].shape = __pyx_pybuffernd_select.rcbuffer->pybuffer.shape[0];

  /* "kwant/linalg/lapack.pyx":2390
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __Pyx_TraceLine(2390,0,__PYX_ERR(0, 2390, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_assert_fortran_mat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  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_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2390, __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[5] = {__pyx_t_3, ((PyObject *)__pyx_v_S), ((PyObject *)__pyx_v_T), ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_Z)};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2390, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2390, __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(((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_S));
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_T));
    __Pyx_INCREF(((PyObject *)__pyx_v_Q));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, ((PyObject *)__pyx_v_Q));
    __Pyx_INCREF(((PyObject *)__pyx_v_Z));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, ((PyObject *)__pyx_v_Z));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2390, __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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2392
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(2*N, dtype = np.float64)
 */
  __Pyx_TraceLine(2392,0,__PYX_ERR(0, 2392, __pyx_L1_error))
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2393
 * 
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 */
  __Pyx_TraceLine(2393,0,__PYX_ERR(0, 2393, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2393, __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, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2393, __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, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2393, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_work.rcbuffer->pybuffer, (PyObject*)__pyx_v_work, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
      __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_work.diminfo[0].strides = __pyx_pybuffernd_work.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_work.diminfo[0].shape = __pyx_pybuffernd_work.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2393, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "kwant/linalg/lapack.pyx":2394
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(2*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __Pyx_TraceLine(2394,0,__PYX_ERR(0, 2394, __pyx_L1_error))
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_From_long((2 * __pyx_v_N)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2394, __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, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2394, __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_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2394, __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_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2394, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_4 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer, (PyObject*)__pyx_v_rwork, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
      __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
    }
    __pyx_pybuffernd_rwork.diminfo[0].strides = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rwork.diminfo[0].shape = __pyx_pybuffernd_rwork.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2394, __pyx_L1_error)
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2396
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __Pyx_TraceLine(2396,0,__PYX_ERR(0, 2396, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2396, __pyx_L1_error)
  if (__pyx_t_13) {
  } else {
    __pyx_t_12 = __pyx_t_13;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2396, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_13;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2397
 * 
 *     if left and right:
 *         side = "B"             # <<<<<<<<<<<<<<
 *     elif left:
 *         side = "L"
 */
    __Pyx_TraceLine(2397,0,__PYX_ERR(0, 2397, __pyx_L1_error))
    __pyx_v_side = ((char *)"B");

    /* "kwant/linalg/lapack.pyx":2396
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2398
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __Pyx_TraceLine(2398,0,__PYX_ERR(0, 2398, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2398, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2399
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __Pyx_TraceLine(2399,0,__PYX_ERR(0, 2399, __pyx_L1_error))
    __pyx_v_side = ((char *)"L");

    /* "kwant/linalg/lapack.pyx":2398
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2400
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __Pyx_TraceLine(2400,0,__PYX_ERR(0, 2400, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2400, __pyx_L1_error)
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":2401
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __Pyx_TraceLine(2401,0,__PYX_ERR(0, 2401, __pyx_L1_error))
    __pyx_v_side = ((char *)"R");

    /* "kwant/linalg/lapack.pyx":2400
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2403
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
  __Pyx_TraceLine(2403,0,__PYX_ERR(0, 2403, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2405
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __Pyx_TraceLine(2405,0,__PYX_ERR(0, 2405, __pyx_L1_error))
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2407
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __Pyx_TraceLine(2407,0,__PYX_ERR(0, 2407, __pyx_L1_error))
  __pyx_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  __pyx_t_13 = (__pyx_t_12 != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2408
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __Pyx_TraceLine(2408,0,__PYX_ERR(0, 2408, __pyx_L1_error))
    __pyx_v_howmny = ((char *)"S");

    /* "kwant/linalg/lapack.pyx":2409
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __Pyx_TraceLine(2409,0,__PYX_ERR(0, 2409, __pyx_L1_error))
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s_nonzero); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2409, __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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2409, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2409, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __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, 2409, __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_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2409, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2409, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":2410
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __Pyx_TraceLine(2410,0,__PYX_ERR(0, 2410, __pyx_L1_error))
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);

    /* "kwant/linalg/lapack.pyx":2407
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
    goto __pyx_L6;
  }

  /* "kwant/linalg/lapack.pyx":2412
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 */
  __Pyx_TraceLine(2412,0,__PYX_ERR(0, 2412, __pyx_L1_error))
  /*else*/ {
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2413
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 */
    __Pyx_TraceLine(2413,0,__PYX_ERR(0, 2413, __pyx_L1_error))
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2414
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2414,0,__PYX_ERR(0, 2414, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2414, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2414, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_15 = (__pyx_t_12 != 0);
    if (!__pyx_t_15) {
      goto __pyx_L9_next_or;
    } else {
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L9_next_or:;

    /* "kwant/linalg/lapack.pyx":2415
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or             # <<<<<<<<<<<<<<
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 */
    __Pyx_TraceLine(2415,0,__PYX_ERR(0, 2415, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2415, __pyx_L1_error)
    if (!__pyx_t_12) {
      goto __pyx_L13_next_or;
    } else {
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2415, __pyx_L1_error)
    __pyx_t_15 = ((!__pyx_t_12) != 0);
    if (!__pyx_t_15) {
      goto __pyx_L13_next_or;
    } else {
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_L13_next_or:;

    /* "kwant/linalg/lapack.pyx":2416
 *         if ((left and right and Q is not None and Z is not None) or
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *             backtr = True
 */
    __Pyx_TraceLine(2416,0,__PYX_ERR(0, 2416, __pyx_L1_error))
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2416, __pyx_L1_error)
    if (__pyx_t_12) {
    } else {
      __pyx_t_13 = __pyx_t_12;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2416, __pyx_L1_error)
    __pyx_t_15 = ((!__pyx_t_12) != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_13 = __pyx_t_15;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_15 = (((PyObject *)__pyx_v_Z) != Py_None);
    __pyx_t_12 = (__pyx_t_15 != 0);
    __pyx_t_13 = __pyx_t_12;
    __pyx_L8_bool_binop_done:;

    /* "kwant/linalg/lapack.pyx":2414
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
    __Pyx_TraceLine(2414,0,__PYX_ERR(0, 2414, __pyx_L1_error))
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2417
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *             backtr = True
 *         else:
 */
      __Pyx_TraceLine(2417,0,__PYX_ERR(0, 2417, __pyx_L1_error))
      __pyx_v_howmny = ((char *)"B");

      /* "kwant/linalg/lapack.pyx":2418
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __Pyx_TraceLine(2418,0,__PYX_ERR(0, 2418, __pyx_L1_error))
      __pyx_v_backtr = 1;

      /* "kwant/linalg/lapack.pyx":2414
 *         MM = N
 *         select_ptr = NULL
 *         if ((left and right and Q is not None and Z is not None) or             # <<<<<<<<<<<<<<
 *             (left and not right and Q is not None) or
 *             (right and not left and Z is not None)):
 */
      goto __pyx_L7;
    }

    /* "kwant/linalg/lapack.pyx":2420
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
    __Pyx_TraceLine(2420,0,__PYX_ERR(0, 2420, __pyx_L1_error))
    /*else*/ {
      __pyx_v_howmny = ((char *)"A");
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2422
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
  __Pyx_TraceLine(2422,0,__PYX_ERR(0, 2422, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2422, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2423
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
    __Pyx_TraceLine(2423,0,__PYX_ERR(0, 2423, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_backtr != 0);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2424
 *     if left:
 *         if backtr:
 *             vl = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      __Pyx_TraceLine(2424,0,__PYX_ERR(0, 2424, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Q), &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2424, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl = ((PyArrayObject *)__pyx_v_Q);

      /* "kwant/linalg/lapack.pyx":2423
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
      goto __pyx_L19;
    }

    /* "kwant/linalg/lapack.pyx":2426
 *             vl = Q
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *     else:
 */
    __Pyx_TraceLine(2426,0,__PYX_ERR(0, 2426, __pyx_L1_error))
    /*else*/ {
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2426, __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_5);
      PyTuple_SET_ITEM(__pyx_t_1, 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, 2426, __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(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_complex128); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2426, __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, 2426, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2426, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2426, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __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;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2426, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2426, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":2427
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __Pyx_TraceLine(2427,0,__PYX_ERR(0, 2427, __pyx_L1_error))
    __pyx_v_vl_ptr = ((__pyx_t_double_complex *)__pyx_v_vl->data);

    /* "kwant/linalg/lapack.pyx":2422
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2429
 *         vl_ptr = <double complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
  __Pyx_TraceLine(2429,0,__PYX_ERR(0, 2429, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L18:;

  /* "kwant/linalg/lapack.pyx":2431
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
  __Pyx_TraceLine(2431,0,__PYX_ERR(0, 2431, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2431, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2432
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
    __Pyx_TraceLine(2432,0,__PYX_ERR(0, 2432, __pyx_L1_error))
    __pyx_t_13 = (__pyx_v_backtr != 0);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2433
 *     if right:
 *         if backtr:
 *             vr = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      __Pyx_TraceLine(2433,0,__PYX_ERR(0, 2433, __pyx_L1_error))
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_v_Z), &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2433, __pyx_L1_error)
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr = ((PyArrayObject *)__pyx_v_Z);

      /* "kwant/linalg/lapack.pyx":2432
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
      goto __pyx_L21;
    }

    /* "kwant/linalg/lapack.pyx":2435
 *             vr = Z
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *     else:
 */
    __Pyx_TraceLine(2435,0,__PYX_ERR(0, 2435, __pyx_L1_error))
    /*else*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2435, __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); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_MM); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2435, __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_5);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2435, __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(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_complex128); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_order, __pyx_n_u_F) < 0) __PYX_ERR(0, 2435, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2435, __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_6); __pyx_t_6 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2435, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2435, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L21:;

    /* "kwant/linalg/lapack.pyx":2436
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __Pyx_TraceLine(2436,0,__PYX_ERR(0, 2436, __pyx_L1_error))
    __pyx_v_vr_ptr = ((__pyx_t_double_complex *)__pyx_v_vr->data);

    /* "kwant/linalg/lapack.pyx":2431
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
    goto __pyx_L20;
  }

  /* "kwant/linalg/lapack.pyx":2438
 *         vr_ptr = <double complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ztgevc_(side, howmny, select_ptr,
 */
  __Pyx_TraceLine(2438,0,__PYX_ERR(0, 2438, __pyx_L1_error))
  /*else*/ {
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L20:;

  /* "kwant/linalg/lapack.pyx":2440
 *         vr_ptr = NULL
 * 
 *     f_lapack.ztgevc_(side, howmny, select_ptr,             # <<<<<<<<<<<<<<
 *                      &N, <double complex *>S.data, &N,
 *                      <double complex *>T.data, &N,
 */
  __Pyx_TraceLine(2440,0,__PYX_ERR(0, 2440, __pyx_L1_error))
  ztgevc_(__pyx_v_side, __pyx_v_howmny, __pyx_v_select_ptr, (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_S->data), (&__pyx_v_N), ((__pyx_t_double_complex *)__pyx_v_T->data), (&__pyx_v_N), __pyx_v_vl_ptr, (&__pyx_v_N), __pyx_v_vr_ptr, (&__pyx_v_N), (&__pyx_v_MM), (&__pyx_v_M), ((__pyx_t_double_complex *)__pyx_v_work->data), ((double *)__pyx_v_rwork->data), (&__pyx_v_info));

  /* "kwant/linalg/lapack.pyx":2446
 *                      <double complex *>work.data, <double *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in ztgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"
 * 
 */
  __Pyx_TraceLine(2446,0,__PYX_ERR(0, 2446, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_info == 0) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Argument_error_in_ztgevc);
      __PYX_ERR(0, 2446, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2447
 * 
 *     assert info == 0, "Argument error in ztgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  __Pyx_TraceLine(2447,0,__PYX_ERR(0, 2447, __pyx_L1_error))
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_MM == __pyx_v_M) != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_u_Unexpected_number_of_eigenvector_8);
      __PYX_ERR(0, 2447, __pyx_L1_error)
    }
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2449
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __Pyx_TraceLine(2449,0,__PYX_ERR(0, 2449, __pyx_L1_error))
  __pyx_t_13 = ((!(__pyx_v_backtr != 0)) != 0);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2450
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __Pyx_TraceLine(2450,0,__PYX_ERR(0, 2450, __pyx_L1_error))
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2450, __pyx_L1_error)
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2451
 *     if not backtr:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))
 */
      __Pyx_TraceLine(2451,0,__PYX_ERR(0, 2451, __pyx_L1_error))
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_4 = 0;
      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 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2451, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_Q), ((PyObject *)__pyx_v_vl)};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2451, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2451, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Q));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_4, ((PyObject *)__pyx_v_Q));
        __Pyx_INCREF(((PyObject *)__pyx_v_vl));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_4, ((PyObject *)__pyx_v_vl));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2451, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __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);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2451, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2451, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __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[2] = {__pyx_t_2, __pyx_t_6};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2451, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2451, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_v_vl, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
          __pyx_t_8 = __pyx_t_9 = __pyx_t_10 = 0;
        }
        __pyx_pybuffernd_vl.diminfo[0].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vl.diminfo[0].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vl.diminfo[1].strides = __pyx_pybuffernd_vl.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vl.diminfo[1].shape = __pyx_pybuffernd_vl.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2451, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vl, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":2450
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    }

    /* "kwant/linalg/lapack.pyx":2452
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    __Pyx_TraceLine(2452,0,__PYX_ERR(0, 2452, __pyx_L1_error))
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2452, __pyx_L1_error)
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":2453
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_TraceLine(2453,0,__PYX_ERR(0, 2453, __pyx_L1_error))
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __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[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr)};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2453, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, ((PyObject *)__pyx_v_Z), ((PyObject *)__pyx_v_vr)};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2453, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(((PyObject *)__pyx_v_Z));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_4, ((PyObject *)__pyx_v_Z));
        __Pyx_INCREF(((PyObject *)__pyx_v_vr));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_4, ((PyObject *)__pyx_v_vr));
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2453, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __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_17))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_17);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_17, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        {
          __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_5);
          __pyx_t_5 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2453, __pyx_L1_error)
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_4 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_4 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_v_vr, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
          __pyx_t_10 = __pyx_t_9 = __pyx_t_8 = 0;
        }
        __pyx_pybuffernd_vr.diminfo[0].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vr.diminfo[0].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_vr.diminfo[1].strides = __pyx_pybuffernd_vr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_vr.diminfo[1].shape = __pyx_pybuffernd_vr.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2453, __pyx_L1_error)
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_vr, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "kwant/linalg/lapack.pyx":2452
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    }

    /* "kwant/linalg/lapack.pyx":2449
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  }

  /* "kwant/linalg/lapack.pyx":2455
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __Pyx_TraceLine(2455,0,__PYX_ERR(0, 2455, __pyx_L1_error))
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2455, __pyx_L1_error)
  if (__pyx_t_12) {
  } else {
    __pyx_t_13 = __pyx_t_12;
    goto __pyx_L26_bool_binop_done;
  }
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2455, __pyx_L1_error)
  __pyx_t_13 = __pyx_t_12;
  __pyx_L26_bool_binop_done:;
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2456
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_TraceLine(2456,0,__PYX_ERR(0, 2456, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2456, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2455
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  }

  /* "kwant/linalg/lapack.pyx":2457
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __Pyx_TraceLine(2457,0,__PYX_ERR(0, 2457, __pyx_L1_error))
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2457, __pyx_L1_error)
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2458
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_TraceLine(2458,0,__PYX_ERR(0, 2458, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;

    /* "kwant/linalg/lapack.pyx":2457
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  }

  /* "kwant/linalg/lapack.pyx":2460
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(2460,0,__PYX_ERR(0, 2460, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }

  /* "kwant/linalg/lapack.pyx":2374
 * 
 * 
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_17);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("kwant.linalg.lapack.ztgevc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Q.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_S.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_T.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Z.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rwork.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_work.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vl);
  __Pyx_XDECREF((PyObject *)__pyx_v_vr);
  __Pyx_XDECREF((PyObject *)__pyx_v_work);
  __Pyx_XDECREF((PyObject *)__pyx_v_rwork);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2463
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_89prepare_for_lapack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5kwant_6linalg_6lapack_88prepare_for_lapack[] = "Convert arrays to Fortran format.\n\n    This function takes a number of array objects in `args` and converts them\n    to a format that can be directly passed to a Fortran function (Fortran\n    contiguous NumPy array). If the arrays have different data type, they\n    converted arrays are cast to a common compatible data type (one of NumPy's\n    `float32`, `float64`, `complex64`, `complex128` data types).\n\n    If `overwrite` is ``False``, an NumPy array that would already be in the\n    correct format (Fortran contiguous, right data type) is neverthelessed\n    copied. (Hence, overwrite = True does not imply that acting on the\n    converted array in the return values will overwrite the original array in\n    all cases -- it does only so if the original array was already in the\n    correct format. The conversions require copying. In fact, that's the same\n    behavior as in SciPy, it's just not explicitly stated there)\n\n    If an argument is ``None``, it is just passed through and not used to\n    determine the proper LAPACK type.\n\n    `prepare_for_lapack` returns a character indicating the proper LAPACK data\n    type ('s', 'd', 'c', 'z') and a list of properly converted arrays.\n    ";
static PyMethodDef __pyx_mdef_5kwant_6linalg_6lapack_89prepare_for_lapack = {"prepare_for_lapack", (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_89prepare_for_lapack, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kwant_6linalg_6lapack_88prepare_for_lapack};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_89prepare_for_lapack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_overwrite = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("prepare_for_lapack (wrapper)", 0);
  if (PyTuple_GET_SIZE(__pyx_args) > 1) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 1, PyTuple_GET_SIZE(__pyx_args));
    if (unlikely(!__pyx_v_args)) {
      __Pyx_RefNannyFinishContext();
      return NULL;
    }
    __Pyx_GOTREF(__pyx_v_args);
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_overwrite,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) {
        default:
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_overwrite)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t used_pos_args = (pos_args < 1) ? pos_args : 1;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "prepare_for_lapack") < 0)) __PYX_ERR(0, 2463, __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_overwrite = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("prepare_for_lapack", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2463, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
  __Pyx_AddTraceback("kwant.linalg.lapack.prepare_for_lapack", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_88prepare_for_lapack(__pyx_self, __pyx_v_overwrite, __pyx_v_args);

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

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_88prepare_for_lapack(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_overwrite, PyObject *__pyx_v_args) {
  PyObject *__pyx_v_mats = NULL;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_v_arr = NULL;
  PyObject *__pyx_v_dtype = NULL;
  PyObject *__pyx_v_lapacktype = NULL;
  PyObject *__pyx_v_ret = NULL;
  PyObject *__pyx_v_npmat = NULL;
  PyObject *__pyx_v_ovwrt = NULL;
  PyObject *__pyx_8genexpr1__pyx_v_arr = NULL;
  CYTHON_UNUSED PyObject *__pyx_8genexpr1__pyx_v_ovwrt = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __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;
  PyObject *__pyx_t_13 = NULL;
  PyObject *(*__pyx_t_14)(PyObject *);
  int __pyx_t_15;
  __Pyx_TraceFrameInit(__pyx_codeobj__92)
  __Pyx_RefNannySetupContext("prepare_for_lapack", 0);
  __Pyx_TraceCall("prepare_for_lapack", __pyx_f[0], 2463, 0, __PYX_ERR(0, 2463, __pyx_L1_error));

  /* "kwant/linalg/lapack.pyx":2488
 * 
 *     # Make sure we have NumPy arrays
 *     mats = [None]*len(args)             # <<<<<<<<<<<<<<
 *     for i in range(len(args)):
 *         if args[i] is not None:
 */
  __Pyx_TraceLine(2488,0,__PYX_ERR(0, 2488, __pyx_L1_error))
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_args); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2488, __pyx_L1_error)
  __pyx_t_2 = PyList_New(1 * ((__pyx_t_1<0) ? 0:__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  { Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < __pyx_t_1; __pyx_temp++) {
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyList_SET_ITEM(__pyx_t_2, __pyx_temp, Py_None);
    }
  }
  __pyx_v_mats = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2489
 *     # Make sure we have NumPy arrays
 *     mats = [None]*len(args)
 *     for i in range(len(args)):             # <<<<<<<<<<<<<<
 *         if args[i] is not None:
 *             arr = np.asanyarray(args[i])
 */
  __Pyx_TraceLine(2489,0,__PYX_ERR(0, 2489, __pyx_L1_error))
  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_args); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2489, __pyx_L1_error)
  __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;

    /* "kwant/linalg/lapack.pyx":2490
 *     mats = [None]*len(args)
 *     for i in range(len(args)):
 *         if args[i] is not None:             # <<<<<<<<<<<<<<
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 */
    __Pyx_TraceLine(2490,0,__PYX_ERR(0, 2490, __pyx_L1_error))
    __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_args, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = (__pyx_t_2 != Py_None);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "kwant/linalg/lapack.pyx":2491
 *     for i in range(len(args)):
 *         if args[i] is not None:
 *             arr = np.asanyarray(args[i])             # <<<<<<<<<<<<<<
 *             if not np.issubdtype(arr.dtype, np.number):
 *                 raise ValueError("Argument cannot be interpreted "
 */
      __Pyx_TraceLine(2491,0,__PYX_ERR(0, 2491, __pyx_L1_error))
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_asanyarray); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_args, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (!__pyx_t_9) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2491, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2491, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2491, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2491, __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 = NULL;
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2491, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_arr, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":2492
 *         if args[i] is not None:
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):             # <<<<<<<<<<<<<<
 *                 raise ValueError("Argument cannot be interpreted "
 *                                  "as a numeric array")
 */
      __Pyx_TraceLine(2492,0,__PYX_ERR(0, 2492, __pyx_L1_error))
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_issubdtype); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_number); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_7);
          __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_7, __pyx_t_8, __pyx_t_9};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2492, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __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_10)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_9};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2492, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 2492, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_9);
        __pyx_t_8 = 0;
        __pyx_t_9 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2492, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2492, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_5 = ((!__pyx_t_6) != 0);
      if (unlikely(__pyx_t_5)) {

        /* "kwant/linalg/lapack.pyx":2493
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 *                 raise ValueError("Argument cannot be interpreted "             # <<<<<<<<<<<<<<
 *                                  "as a numeric array")
 * 
 */
        __Pyx_TraceLine(2493,0,__PYX_ERR(0, 2493, __pyx_L1_error))
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2493, __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, 2493, __pyx_L1_error)

        /* "kwant/linalg/lapack.pyx":2492
 *         if args[i] is not None:
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):             # <<<<<<<<<<<<<<
 *                 raise ValueError("Argument cannot be interpreted "
 *                                  "as a numeric array")
 */
      }

      /* "kwant/linalg/lapack.pyx":2496
 *                                  "as a numeric array")
 * 
 *             mats[i] = (arr, arr is not args[i] or overwrite)             # <<<<<<<<<<<<<<
 *         else:
 *             mats[i] = (None, True)
 */
      __Pyx_TraceLine(2496,0,__PYX_ERR(0, 2496, __pyx_L1_error))
      __pyx_t_10 = __Pyx_GetItemInt_Tuple(__pyx_v_args, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2496, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_5 = (__pyx_v_arr != __pyx_t_10);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (!__pyx_t_5) {
      } else {
        __pyx_t_10 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2496, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_2 = __pyx_t_10;
        __pyx_t_10 = 0;
        goto __pyx_L7_bool_binop_done;
      }
      __Pyx_INCREF(__pyx_v_overwrite);
      __pyx_t_2 = __pyx_v_overwrite;
      __pyx_L7_bool_binop_done:;
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2496, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_arr);
      __Pyx_GIVEREF(__pyx_v_arr);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_arr);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2);
      __pyx_t_2 = 0;
      if (unlikely(__Pyx_SetItemInt(__pyx_v_mats, __pyx_v_i, __pyx_t_10, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 2496, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "kwant/linalg/lapack.pyx":2490
 *     mats = [None]*len(args)
 *     for i in range(len(args)):
 *         if args[i] is not None:             # <<<<<<<<<<<<<<
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 */
      goto __pyx_L5;
    }

    /* "kwant/linalg/lapack.pyx":2498
 *             mats[i] = (arr, arr is not args[i] or overwrite)
 *         else:
 *             mats[i] = (None, True)             # <<<<<<<<<<<<<<
 * 
 *     # First figure out common dtype
 */
    __Pyx_TraceLine(2498,0,__PYX_ERR(0, 2498, __pyx_L1_error))
    /*else*/ {
      if (unlikely(__Pyx_SetItemInt(__pyx_v_mats, __pyx_v_i, __pyx_tuple__94, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 2498, __pyx_L1_error)
    }
    __pyx_L5:;
  }

  /* "kwant/linalg/lapack.pyx":2503
 *     # Note: The return type of common_type is guaranteed to be a floating point
 *     #       kind.
 *     dtype = np.common_type(*[arr for arr, ovwrt in mats if arr is not None])             # <<<<<<<<<<<<<<
 * 
 *     if dtype == np.float32:
 */
  __Pyx_TraceLine(2503,0,__PYX_ERR(0, 2503, __pyx_L1_error))
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_common_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  { /* enter inner scope */
    __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2503, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_12 = __pyx_v_mats; __Pyx_INCREF(__pyx_t_12); __pyx_t_1 = 0;
    for (;;) {
      if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_12)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_9 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_9); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2503, __pyx_L11_error)
      #else
      __pyx_t_9 = PySequence_ITEM(__pyx_t_12, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2503, __pyx_L11_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
        PyObject* sequence = __pyx_t_9;
        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, 2503, __pyx_L11_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2503, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2503, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_13 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2503, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext;
        index = 0; __pyx_t_8 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_8)) goto __pyx_L14_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        index = 1; __pyx_t_7 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_7)) goto __pyx_L14_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 2) < 0) __PYX_ERR(0, 2503, __pyx_L11_error)
        __pyx_t_14 = NULL;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        goto __pyx_L15_unpacking_done;
        __pyx_L14_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_14 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 2503, __pyx_L11_error)
        __pyx_L15_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_arr, __pyx_t_8);
      __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_ovwrt, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_5 = (__pyx_8genexpr1__pyx_v_arr != Py_None);
      __pyx_t_6 = (__pyx_t_5 != 0);
      if (__pyx_t_6) {
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_10, (PyObject*)__pyx_8genexpr1__pyx_v_arr))) __PYX_ERR(0, 2503, __pyx_L11_error)
      }
    }
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_arr); __pyx_8genexpr1__pyx_v_arr = 0;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_ovwrt); __pyx_8genexpr1__pyx_v_ovwrt = 0;
    goto __pyx_L17_exit_scope;
    __pyx_L11_error:;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_arr); __pyx_8genexpr1__pyx_v_arr = 0;
    __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_ovwrt); __pyx_8genexpr1__pyx_v_ovwrt = 0;
    goto __pyx_L1_error;
    __pyx_L17_exit_scope:;
  } /* exit inner scope */
  __pyx_t_12 = PySequence_Tuple(__pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_v_dtype = __pyx_t_10;
  __pyx_t_10 = 0;

  /* "kwant/linalg/lapack.pyx":2505
 *     dtype = np.common_type(*[arr for arr, ovwrt in mats if arr is not None])
 * 
 *     if dtype == np.float32:             # <<<<<<<<<<<<<<
 *         lapacktype = 's'
 *     elif dtype == np.float64:
 */
  __Pyx_TraceLine(2505,0,__PYX_ERR(0, 2505, __pyx_L1_error))
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_float32); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_12, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2505, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (__pyx_t_6) {

    /* "kwant/linalg/lapack.pyx":2506
 * 
 *     if dtype == np.float32:
 *         lapacktype = 's'             # <<<<<<<<<<<<<<
 *     elif dtype == np.float64:
 *         lapacktype = 'd'
 */
    __Pyx_TraceLine(2506,0,__PYX_ERR(0, 2506, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_s);
    __pyx_v_lapacktype = __pyx_n_u_s;

    /* "kwant/linalg/lapack.pyx":2505
 *     dtype = np.common_type(*[arr for arr, ovwrt in mats if arr is not None])
 * 
 *     if dtype == np.float32:             # <<<<<<<<<<<<<<
 *         lapacktype = 's'
 *     elif dtype == np.float64:
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2507
 *     if dtype == np.float32:
 *         lapacktype = 's'
 *     elif dtype == np.float64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:
 */
  __Pyx_TraceLine(2507,0,__PYX_ERR(0, 2507, __pyx_L1_error))
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_float64); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2507, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_12, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2507, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2507, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (__pyx_t_6) {

    /* "kwant/linalg/lapack.pyx":2508
 *         lapacktype = 's'
 *     elif dtype == np.float64:
 *         lapacktype = 'd'             # <<<<<<<<<<<<<<
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'
 */
    __Pyx_TraceLine(2508,0,__PYX_ERR(0, 2508, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_d);
    __pyx_v_lapacktype = __pyx_n_u_d;

    /* "kwant/linalg/lapack.pyx":2507
 *     if dtype == np.float32:
 *         lapacktype = 's'
 *     elif dtype == np.float64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2509
 *     elif dtype == np.float64:
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:
 */
  __Pyx_TraceLine(2509,0,__PYX_ERR(0, 2509, __pyx_L1_error))
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_complex64); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_12, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2509, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2509, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (__pyx_t_6) {

    /* "kwant/linalg/lapack.pyx":2510
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'             # <<<<<<<<<<<<<<
 *     elif dtype == np.complex128:
 *         lapacktype = 'z'
 */
    __Pyx_TraceLine(2510,0,__PYX_ERR(0, 2510, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_c);
    __pyx_v_lapacktype = __pyx_n_u_c;

    /* "kwant/linalg/lapack.pyx":2509
 *     elif dtype == np.float64:
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2511
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:             # <<<<<<<<<<<<<<
 *         lapacktype = 'z'
 *     else:
 */
  __Pyx_TraceLine(2511,0,__PYX_ERR(0, 2511, __pyx_L1_error))
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_complex128); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_12, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (likely(__pyx_t_6)) {

    /* "kwant/linalg/lapack.pyx":2512
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:
 *         lapacktype = 'z'             # <<<<<<<<<<<<<<
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")
 */
    __Pyx_TraceLine(2512,0,__PYX_ERR(0, 2512, __pyx_L1_error))
    __Pyx_INCREF(__pyx_n_u_z);
    __pyx_v_lapacktype = __pyx_n_u_z;

    /* "kwant/linalg/lapack.pyx":2511
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:             # <<<<<<<<<<<<<<
 *         lapacktype = 'z'
 *     else:
 */
    goto __pyx_L18;
  }

  /* "kwant/linalg/lapack.pyx":2514
 *         lapacktype = 'z'
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")             # <<<<<<<<<<<<<<
 * 
 *     ret = [ lapacktype ]
 */
  __Pyx_TraceLine(2514,0,__PYX_ERR(0, 2514, __pyx_L1_error))
  /*else*/ {
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_AssertionError, __pyx_tuple__95, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2514, __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(0, 2514, __pyx_L1_error)
  }
  __pyx_L18:;

  /* "kwant/linalg/lapack.pyx":2516
 *         raise AssertionError("Unexpected data type from common_type")
 * 
 *     ret = [ lapacktype ]             # <<<<<<<<<<<<<<
 *     for npmat, ovwrt in mats:
 *         # Now make sure that the array is contiguous, and copy if necessary.
 */
  __Pyx_TraceLine(2516,0,__PYX_ERR(0, 2516, __pyx_L1_error))
  __pyx_t_10 = PyList_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2516, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_v_lapacktype);
  __Pyx_GIVEREF(__pyx_v_lapacktype);
  PyList_SET_ITEM(__pyx_t_10, 0, __pyx_v_lapacktype);
  __pyx_v_ret = ((PyObject*)__pyx_t_10);
  __pyx_t_10 = 0;

  /* "kwant/linalg/lapack.pyx":2517
 * 
 *     ret = [ lapacktype ]
 *     for npmat, ovwrt in mats:             # <<<<<<<<<<<<<<
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:
 */
  __Pyx_TraceLine(2517,0,__PYX_ERR(0, 2517, __pyx_L1_error))
  __pyx_t_10 = __pyx_v_mats; __Pyx_INCREF(__pyx_t_10); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_10)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_12 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_12); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2517, __pyx_L1_error)
    #else
    __pyx_t_12 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
      PyObject* sequence = __pyx_t_12;
      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, 2517, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_14 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_14(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_9 = __pyx_t_14(__pyx_t_7); if (unlikely(!__pyx_t_9)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2517, __pyx_L1_error)
      __pyx_t_14 = NULL;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L22_unpacking_done;
      __pyx_L21_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_14 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2517, __pyx_L1_error)
      __pyx_L22_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_npmat, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ovwrt, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "kwant/linalg/lapack.pyx":2519
 *     for npmat, ovwrt in mats:
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:             # <<<<<<<<<<<<<<
 *             if npmat.ndim == 2:
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 */
    __Pyx_TraceLine(2519,0,__PYX_ERR(0, 2519, __pyx_L1_error))
    __pyx_t_6 = (__pyx_v_npmat != Py_None);
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "kwant/linalg/lapack.pyx":2520
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:
 *             if npmat.ndim == 2:             # <<<<<<<<<<<<<<
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 */
      __Pyx_TraceLine(2520,0,__PYX_ERR(0, 2520, __pyx_L1_error))
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_ndim); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_9 = __Pyx_PyInt_EqObjC(__pyx_t_12, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2520, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_5) {

        /* "kwant/linalg/lapack.pyx":2521
 *         if npmat is not None:
 *             if npmat.ndim == 2:
 *                 if not npmat.flags["F_CONTIGUOUS"]:             # <<<<<<<<<<<<<<
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 */
        __Pyx_TraceLine(2521,0,__PYX_ERR(0, 2521, __pyx_L1_error))
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_flags); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2521, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_12 = __Pyx_PyObject_Dict_GetItem(__pyx_t_9, __pyx_n_u_F_CONTIGUOUS); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2521, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2521, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_6 = ((!__pyx_t_5) != 0);
        if (__pyx_t_6) {

          /* "kwant/linalg/lapack.pyx":2522
 *             if npmat.ndim == 2:
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)             # <<<<<<<<<<<<<<
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 */
          __Pyx_TraceLine(2522,0,__PYX_ERR(0, 2522, __pyx_L1_error))
          __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_INCREF(__pyx_v_npmat);
          __Pyx_GIVEREF(__pyx_v_npmat);
          PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_npmat);
          __pyx_t_2 = __Pyx_PyDict_NewPresized(1); 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_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 2522, __pyx_L1_error)
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "kwant/linalg/lapack.pyx":2521
 *         if npmat is not None:
 *             if npmat.ndim == 2:
 *                 if not npmat.flags["F_CONTIGUOUS"]:             # <<<<<<<<<<<<<<
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 */
          goto __pyx_L25;
        }

        /* "kwant/linalg/lapack.pyx":2523
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
        __Pyx_TraceLine(2523,0,__PYX_ERR(0, 2523, __pyx_L1_error))
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_dtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2523, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_7, __pyx_v_dtype, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2523, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2523, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__pyx_t_6) {

          /* "kwant/linalg/lapack.pyx":2524
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)             # <<<<<<<<<<<<<<
 *                 elif not ovwrt:
 *                     # ugly here: copy makes always C-array, no way to tell it
 */
          __Pyx_TraceLine(2524,0,__PYX_ERR(0, 2524, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2524, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_12 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(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);
            }
          }
          if (!__pyx_t_12) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_dtype};
              __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_2);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_dtype};
              __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_2);
            } else
            #endif
            {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2524, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_12); __pyx_t_12 = NULL;
              __Pyx_INCREF(__pyx_v_dtype);
              __Pyx_GIVEREF(__pyx_v_dtype);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_dtype);
              __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "kwant/linalg/lapack.pyx":2523
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
          goto __pyx_L25;
        }

        /* "kwant/linalg/lapack.pyx":2525
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:             # <<<<<<<<<<<<<<
 *                     # ugly here: copy makes always C-array, no way to tell it
 *                     # to make a Fortran array.
 */
        __Pyx_TraceLine(2525,0,__PYX_ERR(0, 2525, __pyx_L1_error))
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_ovwrt); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2525, __pyx_L1_error)
        __pyx_t_5 = ((!__pyx_t_6) != 0);
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2528
 *                     # ugly here: copy makes always C-array, no way to tell it
 *                     # to make a Fortran array.
 *                     npmat = np.asfortranarray(npmat.copy())             # <<<<<<<<<<<<<<
 *             elif npmat.ndim == 1:
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 */
          __Pyx_TraceLine(2528,0,__PYX_ERR(0, 2528, __pyx_L1_error))
          __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2528, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2528, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_copy); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2528, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_8 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_12);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_12, function);
            }
          }
          if (__pyx_t_8) {
            __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2528, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          } else {
            __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2528, __pyx_L1_error)
          }
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_12)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_12);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
            }
          }
          if (!__pyx_t_12) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2528, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_2);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_7};
              __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2528, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_7};
              __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2528, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2528, __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 = NULL;
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2528, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "kwant/linalg/lapack.pyx":2525
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:             # <<<<<<<<<<<<<<
 *                     # ugly here: copy makes always C-array, no way to tell it
 *                     # to make a Fortran array.
 */
        }
        __pyx_L25:;

        /* "kwant/linalg/lapack.pyx":2520
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:
 *             if npmat.ndim == 2:             # <<<<<<<<<<<<<<
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 */
        goto __pyx_L24;
      }

      /* "kwant/linalg/lapack.pyx":2529
 *                     # to make a Fortran array.
 *                     npmat = np.asfortranarray(npmat.copy())
 *             elif npmat.ndim == 1:             # <<<<<<<<<<<<<<
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 */
      __Pyx_TraceLine(2529,0,__PYX_ERR(0, 2529, __pyx_L1_error))
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2529, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2529, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2529, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (likely(__pyx_t_5)) {

        /* "kwant/linalg/lapack.pyx":2530
 *                     npmat = np.asfortranarray(npmat.copy())
 *             elif npmat.ndim == 1:
 *                 if not npmat.flags["C_CONTIGUOUS"]:             # <<<<<<<<<<<<<<
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 */
        __Pyx_TraceLine(2530,0,__PYX_ERR(0, 2530, __pyx_L1_error))
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_flags); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2530, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_9, __pyx_n_u_C_CONTIGUOUS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2530, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2530, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_6 = ((!__pyx_t_5) != 0);
        if (__pyx_t_6) {

          /* "kwant/linalg/lapack.pyx":2531
 *             elif npmat.ndim == 1:
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)             # <<<<<<<<<<<<<<
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 */
          __Pyx_TraceLine(2531,0,__PYX_ERR(0, 2531, __pyx_L1_error))
          __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2531, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2531, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2531, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_v_npmat);
          __Pyx_GIVEREF(__pyx_v_npmat);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_npmat);
          __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2531, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 2531, __pyx_L1_error)
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2531, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "kwant/linalg/lapack.pyx":2530
 *                     npmat = np.asfortranarray(npmat.copy())
 *             elif npmat.ndim == 1:
 *                 if not npmat.flags["C_CONTIGUOUS"]:             # <<<<<<<<<<<<<<
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 */
          goto __pyx_L26;
        }

        /* "kwant/linalg/lapack.pyx":2532
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
        __Pyx_TraceLine(2532,0,__PYX_ERR(0, 2532, __pyx_L1_error))
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_dtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2532, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_v_dtype, Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2532, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2532, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__pyx_t_6) {

          /* "kwant/linalg/lapack.pyx":2533
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)             # <<<<<<<<<<<<<<
 *                 elif not ovwrt:
 *                     npmat = np.asfortranarray(npmat.copy())
 */
          __Pyx_TraceLine(2533,0,__PYX_ERR(0, 2533, __pyx_L1_error))
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2533, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_2 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          if (!__pyx_t_2) {
            __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2533, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_dtype};
              __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2533, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_GOTREF(__pyx_t_8);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_dtype};
              __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2533, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_GOTREF(__pyx_t_8);
            } else
            #endif
            {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2533, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); __pyx_t_2 = NULL;
              __Pyx_INCREF(__pyx_v_dtype);
              __Pyx_GIVEREF(__pyx_v_dtype);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_dtype);
              __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2533, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_8);
          __pyx_t_8 = 0;

          /* "kwant/linalg/lapack.pyx":2532
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
          goto __pyx_L26;
        }

        /* "kwant/linalg/lapack.pyx":2534
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:             # <<<<<<<<<<<<<<
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 */
        __Pyx_TraceLine(2534,0,__PYX_ERR(0, 2534, __pyx_L1_error))
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_ovwrt); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2534, __pyx_L1_error)
        __pyx_t_5 = ((!__pyx_t_6) != 0);
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2535
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 *                     npmat = np.asfortranarray(npmat.copy())             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")
 */
          __Pyx_TraceLine(2535,0,__PYX_ERR(0, 2535, __pyx_L1_error))
          __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2535, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_asfortranarray); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2535, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2535, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_12 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_12)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_12);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
            }
          }
          if (__pyx_t_12) {
            __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2535, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          } else {
            __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2535, __pyx_L1_error)
          }
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_2); __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);
            }
          }
          if (!__pyx_t_2) {
            __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2535, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_8);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_7};
              __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2535, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_7};
              __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2535, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2535, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_12);
              __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); __pyx_t_2 = NULL;
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2535, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF_SET(__pyx_v_npmat, __pyx_t_8);
          __pyx_t_8 = 0;

          /* "kwant/linalg/lapack.pyx":2534
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:             # <<<<<<<<<<<<<<
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 */
        }
        __pyx_L26:;

        /* "kwant/linalg/lapack.pyx":2529
 *                     # to make a Fortran array.
 *                     npmat = np.asfortranarray(npmat.copy())
 *             elif npmat.ndim == 1:             # <<<<<<<<<<<<<<
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 */
        goto __pyx_L24;
      }

      /* "kwant/linalg/lapack.pyx":2537
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")             # <<<<<<<<<<<<<<
 * 
 *         ret.append(npmat)
 */
      __Pyx_TraceLine(2537,0,__PYX_ERR(0, 2537, __pyx_L1_error))
      /*else*/ {
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__96, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2537, __pyx_L1_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(0, 2537, __pyx_L1_error)
      }
      __pyx_L24:;

      /* "kwant/linalg/lapack.pyx":2519
 *     for npmat, ovwrt in mats:
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:             # <<<<<<<<<<<<<<
 *             if npmat.ndim == 2:
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 */
    }

    /* "kwant/linalg/lapack.pyx":2539
 *                 raise ValueError("Dimensionality of array is not 1 or 2")
 * 
 *         ret.append(npmat)             # <<<<<<<<<<<<<<
 * 
 *     return tuple(ret)
 */
    __Pyx_TraceLine(2539,0,__PYX_ERR(0, 2539, __pyx_L1_error))
    __pyx_t_15 = __Pyx_PyList_Append(__pyx_v_ret, __pyx_v_npmat); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 2539, __pyx_L1_error)

    /* "kwant/linalg/lapack.pyx":2517
 * 
 *     ret = [ lapacktype ]
 *     for npmat, ovwrt in mats:             # <<<<<<<<<<<<<<
 *         # Now make sure that the array is contiguous, and copy if necessary.
 *         if npmat is not None:
 */
    __Pyx_TraceLine(2517,0,__PYX_ERR(0, 2517, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "kwant/linalg/lapack.pyx":2541
 *         ret.append(npmat)
 * 
 *     return tuple(ret)             # <<<<<<<<<<<<<<
 */
  __Pyx_TraceLine(2541,0,__PYX_ERR(0, 2541, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_10 = PyList_AsTuple(__pyx_v_ret); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2541, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_r = __pyx_t_10;
  __pyx_t_10 = 0;
  goto __pyx_L0;

  /* "kwant/linalg/lapack.pyx":2463
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __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_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("kwant.linalg.lapack.prepare_for_lapack", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mats);
  __Pyx_XDECREF(__pyx_v_arr);
  __Pyx_XDECREF(__pyx_v_dtype);
  __Pyx_XDECREF(__pyx_v_lapacktype);
  __Pyx_XDECREF(__pyx_v_ret);
  __Pyx_XDECREF(__pyx_v_npmat);
  __Pyx_XDECREF(__pyx_v_ovwrt);
  __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_arr);
  __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_ovwrt);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":215
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__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_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  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], 215, 0, __PYX_ERR(1, 215, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":222
 * 
 *             cdef int i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __Pyx_TraceLine(222,0,__PYX_ERR(1, 222, __pyx_L1_error))
  __pyx_v_endian_detector = 1;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":223
 *             cdef int i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __Pyx_TraceLine(223,0,__PYX_ERR(1, 223, __pyx_L1_error))
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":225
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
  __Pyx_TraceLine(225,0,__PYX_ERR(1, 225, __pyx_L1_error))
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __Pyx_TraceLine(227,0,__PYX_ERR(1, 227, __pyx_L1_error))
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":228
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
  __Pyx_TraceLine(228,0,__PYX_ERR(1, 228, __pyx_L1_error))
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __Pyx_TraceLine(227,0,__PYX_ERR(1, 227, __pyx_L1_error))
  if (unlikely(__pyx_t_1)) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":229
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __Pyx_TraceLine(229,0,__PYX_ERR(1, 229, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__97, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 229, __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, 229, __pyx_L1_error)

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __Pyx_TraceLine(231,0,__PYX_ERR(1, 231, __pyx_L1_error))
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":232
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
  __Pyx_TraceLine(232,0,__PYX_ERR(1, 232, __pyx_L1_error))
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __Pyx_TraceLine(231,0,__PYX_ERR(1, 231, __pyx_L1_error))
  if (unlikely(__pyx_t_1)) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":233
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __Pyx_TraceLine(233,0,__PYX_ERR(1, 233, __pyx_L1_error))
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__98, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 233, __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, 233, __pyx_L1_error)

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":235
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __Pyx_TraceLine(235,0,__PYX_ERR(1, 235, __pyx_L1_error))
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":236
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 # Allocate new buffer for strides and shape info.
 */
  __Pyx_TraceLine(236,0,__PYX_ERR(1, 236, __pyx_L1_error))
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":237
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  __Pyx_TraceLine(237,0,__PYX_ERR(1, 237, __pyx_L1_error))
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":240
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __Pyx_TraceLine(240,0,__PYX_ERR(1, 240, __pyx_L1_error))
    __pyx_v_info->strides = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * 2) * ((size_t)__pyx_v_ndim))));

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":241
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __Pyx_TraceLine(241,0,__PYX_ERR(1, 241, __pyx_L1_error))
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":242
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __Pyx_TraceLine(242,0,__PYX_ERR(1, 242, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_ndim;
    __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;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":243
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      __Pyx_TraceLine(243,0,__PYX_ERR(1, 243, __pyx_L1_error))
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":244
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      __Pyx_TraceLine(244,0,__PYX_ERR(1, 244, __pyx_L1_error))
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":237
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
    goto __pyx_L9;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":246
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
  __Pyx_TraceLine(246,0,__PYX_ERR(1, 246, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":247
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __Pyx_TraceLine(247,0,__PYX_ERR(1, 247, __pyx_L1_error))
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L9:;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":248
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __Pyx_TraceLine(248,0,__PYX_ERR(1, 248, __pyx_L1_error))
  __pyx_v_info->suboffsets = NULL;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":249
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __Pyx_TraceLine(249,0,__PYX_ERR(1, 249, __pyx_L1_error))
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":250
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __Pyx_TraceLine(250,0,__PYX_ERR(1, 250, __pyx_L1_error))
  __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":253
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef int offset
 */
  __Pyx_TraceLine(253,0,__PYX_ERR(1, 253, __pyx_L1_error))
  __pyx_v_f = NULL;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":254
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef int offset
 * 
 */
  __Pyx_TraceLine(254,0,__PYX_ERR(1, 254, __pyx_L1_error))
  __pyx_t_3 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":257
 *             cdef int offset
 * 
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not PyDataType_HASFIELDS(descr):
 */
  __Pyx_TraceLine(257,0,__PYX_ERR(1, 257, __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);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":259
 *             info.obj = self
 * 
 *             if not PyDataType_HASFIELDS(descr):             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __Pyx_TraceLine(259,0,__PYX_ERR(1, 259, __pyx_L1_error))
  __pyx_t_1 = ((!(PyDataType_HASFIELDS(__pyx_v_descr) != 0)) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":260
 * 
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __Pyx_TraceLine(260,0,__PYX_ERR(1, 260, __pyx_L1_error))
    __pyx_t_4 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_4;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __Pyx_TraceLine(261,0,__PYX_ERR(1, 261, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '>') != 0);
    if (!__pyx_t_2) {
      goto __pyx_L15_next_or;
    } else {
    }
    __pyx_t_2 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_L15_next_or:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":262
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
    __Pyx_TraceLine(262,0,__PYX_ERR(1, 262, __pyx_L1_error))
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '<') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_2 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L14_bool_binop_done:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __Pyx_TraceLine(261,0,__PYX_ERR(1, 261, __pyx_L1_error))
    if (unlikely(__pyx_t_1)) {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __Pyx_TraceLine(263,0,__PYX_ERR(1, 263, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__99, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 263, __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, 263, __pyx_L1_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":264
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    __Pyx_TraceLine(264,0,__PYX_ERR(1, 264, __pyx_L1_error))
    switch (__pyx_v_t) {
      case NPY_BYTE:
      __pyx_v_f = ((char *)"b");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":265
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
      __Pyx_TraceLine(265,0,__PYX_ERR(1, 265, __pyx_L1_error))
      case NPY_UBYTE:
      __pyx_v_f = ((char *)"B");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":266
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
      __Pyx_TraceLine(266,0,__PYX_ERR(1, 266, __pyx_L1_error))
      case NPY_SHORT:
      __pyx_v_f = ((char *)"h");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":267
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
      __Pyx_TraceLine(267,0,__PYX_ERR(1, 267, __pyx_L1_error))
      case NPY_USHORT:
      __pyx_v_f = ((char *)"H");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":268
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
      __Pyx_TraceLine(268,0,__PYX_ERR(1, 268, __pyx_L1_error))
      case NPY_INT:
      __pyx_v_f = ((char *)"i");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":269
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
      __Pyx_TraceLine(269,0,__PYX_ERR(1, 269, __pyx_L1_error))
      case NPY_UINT:
      __pyx_v_f = ((char *)"I");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":270
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
      __Pyx_TraceLine(270,0,__PYX_ERR(1, 270, __pyx_L1_error))
      case NPY_LONG:
      __pyx_v_f = ((char *)"l");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":271
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
      __Pyx_TraceLine(271,0,__PYX_ERR(1, 271, __pyx_L1_error))
      case NPY_ULONG:
      __pyx_v_f = ((char *)"L");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":272
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
      __Pyx_TraceLine(272,0,__PYX_ERR(1, 272, __pyx_L1_error))
      case NPY_LONGLONG:
      __pyx_v_f = ((char *)"q");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":273
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
      __Pyx_TraceLine(273,0,__PYX_ERR(1, 273, __pyx_L1_error))
      case NPY_ULONGLONG:
      __pyx_v_f = ((char *)"Q");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":274
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
      __Pyx_TraceLine(274,0,__PYX_ERR(1, 274, __pyx_L1_error))
      case NPY_FLOAT:
      __pyx_v_f = ((char *)"f");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":275
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
      __Pyx_TraceLine(275,0,__PYX_ERR(1, 275, __pyx_L1_error))
      case NPY_DOUBLE:
      __pyx_v_f = ((char *)"d");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":276
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
      __Pyx_TraceLine(276,0,__PYX_ERR(1, 276, __pyx_L1_error))
      case NPY_LONGDOUBLE:
      __pyx_v_f = ((char *)"g");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":277
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
      __Pyx_TraceLine(277,0,__PYX_ERR(1, 277, __pyx_L1_error))
      case NPY_CFLOAT:
      __pyx_v_f = ((char *)"Zf");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":278
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
      __Pyx_TraceLine(278,0,__PYX_ERR(1, 278, __pyx_L1_error))
      case NPY_CDOUBLE:
      __pyx_v_f = ((char *)"Zd");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":279
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
      __Pyx_TraceLine(279,0,__PYX_ERR(1, 279, __pyx_L1_error))
      case NPY_CLONGDOUBLE:
      __pyx_v_f = ((char *)"Zg");
      break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":280
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __Pyx_TraceLine(280,0,__PYX_ERR(1, 280, __pyx_L1_error))
      case NPY_OBJECT:
      __pyx_v_f = ((char *)"O");
      break;
      default:

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":282
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __Pyx_TraceLine(282,0,__PYX_ERR(1, 282, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(1, 282, __pyx_L1_error)
      break;
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":283
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __Pyx_TraceLine(283,0,__PYX_ERR(1, 283, __pyx_L1_error))
    __pyx_v_info->format = __pyx_v_f;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":284
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 */
    __Pyx_TraceLine(284,0,__PYX_ERR(1, 284, __pyx_L1_error))
    __pyx_r = 0;
    goto __pyx_L0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":259
 *             info.obj = self
 * 
 *             if not PyDataType_HASFIELDS(descr):             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":286
 *                 return
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
  __Pyx_TraceLine(286,0,__PYX_ERR(1, 286, __pyx_L1_error))
  /*else*/ {
    __pyx_v_info->format = ((char *)PyObject_Malloc(0xFF));

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":287
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    __Pyx_TraceLine(287,0,__PYX_ERR(1, 287, __pyx_L1_error))
    (__pyx_v_info->format[0]) = '^';

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":288
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __Pyx_TraceLine(288,0,__PYX_ERR(1, 288, __pyx_L1_error))
    __pyx_v_offset = 0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":289
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,             # <<<<<<<<<<<<<<
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 */
    __Pyx_TraceLine(289,0,__PYX_ERR(1, 289, __pyx_L1_error))
    __pyx_t_8 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 0xFF), (&__pyx_v_offset)); if (unlikely(__pyx_t_8 == ((char *)NULL))) __PYX_ERR(1, 289, __pyx_L1_error)
    __pyx_v_f = __pyx_t_8;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":292
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    __Pyx_TraceLine(292,0,__PYX_ERR(1, 292, __pyx_L1_error))
    (__pyx_v_f[0]) = '\x00';
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":215
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("numpy.ndarray.__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_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);
  __Pyx_TraceCall("__releasebuffer__", __pyx_f[1], 294, 0, __PYX_ERR(1, 294, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":295
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __Pyx_TraceLine(295,0,__PYX_ERR(1, 295, __pyx_L1_error))
  __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":296
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 PyObject_Free(info.strides)
 */
    __Pyx_TraceLine(296,0,__PYX_ERR(1, 296, __pyx_L1_error))
    PyObject_Free(__pyx_v_info->format);

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":295
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":297
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __Pyx_TraceLine(297,0,__PYX_ERR(1, 297, __pyx_L1_error))
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":298
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 PyObject_Free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    __Pyx_TraceLine(298,0,__PYX_ERR(1, 298, __pyx_L1_error))
    PyObject_Free(__pyx_v_info->strides);

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":297
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("numpy.ndarray.__releasebuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":775
 * 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;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew1", __pyx_f[1], 775, 0, __PYX_ERR(1, 775, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":776
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_TraceLine(776,0,__PYX_ERR(1, 776, __pyx_L1_error))
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":775
 * 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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":778
 *     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;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew2", __pyx_f[1], 778, 0, __PYX_ERR(1, 778, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":779
 * 
 * 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(779,0,__PYX_ERR(1, 779, __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(1, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":778
 *     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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":781
 *     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;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew3", __pyx_f[1], 781, 0, __PYX_ERR(1, 781, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":782
 * 
 * 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(782,0,__PYX_ERR(1, 782, __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(1, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":781
 *     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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":784
 *     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;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew4", __pyx_f[1], 784, 0, __PYX_ERR(1, 784, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":785
 * 
 * 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(785,0,__PYX_ERR(1, 785, __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(1, 785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":784
 *     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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":787
 *     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;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);
  __Pyx_TraceCall("PyArray_MultiIterNew5", __pyx_f[1], 787, 0, __PYX_ERR(1, 787, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":788
 * 
 * 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(788,0,__PYX_ERR(1, 788, __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(1, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":787
 *     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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":790
 *     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;
  __Pyx_RefNannySetupContext("PyDataType_SHAPE", 0);
  __Pyx_TraceCall("PyDataType_SHAPE", __pyx_f[1], 790, 0, __PYX_ERR(1, 790, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":791
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  __Pyx_TraceLine(791,0,__PYX_ERR(1, 791, __pyx_L1_error))
  __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":792
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape             # <<<<<<<<<<<<<<
 *     else:
 *         return ()
 */
    __Pyx_TraceLine(792,0,__PYX_ERR(1, 792, __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;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":791
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":794
 *         return <tuple>d.subarray.shape
 *     else:
 *         return ()             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __Pyx_TraceLine(794,0,__PYX_ERR(1, 794, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_empty_tuple);
    __pyx_r = __pyx_empty_tuple;
    goto __pyx_L0;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":790
 *     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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":796
 *         return ()
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  long __pyx_t_8;
  char *__pyx_t_9;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);
  __Pyx_TraceCall("_util_dtypestring", __pyx_f[1], 796, 0, __PYX_ERR(1, 796, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":801
 * 
 *     cdef dtype child
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __Pyx_TraceLine(801,0,__PYX_ERR(1, 801, __pyx_L1_error))
  __pyx_v_endian_detector = 1;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":802
 *     cdef dtype child
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __Pyx_TraceLine(802,0,__PYX_ERR(1, 802, __pyx_L1_error))
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":805
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  __Pyx_TraceLine(805,0,__PYX_ERR(1, 805, __pyx_L1_error))
  if (unlikely(__pyx_v_descr->names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(1, 805, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 805, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":806
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    __Pyx_TraceLine(806,0,__PYX_ERR(1, 806, __pyx_L1_error))
    if (unlikely(__pyx_v_descr->fields == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 806, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 806, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 806, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":807
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 */
    __Pyx_TraceLine(807,0,__PYX_ERR(1, 807, __pyx_L1_error))
    if (likely(__pyx_v_fields != Py_None)) {
      PyObject* sequence = __pyx_v_fields;
      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, 807, __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, 807, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 807, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 807, __pyx_L1_error)
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) __PYX_ERR(1, 807, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3));
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":809
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __Pyx_TraceLine(809,0,__PYX_ERR(1, 809, __pyx_L1_error))
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 809, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 809, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 809, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0);
    if (unlikely(__pyx_t_6)) {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":810
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
      __Pyx_TraceLine(810,0,__PYX_ERR(1, 810, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__100, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 810, __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, 810, __pyx_L1_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":809
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __Pyx_TraceLine(812,0,__PYX_ERR(1, 812, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_child->byteorder == '>') != 0);
    if (!__pyx_t_7) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_7 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":813
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
    __Pyx_TraceLine(813,0,__PYX_ERR(1, 813, __pyx_L1_error))
    __pyx_t_7 = ((__pyx_v_child->byteorder == '<') != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_7 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_6 = __pyx_t_7;
    __pyx_L7_bool_binop_done:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __Pyx_TraceLine(812,0,__PYX_ERR(1, 812, __pyx_L1_error))
    if (unlikely(__pyx_t_6)) {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":814
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __Pyx_TraceLine(814,0,__PYX_ERR(1, 814, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__101, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 814, __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, 814, __pyx_L1_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":824
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    __Pyx_TraceLine(824,0,__PYX_ERR(1, 824, __pyx_L1_error))
    while (1) {
      __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 824, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 824, __pyx_L1_error)
      __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(1, 824, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!__pyx_t_6) break;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":825
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      __Pyx_TraceLine(825,0,__PYX_ERR(1, 825, __pyx_L1_error))
      (__pyx_v_f[0]) = 0x78;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":826
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __Pyx_TraceLine(826,0,__PYX_ERR(1, 826, __pyx_L1_error))
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":827
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __Pyx_TraceLine(827,0,__PYX_ERR(1, 827, __pyx_L1_error))
      __pyx_t_8 = 0;
      (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + 1);
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":829
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __Pyx_TraceLine(829,0,__PYX_ERR(1, 829, __pyx_L1_error))
    __pyx_t_8 = 0;
    (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + __pyx_v_child->elsize);

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":831
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __Pyx_TraceLine(831,0,__PYX_ERR(1, 831, __pyx_L1_error))
    __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0);
    if (__pyx_t_6) {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":832
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __Pyx_TraceLine(832,0,__PYX_ERR(1, 832, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":833
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __Pyx_TraceLine(833,0,__PYX_ERR(1, 833, __pyx_L1_error))
      __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0);
      if (unlikely(__pyx_t_6)) {

        /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":834
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __Pyx_TraceLine(834,0,__PYX_ERR(1, 834, __pyx_L1_error))
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__102, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 834, __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(1, 834, __pyx_L1_error)

        /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":833
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":837
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __Pyx_TraceLine(837,0,__PYX_ERR(1, 837, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_BYTE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 837, __pyx_L1_error)
      __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(1, 837, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":838
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __Pyx_TraceLine(838,0,__PYX_ERR(1, 838, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UBYTE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 838, __pyx_L1_error)
      __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(1, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":839
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __Pyx_TraceLine(839,0,__PYX_ERR(1, 839, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_SHORT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 839, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 839, __pyx_L1_error)
      __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(1, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x68;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":840
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __Pyx_TraceLine(840,0,__PYX_ERR(1, 840, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_USHORT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 840, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 840, __pyx_L1_error)
      __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(1, 840, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":841
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __Pyx_TraceLine(841,0,__PYX_ERR(1, 841, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_INT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 841, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 841, __pyx_L1_error)
      __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(1, 841, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x69;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":842
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __Pyx_TraceLine(842,0,__PYX_ERR(1, 842, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UINT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 842, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 842, __pyx_L1_error)
      __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(1, 842, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":843
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __Pyx_TraceLine(843,0,__PYX_ERR(1, 843, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 843, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 843, __pyx_L1_error)
      __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(1, 843, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x6C;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":844
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __Pyx_TraceLine(844,0,__PYX_ERR(1, 844, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 844, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 844, __pyx_L1_error)
      __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(1, 844, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":845
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __Pyx_TraceLine(845,0,__PYX_ERR(1, 845, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 845, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 845, __pyx_L1_error)
      __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(1, 845, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x71;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":846
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __Pyx_TraceLine(846,0,__PYX_ERR(1, 846, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 846, __pyx_L1_error)
      __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(1, 846, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":847
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __Pyx_TraceLine(847,0,__PYX_ERR(1, 847, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_FLOAT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 847, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 847, __pyx_L1_error)
      __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(1, 847, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x66;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":848
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __Pyx_TraceLine(848,0,__PYX_ERR(1, 848, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 848, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 848, __pyx_L1_error)
      __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(1, 848, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x64;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":849
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __Pyx_TraceLine(849,0,__PYX_ERR(1, 849, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 849, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 849, __pyx_L1_error)
      __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(1, 849, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x67;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":850
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __Pyx_TraceLine(850,0,__PYX_ERR(1, 850, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 850, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 850, __pyx_L1_error)
      __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(1, 850, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x66;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":851
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __Pyx_TraceLine(851,0,__PYX_ERR(1, 851, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 851, __pyx_L1_error)
      __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(1, 851, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x64;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":852
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __Pyx_TraceLine(852,0,__PYX_ERR(1, 852, __pyx_L1_error))
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 852, __pyx_L1_error)
      __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(1, 852, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x67;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":853
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __Pyx_TraceLine(853,0,__PYX_ERR(1, 853, __pyx_L1_error))
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_OBJECT); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 853, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 853, __pyx_L1_error)
      __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(1, 853, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(__pyx_t_6)) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":855
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
      __Pyx_TraceLine(855,0,__PYX_ERR(1, 855, __pyx_L1_error))
      /*else*/ {
        __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 855, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 855, __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, 855, __pyx_L1_error)
      }
      __pyx_L15:;

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":856
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __Pyx_TraceLine(856,0,__PYX_ERR(1, 856, __pyx_L1_error))
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":831
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
      goto __pyx_L13;
    }

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":860
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
    __Pyx_TraceLine(860,0,__PYX_ERR(1, 860, __pyx_L1_error))
    /*else*/ {
      __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_9 == ((char *)NULL))) __PYX_ERR(1, 860, __pyx_L1_error)
      __pyx_v_f = __pyx_t_9;
    }
    __pyx_L13:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":805
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
    __Pyx_TraceLine(805,0,__PYX_ERR(1, 805, __pyx_L1_error))
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":861
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(861,0,__PYX_ERR(1, 861, __pyx_L1_error))
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":796
 *         return ()
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("set_array_base", 0);
  __Pyx_TraceCall("set_array_base", __pyx_f[1], 977, 0, __PYX_ERR(1, 977, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":979
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __Pyx_TraceLine(979,0,__PYX_ERR(1, 979, __pyx_L1_error))
  __pyx_t_1 = (__pyx_v_base == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":980
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __Pyx_TraceLine(980,0,__PYX_ERR(1, 980, __pyx_L1_error))
    __pyx_v_baseptr = NULL;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":979
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
    goto __pyx_L3;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":982
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
  __Pyx_TraceLine(982,0,__PYX_ERR(1, 982, __pyx_L1_error))
  /*else*/ {
    Py_INCREF(__pyx_v_base);

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":983
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __Pyx_TraceLine(983,0,__PYX_ERR(1, 983, __pyx_L1_error))
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":984
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  __Pyx_TraceLine(984,0,__PYX_ERR(1, 984, __pyx_L1_error))
  Py_XDECREF(__pyx_v_arr->base);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":985
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __Pyx_TraceLine(985,0,__PYX_ERR(1, 985, __pyx_L1_error))
  __pyx_v_arr->base = __pyx_v_baseptr;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

  /* 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();
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":987
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);
  __Pyx_TraceCall("get_array_base", __pyx_f[1], 987, 0, __PYX_ERR(1, 987, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":988
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __Pyx_TraceLine(988,0,__PYX_ERR(1, 988, __pyx_L1_error))
  __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":989
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_TraceLine(989,0,__PYX_ERR(1, 989, __pyx_L1_error))
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":988
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":991
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_TraceLine(991,0,__PYX_ERR(1, 991, __pyx_L1_error))
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":987
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

  /* 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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":996
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _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;
  __Pyx_RefNannySetupContext("import_array", 0);
  __Pyx_TraceCall("import_array", __pyx_f[1], 996, 0, __PYX_ERR(1, 996, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
  __Pyx_TraceLine(997,0,__PYX_ERR(1, 997, __pyx_L3_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:*/ {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":998
 * cdef inline int import_array() except -1:
 *     try:
 *         _import_array()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")
 */
      __Pyx_TraceLine(998,0,__PYX_ERR(1, 998, __pyx_L3_error))
      __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 998, __pyx_L3_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _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:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":999
 *     try:
 *         _import_array()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 */
    __Pyx_TraceLine(999,0,__PYX_ERR(1, 999, __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(1, 999, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1000
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
      __Pyx_TraceLine(1000,0,__PYX_ERR(1, 1000, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__103, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1000, __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(1, 1000, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _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:;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":996
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1002
 *         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;
  __Pyx_RefNannySetupContext("import_umath", 0);
  __Pyx_TraceCall("import_umath", __pyx_f[1], 1002, 0, __PYX_ERR(1, 1002, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  __Pyx_TraceLine(1003,0,__PYX_ERR(1, 1003, __pyx_L3_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:*/ {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1004
 * cdef inline int import_umath() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __Pyx_TraceLine(1004,0,__PYX_ERR(1, 1004, __pyx_L3_error))
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 1004, __pyx_L3_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * 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:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1005
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __Pyx_TraceLine(1005,0,__PYX_ERR(1, 1005, __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(1, 1005, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1006
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
      __Pyx_TraceLine(1006,0,__PYX_ERR(1, 1006, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__104, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1006, __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(1, 1006, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * 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:;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1002
 *         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;
}

/* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         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;
  __Pyx_RefNannySetupContext("import_ufunc", 0);
  __Pyx_TraceCall("import_ufunc", __pyx_f[1], 1008, 0, __PYX_ERR(1, 1008, __pyx_L1_error));

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  __Pyx_TraceLine(1009,0,__PYX_ERR(1, 1009, __pyx_L3_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:*/ {

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1010
 * cdef inline int import_ufunc() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __Pyx_TraceLine(1010,0,__PYX_ERR(1, 1010, __pyx_L3_error))
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 1010, __pyx_L3_error)

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * 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:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1011
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 */
    __Pyx_TraceLine(1011,0,__PYX_ERR(1, 1011, __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(1, 1011, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1012
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
      __Pyx_TraceLine(1012,0,__PYX_ERR(1, 1012, __pyx_L5_except_error))
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__105, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1012, __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(1, 1012, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * 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:;
  }

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         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;
}

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_lapack(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_lapack},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "lapack",
    __pyx_k_Low_level_access_to_LAPACK_funct, /* 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

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
  {&__pyx_kp_u_Argument_cannot_be_interpreted_a, __pyx_k_Argument_cannot_be_interpreted_a, sizeof(__pyx_k_Argument_cannot_be_interpreted_a), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_cgecon, __pyx_k_Argument_error_in_cgecon, sizeof(__pyx_k_Argument_error_in_cgecon), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_cgees, __pyx_k_Argument_error_in_cgees, sizeof(__pyx_k_Argument_error_in_cgees), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_cgetrf, __pyx_k_Argument_error_in_cgetrf, sizeof(__pyx_k_Argument_error_in_cgetrf), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_cgetrs, __pyx_k_Argument_error_in_cgetrs, sizeof(__pyx_k_Argument_error_in_cgetrs), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_cggev, __pyx_k_Argument_error_in_cggev, sizeof(__pyx_k_Argument_error_in_cggev), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ctgevc, __pyx_k_Argument_error_in_ctgevc, sizeof(__pyx_k_Argument_error_in_ctgevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ctgsen, __pyx_k_Argument_error_in_ctgsen, sizeof(__pyx_k_Argument_error_in_ctgsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ctrevc, __pyx_k_Argument_error_in_ctrevc, sizeof(__pyx_k_Argument_error_in_ctrevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ctrsen, __pyx_k_Argument_error_in_ctrsen, sizeof(__pyx_k_Argument_error_in_ctrsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dgecon, __pyx_k_Argument_error_in_dgecon, sizeof(__pyx_k_Argument_error_in_dgecon), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dgees, __pyx_k_Argument_error_in_dgees, sizeof(__pyx_k_Argument_error_in_dgees), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dgetrf, __pyx_k_Argument_error_in_dgetrf, sizeof(__pyx_k_Argument_error_in_dgetrf), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dgetrs, __pyx_k_Argument_error_in_dgetrs, sizeof(__pyx_k_Argument_error_in_dgetrs), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dggev, __pyx_k_Argument_error_in_dggev, sizeof(__pyx_k_Argument_error_in_dggev), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dtgevc, __pyx_k_Argument_error_in_dtgevc, sizeof(__pyx_k_Argument_error_in_dtgevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dtgsen, __pyx_k_Argument_error_in_dtgsen, sizeof(__pyx_k_Argument_error_in_dtgsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dtrevc, __pyx_k_Argument_error_in_dtrevc, sizeof(__pyx_k_Argument_error_in_dtrevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_dtrsen, __pyx_k_Argument_error_in_dtrsen, sizeof(__pyx_k_Argument_error_in_dtrsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_sgecon, __pyx_k_Argument_error_in_sgecon, sizeof(__pyx_k_Argument_error_in_sgecon), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_sgees, __pyx_k_Argument_error_in_sgees, sizeof(__pyx_k_Argument_error_in_sgees), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_sgetrf, __pyx_k_Argument_error_in_sgetrf, sizeof(__pyx_k_Argument_error_in_sgetrf), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_sgetrs, __pyx_k_Argument_error_in_sgetrs, sizeof(__pyx_k_Argument_error_in_sgetrs), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_sggev, __pyx_k_Argument_error_in_sggev, sizeof(__pyx_k_Argument_error_in_sggev), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_stgevc, __pyx_k_Argument_error_in_stgevc, sizeof(__pyx_k_Argument_error_in_stgevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_stgsen, __pyx_k_Argument_error_in_stgsen, sizeof(__pyx_k_Argument_error_in_stgsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_strevc, __pyx_k_Argument_error_in_strevc, sizeof(__pyx_k_Argument_error_in_strevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_strsen, __pyx_k_Argument_error_in_strsen, sizeof(__pyx_k_Argument_error_in_strsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_zgecon, __pyx_k_Argument_error_in_zgecon, sizeof(__pyx_k_Argument_error_in_zgecon), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_zgees, __pyx_k_Argument_error_in_zgees, sizeof(__pyx_k_Argument_error_in_zgees), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_zgetrf, __pyx_k_Argument_error_in_zgetrf, sizeof(__pyx_k_Argument_error_in_zgetrf), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_zgetrs, __pyx_k_Argument_error_in_zgetrs, sizeof(__pyx_k_Argument_error_in_zgetrs), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_zggev, __pyx_k_Argument_error_in_zggev, sizeof(__pyx_k_Argument_error_in_zggev), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ztgevc, __pyx_k_Argument_error_in_ztgevc, sizeof(__pyx_k_Argument_error_in_ztgevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ztgsen, __pyx_k_Argument_error_in_ztgsen, sizeof(__pyx_k_Argument_error_in_ztgsen), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ztrevc, __pyx_k_Argument_error_in_ztrevc, sizeof(__pyx_k_Argument_error_in_ztrevc), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_error_in_ztrsen, __pyx_k_Argument_error_in_ztrsen, sizeof(__pyx_k_Argument_error_in_ztrsen), 0, 1, 0, 0},
  {&__pyx_n_s_AssertionError, __pyx_k_AssertionError, sizeof(__pyx_k_AssertionError), 0, 0, 1, 1},
  {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1},
  {&__pyx_n_u_C_CONTIGUOUS, __pyx_k_C_CONTIGUOUS, sizeof(__pyx_k_C_CONTIGUOUS), 0, 1, 0, 1},
  {&__pyx_kp_u_Dimensionality_of_array_is_not_1, __pyx_k_Dimensionality_of_array_is_not_1, sizeof(__pyx_k_Dimensionality_of_array_is_not_1), 0, 1, 0, 0},
  {&__pyx_n_u_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 1, 0, 1},
  {&__pyx_n_u_F_CONTIGUOUS, __pyx_k_F_CONTIGUOUS, sizeof(__pyx_k_F_CONTIGUOUS), 0, 1, 0, 1},
  {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0},
  {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0},
  {&__pyx_n_s_IPIV, __pyx_k_IPIV, sizeof(__pyx_k_IPIV), 0, 0, 1, 1},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_kp_u_In_cgetrs_B_must_be_a_vector_or, __pyx_k_In_cgetrs_B_must_be_a_vector_or, sizeof(__pyx_k_In_cgetrs_B_must_be_a_vector_or), 0, 1, 0, 0},
  {&__pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or, __pyx_k_In_dgetrs_B_must_be_a_Fortran_or, sizeof(__pyx_k_In_dgetrs_B_must_be_a_Fortran_or), 0, 1, 0, 0},
  {&__pyx_kp_u_In_dgetrs_B_must_be_a_vector_or, __pyx_k_In_dgetrs_B_must_be_a_vector_or, sizeof(__pyx_k_In_dgetrs_B_must_be_a_vector_or), 0, 1, 0, 0},
  {&__pyx_kp_u_In_sgetrs_B_must_be_a_vector_or, __pyx_k_In_sgetrs_B_must_be_a_vector_or, sizeof(__pyx_k_In_sgetrs_B_must_be_a_vector_or), 0, 1, 0, 0},
  {&__pyx_kp_u_In_zgetrs_B_must_be_a_vector_or, __pyx_k_In_zgetrs_B_must_be_a_vector_or, sizeof(__pyx_k_In_zgetrs_B_must_be_a_vector_or), 0, 1, 0, 0},
  {&__pyx_kp_u_Input_matrix_must_be_Fortran_con, __pyx_k_Input_matrix_must_be_Fortran_con, sizeof(__pyx_k_Input_matrix_must_be_Fortran_con), 0, 1, 0, 0},
  {&__pyx_n_s_LU, __pyx_k_LU, sizeof(__pyx_k_LU), 0, 0, 1, 1},
  {&__pyx_n_s_LinAlgError, __pyx_k_LinAlgError, sizeof(__pyx_k_LinAlgError), 0, 0, 1, 1},
  {&__pyx_n_s_M, __pyx_k_M, sizeof(__pyx_k_M), 0, 0, 1, 1},
  {&__pyx_n_s_MM, __pyx_k_MM, sizeof(__pyx_k_MM), 0, 0, 1, 1},
  {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
  {&__pyx_n_s_NRHS, __pyx_k_NRHS, sizeof(__pyx_k_NRHS), 0, 0, 1, 1},
  {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
  {&__pyx_n_s_Q, __pyx_k_Q, sizeof(__pyx_k_Q), 0, 0, 1, 1},
  {&__pyx_kp_u_QR_iteration_failed_to_converge, __pyx_k_QR_iteration_failed_to_converge, sizeof(__pyx_k_QR_iteration_failed_to_converge), 0, 1, 0, 0},
  {&__pyx_kp_u_QR_iteration_failed_to_converge_2, __pyx_k_QR_iteration_failed_to_converge_2, sizeof(__pyx_k_QR_iteration_failed_to_converge_2), 0, 1, 0, 0},
  {&__pyx_kp_u_QR_iteration_failed_to_converge_3, __pyx_k_QR_iteration_failed_to_converge_3, sizeof(__pyx_k_QR_iteration_failed_to_converge_3), 0, 1, 0, 0},
  {&__pyx_kp_u_QR_iteration_failed_to_converge_4, __pyx_k_QR_iteration_failed_to_converge_4, sizeof(__pyx_k_QR_iteration_failed_to_converge_4), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge, __pyx_k_QZ_iteration_failed_to_converge, sizeof(__pyx_k_QZ_iteration_failed_to_converge), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_2, __pyx_k_QZ_iteration_failed_to_converge_2, sizeof(__pyx_k_QZ_iteration_failed_to_converge_2), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_3, __pyx_k_QZ_iteration_failed_to_converge_3, sizeof(__pyx_k_QZ_iteration_failed_to_converge_3), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_4, __pyx_k_QZ_iteration_failed_to_converge_4, sizeof(__pyx_k_QZ_iteration_failed_to_converge_4), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_5, __pyx_k_QZ_iteration_failed_to_converge_5, sizeof(__pyx_k_QZ_iteration_failed_to_converge_5), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_6, __pyx_k_QZ_iteration_failed_to_converge_6, sizeof(__pyx_k_QZ_iteration_failed_to_converge_6), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_7, __pyx_k_QZ_iteration_failed_to_converge_7, sizeof(__pyx_k_QZ_iteration_failed_to_converge_7), 0, 1, 0, 0},
  {&__pyx_kp_u_QZ_iteration_failed_to_converge_8, __pyx_k_QZ_iteration_failed_to_converge_8, sizeof(__pyx_k_QZ_iteration_failed_to_converge_8), 0, 1, 0, 0},
  {&__pyx_kp_u_Reordering_failed_problem_is_ver, __pyx_k_Reordering_failed_problem_is_ver, sizeof(__pyx_k_Reordering_failed_problem_is_ver), 0, 1, 0, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1},
  {&__pyx_n_s_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 1, 1},
  {&__pyx_kp_u_Unexpected_data_type_from_common, __pyx_k_Unexpected_data_type_from_common, sizeof(__pyx_k_Unexpected_data_type_from_common), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector, __pyx_k_Unexpected_number_of_eigenvector, sizeof(__pyx_k_Unexpected_number_of_eigenvector), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_2, __pyx_k_Unexpected_number_of_eigenvector_2, sizeof(__pyx_k_Unexpected_number_of_eigenvector_2), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_3, __pyx_k_Unexpected_number_of_eigenvector_3, sizeof(__pyx_k_Unexpected_number_of_eigenvector_3), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_4, __pyx_k_Unexpected_number_of_eigenvector_4, sizeof(__pyx_k_Unexpected_number_of_eigenvector_4), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_5, __pyx_k_Unexpected_number_of_eigenvector_5, sizeof(__pyx_k_Unexpected_number_of_eigenvector_5), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_6, __pyx_k_Unexpected_number_of_eigenvector_6, sizeof(__pyx_k_Unexpected_number_of_eigenvector_6), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_7, __pyx_k_Unexpected_number_of_eigenvector_7, sizeof(__pyx_k_Unexpected_number_of_eigenvector_7), 0, 1, 0, 0},
  {&__pyx_kp_u_Unexpected_number_of_eigenvector_8, __pyx_k_Unexpected_number_of_eigenvector_8, sizeof(__pyx_k_Unexpected_number_of_eigenvector_8), 0, 1, 0, 0},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_s_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 1, 1},
  {&__pyx_n_s__106, __pyx_k__106, sizeof(__pyx_k__106), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_alpha, __pyx_k_alpha, sizeof(__pyx_k_alpha), 0, 0, 1, 1},
  {&__pyx_n_s_alphai, __pyx_k_alphai, sizeof(__pyx_k_alphai), 0, 0, 1, 1},
  {&__pyx_n_s_alphar, __pyx_k_alphar, sizeof(__pyx_k_alphar), 0, 0, 1, 1},
  {&__pyx_n_s_arg, __pyx_k_arg, sizeof(__pyx_k_arg), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_arr, __pyx_k_arr, sizeof(__pyx_k_arr), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_asanyarray, __pyx_k_asanyarray, sizeof(__pyx_k_asanyarray), 0, 0, 1, 1},
  {&__pyx_n_s_ascontiguousarray, __pyx_k_ascontiguousarray, sizeof(__pyx_k_ascontiguousarray), 0, 0, 1, 1},
  {&__pyx_n_s_asfortranarray, __pyx_k_asfortranarray, sizeof(__pyx_k_asfortranarray), 0, 0, 1, 1},
  {&__pyx_n_s_assert_fortran_mat, __pyx_k_assert_fortran_mat, sizeof(__pyx_k_assert_fortran_mat), 0, 0, 1, 1},
  {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_backtr, __pyx_k_backtr, sizeof(__pyx_k_backtr), 0, 0, 1, 1},
  {&__pyx_n_s_beta, __pyx_k_beta, sizeof(__pyx_k_beta), 0, 0, 1, 1},
  {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1},
  {&__pyx_n_s_calc_ev, __pyx_k_calc_ev, sizeof(__pyx_k_calc_ev), 0, 0, 1, 1},
  {&__pyx_n_s_calc_q, __pyx_k_calc_q, sizeof(__pyx_k_calc_q), 0, 0, 1, 1},
  {&__pyx_n_s_calc_z, __pyx_k_calc_z, sizeof(__pyx_k_calc_z), 0, 0, 1, 1},
  {&__pyx_n_s_cgecon, __pyx_k_cgecon, sizeof(__pyx_k_cgecon), 0, 0, 1, 1},
  {&__pyx_n_u_cgecon, __pyx_k_cgecon, sizeof(__pyx_k_cgecon), 0, 1, 0, 1},
  {&__pyx_n_s_cgees, __pyx_k_cgees, sizeof(__pyx_k_cgees), 0, 0, 1, 1},
  {&__pyx_n_u_cgees, __pyx_k_cgees, sizeof(__pyx_k_cgees), 0, 1, 0, 1},
  {&__pyx_n_s_cgetrf, __pyx_k_cgetrf, sizeof(__pyx_k_cgetrf), 0, 0, 1, 1},
  {&__pyx_n_u_cgetrf, __pyx_k_cgetrf, sizeof(__pyx_k_cgetrf), 0, 1, 0, 1},
  {&__pyx_n_s_cgetrs, __pyx_k_cgetrs, sizeof(__pyx_k_cgetrs), 0, 0, 1, 1},
  {&__pyx_n_u_cgetrs, __pyx_k_cgetrs, sizeof(__pyx_k_cgetrs), 0, 1, 0, 1},
  {&__pyx_n_s_cgges, __pyx_k_cgges, sizeof(__pyx_k_cgges), 0, 0, 1, 1},
  {&__pyx_n_u_cgges, __pyx_k_cgges, sizeof(__pyx_k_cgges), 0, 1, 0, 1},
  {&__pyx_n_s_cggev, __pyx_k_cggev, sizeof(__pyx_k_cggev), 0, 0, 1, 1},
  {&__pyx_n_u_cggev, __pyx_k_cggev, sizeof(__pyx_k_cggev), 0, 1, 0, 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_cmplxindx, __pyx_k_cmplxindx, sizeof(__pyx_k_cmplxindx), 0, 0, 1, 1},
  {&__pyx_n_s_common_type, __pyx_k_common_type, sizeof(__pyx_k_common_type), 0, 0, 1, 1},
  {&__pyx_n_s_complex128, __pyx_k_complex128, sizeof(__pyx_k_complex128), 0, 0, 1, 1},
  {&__pyx_n_s_complex64, __pyx_k_complex64, sizeof(__pyx_k_complex64), 0, 0, 1, 1},
  {&__pyx_n_s_compq, __pyx_k_compq, sizeof(__pyx_k_compq), 0, 0, 1, 1},
  {&__pyx_n_s_conj, __pyx_k_conj, sizeof(__pyx_k_conj), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_ctgevc, __pyx_k_ctgevc, sizeof(__pyx_k_ctgevc), 0, 0, 1, 1},
  {&__pyx_n_u_ctgevc, __pyx_k_ctgevc, sizeof(__pyx_k_ctgevc), 0, 1, 0, 1},
  {&__pyx_n_s_ctgsen, __pyx_k_ctgsen, sizeof(__pyx_k_ctgsen), 0, 0, 1, 1},
  {&__pyx_n_u_ctgsen, __pyx_k_ctgsen, sizeof(__pyx_k_ctgsen), 0, 1, 0, 1},
  {&__pyx_n_s_ctrevc, __pyx_k_ctrevc, sizeof(__pyx_k_ctrevc), 0, 0, 1, 1},
  {&__pyx_n_u_ctrevc, __pyx_k_ctrevc, sizeof(__pyx_k_ctrevc), 0, 1, 0, 1},
  {&__pyx_n_s_ctrsen, __pyx_k_ctrsen, sizeof(__pyx_k_ctrsen), 0, 0, 1, 1},
  {&__pyx_n_u_ctrsen, __pyx_k_ctrsen, sizeof(__pyx_k_ctrsen), 0, 1, 0, 1},
  {&__pyx_n_u_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 1, 0, 1},
  {&__pyx_n_s_dgecon, __pyx_k_dgecon, sizeof(__pyx_k_dgecon), 0, 0, 1, 1},
  {&__pyx_n_u_dgecon, __pyx_k_dgecon, sizeof(__pyx_k_dgecon), 0, 1, 0, 1},
  {&__pyx_n_s_dgees, __pyx_k_dgees, sizeof(__pyx_k_dgees), 0, 0, 1, 1},
  {&__pyx_n_u_dgees, __pyx_k_dgees, sizeof(__pyx_k_dgees), 0, 1, 0, 1},
  {&__pyx_n_s_dgetrf, __pyx_k_dgetrf, sizeof(__pyx_k_dgetrf), 0, 0, 1, 1},
  {&__pyx_n_u_dgetrf, __pyx_k_dgetrf, sizeof(__pyx_k_dgetrf), 0, 1, 0, 1},
  {&__pyx_n_s_dgetrs, __pyx_k_dgetrs, sizeof(__pyx_k_dgetrs), 0, 0, 1, 1},
  {&__pyx_n_u_dgetrs, __pyx_k_dgetrs, sizeof(__pyx_k_dgetrs), 0, 1, 0, 1},
  {&__pyx_n_s_dgges, __pyx_k_dgges, sizeof(__pyx_k_dgges), 0, 0, 1, 1},
  {&__pyx_n_u_dgges, __pyx_k_dgges, sizeof(__pyx_k_dgges), 0, 1, 0, 1},
  {&__pyx_n_s_dggev, __pyx_k_dggev, sizeof(__pyx_k_dggev), 0, 0, 1, 1},
  {&__pyx_n_u_dggev, __pyx_k_dggev, sizeof(__pyx_k_dggev), 0, 1, 0, 1},
  {&__pyx_n_s_diagonal, __pyx_k_diagonal, sizeof(__pyx_k_diagonal), 0, 0, 1, 1},
  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_n_s_dot, __pyx_k_dot, sizeof(__pyx_k_dot), 0, 0, 1, 1},
  {&__pyx_n_s_dtgevc, __pyx_k_dtgevc, sizeof(__pyx_k_dtgevc), 0, 0, 1, 1},
  {&__pyx_n_u_dtgevc, __pyx_k_dtgevc, sizeof(__pyx_k_dtgevc), 0, 1, 0, 1},
  {&__pyx_n_s_dtgsen, __pyx_k_dtgsen, sizeof(__pyx_k_dtgsen), 0, 0, 1, 1},
  {&__pyx_n_u_dtgsen, __pyx_k_dtgsen, sizeof(__pyx_k_dtgsen), 0, 1, 0, 1},
  {&__pyx_n_s_dtrevc, __pyx_k_dtrevc, sizeof(__pyx_k_dtrevc), 0, 0, 1, 1},
  {&__pyx_n_u_dtrevc, __pyx_k_dtrevc, sizeof(__pyx_k_dtrevc), 0, 1, 0, 1},
  {&__pyx_n_s_dtrsen, __pyx_k_dtrsen, sizeof(__pyx_k_dtrsen), 0, 0, 1, 1},
  {&__pyx_n_u_dtrsen, __pyx_k_dtrsen, sizeof(__pyx_k_dtrsen), 0, 1, 0, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_f_lapack, __pyx_k_f_lapack, sizeof(__pyx_k_f_lapack), 0, 0, 1, 1},
  {&__pyx_n_s_filter_args, __pyx_k_filter_args, sizeof(__pyx_k_filter_args), 0, 0, 1, 1},
  {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1},
  {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1},
  {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1},
  {&__pyx_n_s_ggev_postprocess, __pyx_k_ggev_postprocess, sizeof(__pyx_k_ggev_postprocess), 0, 0, 1, 1},
  {&__pyx_n_s_howmny, __pyx_k_howmny, sizeof(__pyx_k_howmny), 0, 0, 1, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_ijob, __pyx_k_ijob, sizeof(__pyx_k_ijob), 0, 0, 1, 1},
  {&__pyx_n_s_imag, __pyx_k_imag, sizeof(__pyx_k_imag), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_indx, __pyx_k_indx, sizeof(__pyx_k_indx), 0, 0, 1, 1},
  {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1},
  {&__pyx_n_s_int_dtype, __pyx_k_int_dtype, sizeof(__pyx_k_int_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_ipiv, __pyx_k_ipiv, sizeof(__pyx_k_ipiv), 0, 0, 1, 1},
  {&__pyx_n_s_issubdtype, __pyx_k_issubdtype, sizeof(__pyx_k_issubdtype), 0, 0, 1, 1},
  {&__pyx_n_s_iwork, __pyx_k_iwork, sizeof(__pyx_k_iwork), 0, 0, 1, 1},
  {&__pyx_n_s_jobvl, __pyx_k_jobvl, sizeof(__pyx_k_jobvl), 0, 0, 1, 1},
  {&__pyx_n_s_jobvr, __pyx_k_jobvr, sizeof(__pyx_k_jobvr), 0, 0, 1, 1},
  {&__pyx_n_s_jobvs, __pyx_k_jobvs, sizeof(__pyx_k_jobvs), 0, 0, 1, 1},
  {&__pyx_n_s_jobvsl, __pyx_k_jobvsl, sizeof(__pyx_k_jobvsl), 0, 0, 1, 1},
  {&__pyx_n_s_jobvsr, __pyx_k_jobvsr, sizeof(__pyx_k_jobvsr), 0, 0, 1, 1},
  {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1},
  {&__pyx_n_s_kwant_linalg_lapack, __pyx_k_kwant_linalg_lapack, sizeof(__pyx_k_kwant_linalg_lapack), 0, 0, 1, 1},
  {&__pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_k_kwant_linalg_lapack_pyx, sizeof(__pyx_k_kwant_linalg_lapack_pyx), 0, 0, 1, 0},
  {&__pyx_n_s_l_int_dtype, __pyx_k_l_int_dtype, sizeof(__pyx_k_l_int_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_l_logical_dtype, __pyx_k_l_logical_dtype, sizeof(__pyx_k_l_logical_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_lapacktype, __pyx_k_lapacktype, sizeof(__pyx_k_lapacktype), 0, 0, 1, 1},
  {&__pyx_n_s_left, __pyx_k_left, sizeof(__pyx_k_left), 0, 0, 1, 1},
  {&__pyx_n_s_liwork, __pyx_k_liwork, sizeof(__pyx_k_liwork), 0, 0, 1, 1},
  {&__pyx_n_s_logical_dtype, __pyx_k_logical_dtype, sizeof(__pyx_k_logical_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_lwork, __pyx_k_lwork, sizeof(__pyx_k_lwork), 0, 0, 1, 1},
  {&__pyx_n_s_m, __pyx_k_m, sizeof(__pyx_k_m), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_mat, __pyx_k_mat, sizeof(__pyx_k_mat), 0, 0, 1, 1},
  {&__pyx_n_s_mats, __pyx_k_mats, sizeof(__pyx_k_mats), 0, 0, 1, 1},
  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0},
  {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0},
  {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1},
  {&__pyx_n_s_nonzero, __pyx_k_nonzero, sizeof(__pyx_k_nonzero), 0, 0, 1, 1},
  {&__pyx_n_s_norm, __pyx_k_norm, sizeof(__pyx_k_norm), 0, 0, 1, 1},
  {&__pyx_n_s_normA, __pyx_k_normA, sizeof(__pyx_k_normA), 0, 0, 1, 1},
  {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
  {&__pyx_n_s_npmat, __pyx_k_npmat, sizeof(__pyx_k_npmat), 0, 0, 1, 1},
  {&__pyx_n_s_number, __pyx_k_number, sizeof(__pyx_k_number), 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_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_overwrite, __pyx_k_overwrite, sizeof(__pyx_k_overwrite), 0, 0, 1, 1},
  {&__pyx_n_s_ovwrt, __pyx_k_ovwrt, sizeof(__pyx_k_ovwrt), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_prepare_for_lapack, __pyx_k_prepare_for_lapack, sizeof(__pyx_k_prepare_for_lapack), 0, 0, 1, 1},
  {&__pyx_n_u_prepare_for_lapack, __pyx_k_prepare_for_lapack, sizeof(__pyx_k_prepare_for_lapack), 0, 1, 0, 1},
  {&__pyx_n_s_q_ptr, __pyx_k_q_ptr, sizeof(__pyx_k_q_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_qiwork, __pyx_k_qiwork, sizeof(__pyx_k_qiwork), 0, 0, 1, 1},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
  {&__pyx_n_s_qwork, __pyx_k_qwork, sizeof(__pyx_k_qwork), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rcond, __pyx_k_rcond, sizeof(__pyx_k_rcond), 0, 0, 1, 1},
  {&__pyx_n_s_ret, __pyx_k_ret, sizeof(__pyx_k_ret), 0, 0, 1, 1},
  {&__pyx_n_s_right, __pyx_k_right, sizeof(__pyx_k_right), 0, 0, 1, 1},
  {&__pyx_n_s_rwork, __pyx_k_rwork, sizeof(__pyx_k_rwork), 0, 0, 1, 1},
  {&__pyx_n_u_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 1, 0, 1},
  {&__pyx_n_s_sdim, __pyx_k_sdim, sizeof(__pyx_k_sdim), 0, 0, 1, 1},
  {&__pyx_n_s_sel, __pyx_k_sel, sizeof(__pyx_k_sel), 0, 0, 1, 1},
  {&__pyx_n_s_select, __pyx_k_select, sizeof(__pyx_k_select), 0, 0, 1, 1},
  {&__pyx_n_s_select_cpy, __pyx_k_select_cpy, sizeof(__pyx_k_select_cpy), 0, 0, 1, 1},
  {&__pyx_n_s_select_ptr, __pyx_k_select_ptr, sizeof(__pyx_k_select_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_selindx, __pyx_k_selindx, sizeof(__pyx_k_selindx), 0, 0, 1, 1},
  {&__pyx_n_s_sgecon, __pyx_k_sgecon, sizeof(__pyx_k_sgecon), 0, 0, 1, 1},
  {&__pyx_n_u_sgecon, __pyx_k_sgecon, sizeof(__pyx_k_sgecon), 0, 1, 0, 1},
  {&__pyx_n_s_sgees, __pyx_k_sgees, sizeof(__pyx_k_sgees), 0, 0, 1, 1},
  {&__pyx_n_u_sgees, __pyx_k_sgees, sizeof(__pyx_k_sgees), 0, 1, 0, 1},
  {&__pyx_n_s_sgetrf, __pyx_k_sgetrf, sizeof(__pyx_k_sgetrf), 0, 0, 1, 1},
  {&__pyx_n_u_sgetrf, __pyx_k_sgetrf, sizeof(__pyx_k_sgetrf), 0, 1, 0, 1},
  {&__pyx_n_s_sgetrs, __pyx_k_sgetrs, sizeof(__pyx_k_sgetrs), 0, 0, 1, 1},
  {&__pyx_n_u_sgetrs, __pyx_k_sgetrs, sizeof(__pyx_k_sgetrs), 0, 1, 0, 1},
  {&__pyx_n_s_sgges, __pyx_k_sgges, sizeof(__pyx_k_sgges), 0, 0, 1, 1},
  {&__pyx_n_u_sgges, __pyx_k_sgges, sizeof(__pyx_k_sgges), 0, 1, 0, 1},
  {&__pyx_n_s_sggev, __pyx_k_sggev, sizeof(__pyx_k_sggev), 0, 0, 1, 1},
  {&__pyx_n_u_sggev, __pyx_k_sggev, sizeof(__pyx_k_sggev), 0, 1, 0, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_side, __pyx_k_side, sizeof(__pyx_k_side), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_stgevc, __pyx_k_stgevc, sizeof(__pyx_k_stgevc), 0, 0, 1, 1},
  {&__pyx_n_u_stgevc, __pyx_k_stgevc, sizeof(__pyx_k_stgevc), 0, 1, 0, 1},
  {&__pyx_n_s_stgsen, __pyx_k_stgsen, sizeof(__pyx_k_stgsen), 0, 0, 1, 1},
  {&__pyx_n_u_stgsen, __pyx_k_stgsen, sizeof(__pyx_k_stgsen), 0, 1, 0, 1},
  {&__pyx_n_s_strevc, __pyx_k_strevc, sizeof(__pyx_k_strevc), 0, 0, 1, 1},
  {&__pyx_n_u_strevc, __pyx_k_strevc, sizeof(__pyx_k_strevc), 0, 1, 0, 1},
  {&__pyx_n_s_strsen, __pyx_k_strsen, sizeof(__pyx_k_strsen), 0, 0, 1, 1},
  {&__pyx_n_u_strsen, __pyx_k_strsen, sizeof(__pyx_k_strsen), 0, 1, 0, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_txevc_postprocess, __pyx_k_txevc_postprocess, sizeof(__pyx_k_txevc_postprocess), 0, 0, 1, 1},
  {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0},
  {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
  {&__pyx_n_s_vl, __pyx_k_vl, sizeof(__pyx_k_vl), 0, 0, 1, 1},
  {&__pyx_n_s_vl_ptr, __pyx_k_vl_ptr, sizeof(__pyx_k_vl_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vl_r, __pyx_k_vl_r, sizeof(__pyx_k_vl_r), 0, 0, 1, 1},
  {&__pyx_n_s_vl_r_ptr, __pyx_k_vl_r_ptr, sizeof(__pyx_k_vl_r_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vr, __pyx_k_vr, sizeof(__pyx_k_vr), 0, 0, 1, 1},
  {&__pyx_n_s_vr_ptr, __pyx_k_vr_ptr, sizeof(__pyx_k_vr_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vr_r, __pyx_k_vr_r, sizeof(__pyx_k_vr_r), 0, 0, 1, 1},
  {&__pyx_n_s_vr_r_ptr, __pyx_k_vr_r_ptr, sizeof(__pyx_k_vr_r_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vreal, __pyx_k_vreal, sizeof(__pyx_k_vreal), 0, 0, 1, 1},
  {&__pyx_n_s_vs, __pyx_k_vs, sizeof(__pyx_k_vs), 0, 0, 1, 1},
  {&__pyx_n_s_vs_ptr, __pyx_k_vs_ptr, sizeof(__pyx_k_vs_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vsl, __pyx_k_vsl, sizeof(__pyx_k_vsl), 0, 0, 1, 1},
  {&__pyx_n_s_vsl_ptr, __pyx_k_vsl_ptr, sizeof(__pyx_k_vsl_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_vsr, __pyx_k_vsr, sizeof(__pyx_k_vsr), 0, 0, 1, 1},
  {&__pyx_n_s_vsr_ptr, __pyx_k_vsr_ptr, sizeof(__pyx_k_vsr_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1},
  {&__pyx_n_s_wantq, __pyx_k_wantq, sizeof(__pyx_k_wantq), 0, 0, 1, 1},
  {&__pyx_n_s_wantz, __pyx_k_wantz, sizeof(__pyx_k_wantz), 0, 0, 1, 1},
  {&__pyx_n_s_wi, __pyx_k_wi, sizeof(__pyx_k_wi), 0, 0, 1, 1},
  {&__pyx_n_s_work, __pyx_k_work, sizeof(__pyx_k_work), 0, 0, 1, 1},
  {&__pyx_n_s_wr, __pyx_k_wr, sizeof(__pyx_k_wr), 0, 0, 1, 1},
  {&__pyx_n_u_z, __pyx_k_z, sizeof(__pyx_k_z), 0, 1, 0, 1},
  {&__pyx_n_s_z_ptr, __pyx_k_z_ptr, sizeof(__pyx_k_z_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_zgecon, __pyx_k_zgecon, sizeof(__pyx_k_zgecon), 0, 0, 1, 1},
  {&__pyx_n_u_zgecon, __pyx_k_zgecon, sizeof(__pyx_k_zgecon), 0, 1, 0, 1},
  {&__pyx_n_s_zgees, __pyx_k_zgees, sizeof(__pyx_k_zgees), 0, 0, 1, 1},
  {&__pyx_n_u_zgees, __pyx_k_zgees, sizeof(__pyx_k_zgees), 0, 1, 0, 1},
  {&__pyx_n_s_zgetrf, __pyx_k_zgetrf, sizeof(__pyx_k_zgetrf), 0, 0, 1, 1},
  {&__pyx_n_u_zgetrf, __pyx_k_zgetrf, sizeof(__pyx_k_zgetrf), 0, 1, 0, 1},
  {&__pyx_n_s_zgetrs, __pyx_k_zgetrs, sizeof(__pyx_k_zgetrs), 0, 0, 1, 1},
  {&__pyx_n_u_zgetrs, __pyx_k_zgetrs, sizeof(__pyx_k_zgetrs), 0, 1, 0, 1},
  {&__pyx_n_s_zgges, __pyx_k_zgges, sizeof(__pyx_k_zgges), 0, 0, 1, 1},
  {&__pyx_n_u_zgges, __pyx_k_zgges, sizeof(__pyx_k_zgges), 0, 1, 0, 1},
  {&__pyx_n_s_zggev, __pyx_k_zggev, sizeof(__pyx_k_zggev), 0, 0, 1, 1},
  {&__pyx_n_u_zggev, __pyx_k_zggev, sizeof(__pyx_k_zggev), 0, 1, 0, 1},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {&__pyx_n_s_ztgevc, __pyx_k_ztgevc, sizeof(__pyx_k_ztgevc), 0, 0, 1, 1},
  {&__pyx_n_u_ztgevc, __pyx_k_ztgevc, sizeof(__pyx_k_ztgevc), 0, 1, 0, 1},
  {&__pyx_n_s_ztgsen, __pyx_k_ztgsen, sizeof(__pyx_k_ztgsen), 0, 0, 1, 1},
  {&__pyx_n_u_ztgsen, __pyx_k_ztgsen, sizeof(__pyx_k_ztgsen), 0, 1, 0, 1},
  {&__pyx_n_s_ztrevc, __pyx_k_ztrevc, sizeof(__pyx_k_ztrevc), 0, 0, 1, 1},
  {&__pyx_n_u_ztrevc, __pyx_k_ztrevc, sizeof(__pyx_k_ztrevc), 0, 1, 0, 1},
  {&__pyx_n_s_ztrsen, __pyx_k_ztrsen, sizeof(__pyx_k_ztrsen), 0, 0, 1, 1},
  {&__pyx_n_u_ztrsen, __pyx_k_ztrsen, sizeof(__pyx_k_ztrsen), 0, 1, 0, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 37, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 43, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 51, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 1073, __pyx_L1_error)
  __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(0, 2514, __pyx_L1_error)
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(1, 1000, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "kwant/linalg/lapack.pyx":51
 *         if (mat is not None and (mat.shape[0] > 1 or mat.shape[1] > 1) and
 *             not mat.flags["F_CONTIGUOUS"]):
 *             raise ValueError("Input matrix must be Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_Input_matrix_must_be_Fortran_con); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "kwant/linalg/lapack.pyx":136
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 136, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "kwant/linalg/lapack.pyx":145
 *         NRHS = B.shape[1]
 *     else:
 *         raise ValueError("In sgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.sgetrs_("N", &N, &NRHS, <float *>LU.data, &N,
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_In_sgetrs_B_must_be_a_vector_or); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 145, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "kwant/linalg/lapack.pyx":166
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 166, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "kwant/linalg/lapack.pyx":175
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In dgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dgetrs_("N", &N, &NRHS, <double *>LU.data, &N,
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_u_In_dgetrs_B_must_be_a_vector_or); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "kwant/linalg/lapack.pyx":196
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "kwant/linalg/lapack.pyx":205
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In cgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cgetrs_("N", &N, &NRHS, <float complex *>LU.data, &N,
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_In_cgetrs_B_must_be_a_vector_or); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "kwant/linalg/lapack.pyx":226
 *         (B.ndim == 2 and (B.shape[0] > 1 or B.shape[1] > 1) and
 *          not B.flags["F_CONTIGUOUS"])):
 *         raise ValueError("In dgetrs: B must be a Fortran ordered NumPy array")             # <<<<<<<<<<<<<<
 * 
 *     b = B
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_u_In_dgetrs_B_must_be_a_Fortran_or); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "kwant/linalg/lapack.pyx":235
 *         NRHS = b.shape[1]
 *     else:
 *         raise ValueError("In zgetrs: B must be a vector or matrix")             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zgetrs_("N", &N, &NRHS, <double complex *>LU.data, &N,
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_In_zgetrs_B_must_be_a_vector_or); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "kwant/linalg/lapack.pyx":346
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]             # <<<<<<<<<<<<<<
 *                 vl[:, i+1] = np.conj(vl[:, i])
 *         else:
 */
  __pyx_slice__25 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__25)) __PYX_ERR(0, 346, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__25);
  __Pyx_GIVEREF(__pyx_slice__25);
  __pyx_slice__26 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__26)) __PYX_ERR(0, 346, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__26);
  __Pyx_GIVEREF(__pyx_slice__26);

  /* "kwant/linalg/lapack.pyx":347
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]
 *                 vl[:, i+1] = np.conj(vl[:, i])             # <<<<<<<<<<<<<<
 *         else:
 *             vl = None
 */
  __pyx_slice__27 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__27)) __PYX_ERR(0, 347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__27);
  __Pyx_GIVEREF(__pyx_slice__27);
  __pyx_slice__28 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__28)) __PYX_ERR(0, 347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__28);
  __Pyx_GIVEREF(__pyx_slice__28);

  /* "kwant/linalg/lapack.pyx":354
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]             # <<<<<<<<<<<<<<
 *                 vr[:, i+1] = np.conj(vr[:, i])
 *         else:
 */
  __pyx_slice__29 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__29)) __PYX_ERR(0, 354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__29);
  __Pyx_GIVEREF(__pyx_slice__29);
  __pyx_slice__30 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__30)) __PYX_ERR(0, 354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__30);
  __Pyx_GIVEREF(__pyx_slice__30);

  /* "kwant/linalg/lapack.pyx":355
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]
 *                 vr[:, i+1] = np.conj(vr[:, i])             # <<<<<<<<<<<<<<
 *         else:
 *             vr = None
 */
  __pyx_slice__31 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__31)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__31);
  __Pyx_GIVEREF(__pyx_slice__31);
  __pyx_slice__32 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__32)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__32);
  __Pyx_GIVEREF(__pyx_slice__32);

  /* "kwant/linalg/lapack.pyx":427
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sggev"
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "kwant/linalg/lapack.pyx":497
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dggev"
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_2); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "kwant/linalg/lapack.pyx":545
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "kwant/linalg/lapack.pyx":569
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cggev"
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_3); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "kwant/linalg/lapack.pyx":615
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 615, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "kwant/linalg/lapack.pyx":638
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zggev"
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_4); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "kwant/linalg/lapack.pyx":686
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in sgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgees"
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_u_QR_iteration_failed_to_converge); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 686, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "kwant/linalg/lapack.pyx":738
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in dgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgees"
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_u_QR_iteration_failed_to_converge_2); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 738, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "kwant/linalg/lapack.pyx":792
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in cgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgees"
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_u_QR_iteration_failed_to_converge_3); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 792, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "kwant/linalg/lapack.pyx":841
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in zgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_u_QR_iteration_failed_to_converge_4); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 841, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "kwant/linalg/lapack.pyx":894
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strsen"
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "kwant/linalg/lapack.pyx":952
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrsen"
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "kwant/linalg/lapack.pyx":1005
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrsen"
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "kwant/linalg/lapack.pyx":1053
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrsen"
 */
  __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 1053, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "kwant/linalg/lapack.pyx":1079
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the positive imaginary part desired
 *             v[:, m] = vreal[:, indx] + 1j * vreal[:, indx + 1]             # <<<<<<<<<<<<<<
 * 
 *             # Check if the eigenvalue with negative real part is also
 */
  __pyx_slice__60 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__60)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__60);
  __Pyx_GIVEREF(__pyx_slice__60);
  __pyx_slice__61 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__61)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__61);
  __Pyx_GIVEREF(__pyx_slice__61);
  __pyx_slice__62 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__62)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__62);
  __Pyx_GIVEREF(__pyx_slice__62);

  /* "kwant/linalg/lapack.pyx":1088
 *             # we have the situation of a 2x2 block, and
 *             # the eigenvalue with the negative imaginary part desired
 *             v[:, m] = vreal[:, indx] - 1j * vreal[:, indx + 1]             # <<<<<<<<<<<<<<
 * 
 *             indx += 2
 */
  __pyx_slice__63 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__63)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__63);
  __Pyx_GIVEREF(__pyx_slice__63);
  __pyx_slice__64 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__64)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__64);
  __Pyx_GIVEREF(__pyx_slice__64);
  __pyx_slice__65 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__65)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__65);
  __Pyx_GIVEREF(__pyx_slice__65);

  /* "kwant/linalg/lapack.pyx":1093
 *         else:
 *             # real eigenvalue
 *             v[:, m] = vreal[:, indx]             # <<<<<<<<<<<<<<
 * 
 *             indx += 1
 */
  __pyx_slice__66 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__66)) __PYX_ERR(0, 1093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__66);
  __Pyx_GIVEREF(__pyx_slice__66);
  __pyx_slice__67 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__67)) __PYX_ERR(0, 1093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__67);
  __Pyx_GIVEREF(__pyx_slice__67);

  /* "kwant/linalg/lapack.pyx":1532
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_tuple__73 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_5); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 1532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "kwant/linalg/lapack.pyx":1607
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_6); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 1607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);

  /* "kwant/linalg/lapack.pyx":1682
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_7); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 1682, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);

  /* "kwant/linalg/lapack.pyx":1752
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_u_QZ_iteration_failed_to_converge_8); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 1752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);

  /* "kwant/linalg/lapack.pyx":1826
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgsen"
 */
  __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 1826, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);

  /* "kwant/linalg/lapack.pyx":1905
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgsen"
 */
  __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 1905, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);

  /* "kwant/linalg/lapack.pyx":1981
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgsen"
 */
  __pyx_tuple__85 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 1981, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);

  /* "kwant/linalg/lapack.pyx":2052
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgsen"
 */
  __pyx_tuple__87 = PyTuple_Pack(1, __pyx_kp_u_Reordering_failed_problem_is_ver); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(0, 2052, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);

  /* "kwant/linalg/lapack.pyx":2493
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 *                 raise ValueError("Argument cannot be interpreted "             # <<<<<<<<<<<<<<
 *                                  "as a numeric array")
 * 
 */
  __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_u_Argument_cannot_be_interpreted_a); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(0, 2493, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__93);
  __Pyx_GIVEREF(__pyx_tuple__93);

  /* "kwant/linalg/lapack.pyx":2498
 *             mats[i] = (arr, arr is not args[i] or overwrite)
 *         else:
 *             mats[i] = (None, True)             # <<<<<<<<<<<<<<
 * 
 *     # First figure out common dtype
 */
  __pyx_tuple__94 = PyTuple_Pack(2, Py_None, Py_True); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(0, 2498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);

  /* "kwant/linalg/lapack.pyx":2514
 *         lapacktype = 'z'
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")             # <<<<<<<<<<<<<<
 * 
 *     ret = [ lapacktype ]
 */
  __pyx_tuple__95 = PyTuple_Pack(1, __pyx_kp_u_Unexpected_data_type_from_common); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(0, 2514, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__95);
  __Pyx_GIVEREF(__pyx_tuple__95);

  /* "kwant/linalg/lapack.pyx":2537
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")             # <<<<<<<<<<<<<<
 * 
 *         ret.append(npmat)
 */
  __pyx_tuple__96 = PyTuple_Pack(1, __pyx_kp_u_Dimensionality_of_array_is_not_1); if (unlikely(!__pyx_tuple__96)) __PYX_ERR(0, 2537, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__96);
  __Pyx_GIVEREF(__pyx_tuple__96);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":229
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_tuple__97 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__97)) __PYX_ERR(1, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__97);
  __Pyx_GIVEREF(__pyx_tuple__97);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":233
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_tuple__98 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(1, 233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__98);
  __Pyx_GIVEREF(__pyx_tuple__98);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_tuple__99 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__99)) __PYX_ERR(1, 263, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__99);
  __Pyx_GIVEREF(__pyx_tuple__99);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":810
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
  __pyx_tuple__100 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__100)) __PYX_ERR(1, 810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__100);
  __Pyx_GIVEREF(__pyx_tuple__100);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":814
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_tuple__101 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__101)) __PYX_ERR(1, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__101);
  __Pyx_GIVEREF(__pyx_tuple__101);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":834
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_tuple__102 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(1, 834, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__102);
  __Pyx_GIVEREF(__pyx_tuple__102);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1000
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
  __pyx_tuple__103 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__103)) __PYX_ERR(1, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__103);
  __Pyx_GIVEREF(__pyx_tuple__103);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1006
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
  __pyx_tuple__104 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__104)) __PYX_ERR(1, 1006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__104);
  __Pyx_GIVEREF(__pyx_tuple__104);

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1012
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__105 = PyTuple_Pack(1, __pyx_kp_u_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__105)) __PYX_ERR(1, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__105);
  __Pyx_GIVEREF(__pyx_tuple__105);

  /* "kwant/linalg/lapack.pyx":37
 * # exceptions
 * 
 * class LinAlgError(RuntimeError):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
  __pyx_tuple__107 = PyTuple_Pack(1, __pyx_builtin_RuntimeError); if (unlikely(!__pyx_tuple__107)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__107);
  __Pyx_GIVEREF(__pyx_tuple__107);

  /* "kwant/linalg/lapack.pyx":42
 * 
 * # some helper functions
 * def filter_args(select, args):             # <<<<<<<<<<<<<<
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 */
  __pyx_tuple__108 = PyTuple_Pack(4, __pyx_n_s_select, __pyx_n_s_args, __pyx_n_s_sel, __pyx_n_s_arg); if (unlikely(!__pyx_tuple__108)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__108);
  __Pyx_GIVEREF(__pyx_tuple__108);
  __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__108, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_filter_args, 42, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 42, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":45
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 * def assert_fortran_mat(*mats):             # <<<<<<<<<<<<<<
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 */
  __pyx_tuple__109 = PyTuple_Pack(2, __pyx_n_s_mats, __pyx_n_s_mat); if (unlikely(!__pyx_tuple__109)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__109);
  __Pyx_GIVEREF(__pyx_tuple__109);
  __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__109, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_assert_fortran_mat, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 45, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":55
 * 
 * # Wrappers for xGETRF
 * def sgetrf(np.ndarray[np.float32_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __pyx_tuple__110 = PyTuple_Pack(5, __pyx_n_s_A, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_ipiv); if (unlikely(!__pyx_tuple__110)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__110);
  __Pyx_GIVEREF(__pyx_tuple__110);
  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__110, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sgetrf, 55, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 55, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":72
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def dgetrf(np.ndarray[np.float64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __pyx_tuple__111 = PyTuple_Pack(5, __pyx_n_s_A, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_ipiv); if (unlikely(!__pyx_tuple__111)) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__111);
  __Pyx_GIVEREF(__pyx_tuple__111);
  __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__111, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dgetrf, 72, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 72, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":89
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def cgetrf(np.ndarray[np.complex64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __pyx_tuple__112 = PyTuple_Pack(5, __pyx_n_s_A, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_ipiv); if (unlikely(!__pyx_tuple__112)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__112);
  __Pyx_GIVEREF(__pyx_tuple__112);
  __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__112, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cgetrf, 89, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 89, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":106
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def zgetrf(np.ndarray[np.complex128_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __pyx_tuple__113 = PyTuple_Pack(5, __pyx_n_s_A, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_ipiv); if (unlikely(!__pyx_tuple__113)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__113);
  __Pyx_GIVEREF(__pyx_tuple__113);
  __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__113, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zgetrf, 106, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 106, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":125
 * # Wrappers for xGETRS
 * 
 * def sgetrs(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __pyx_tuple__114 = PyTuple_Pack(7, __pyx_n_s_LU, __pyx_n_s_IPIV, __pyx_n_s_B, __pyx_n_s_N, __pyx_n_s_NRHS, __pyx_n_s_info, __pyx_n_s_b); if (unlikely(!__pyx_tuple__114)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__114);
  __Pyx_GIVEREF(__pyx_tuple__114);
  __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__114, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sgetrs, 125, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 125, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":155
 *     return b
 * 
 * def dgetrs(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __pyx_tuple__115 = PyTuple_Pack(7, __pyx_n_s_LU, __pyx_n_s_IPIV, __pyx_n_s_B, __pyx_n_s_N, __pyx_n_s_NRHS, __pyx_n_s_info, __pyx_n_s_b); if (unlikely(!__pyx_tuple__115)) __PYX_ERR(0, 155, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__115);
  __Pyx_GIVEREF(__pyx_tuple__115);
  __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__115, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dgetrs, 155, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 155, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":185
 *     return b
 * 
 * def cgetrs(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __pyx_tuple__116 = PyTuple_Pack(7, __pyx_n_s_LU, __pyx_n_s_IPIV, __pyx_n_s_B, __pyx_n_s_N, __pyx_n_s_NRHS, __pyx_n_s_info, __pyx_n_s_b); if (unlikely(!__pyx_tuple__116)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__116);
  __Pyx_GIVEREF(__pyx_tuple__116);
  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__116, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cgetrs, 185, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 185, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":215
 *     return b
 * 
 * def zgetrs(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __pyx_tuple__117 = PyTuple_Pack(7, __pyx_n_s_LU, __pyx_n_s_IPIV, __pyx_n_s_B, __pyx_n_s_N, __pyx_n_s_NRHS, __pyx_n_s_info, __pyx_n_s_b); if (unlikely(!__pyx_tuple__117)) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__117);
  __Pyx_GIVEREF(__pyx_tuple__117);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__117, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zgetrs, 215, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 215, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":247
 * # Wrappers for xGECON
 * 
 * def sgecon(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __pyx_tuple__118 = PyTuple_Pack(8, __pyx_n_s_LU, __pyx_n_s_normA, __pyx_n_s_norm, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_rcond, __pyx_n_s_work, __pyx_n_s_iwork); if (unlikely(!__pyx_tuple__118)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__118);
  __Pyx_GIVEREF(__pyx_tuple__118);
  __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__118, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sgecon, 247, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 247, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __pyx_tuple__119 = PyTuple_Pack(8, __pyx_n_s_LU, __pyx_n_s_normA, __pyx_n_s_norm, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_rcond, __pyx_n_s_work, __pyx_n_s_iwork); if (unlikely(!__pyx_tuple__119)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__119);
  __Pyx_GIVEREF(__pyx_tuple__119);
  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__119, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dgecon, 268, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 268, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __pyx_tuple__120 = PyTuple_Pack(8, __pyx_n_s_LU, __pyx_n_s_normA, __pyx_n_s_norm, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_rcond, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__120)) __PYX_ERR(0, 289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__120);
  __Pyx_GIVEREF(__pyx_tuple__120);
  __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__120, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cgecon, 289, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(0, 289, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __pyx_tuple__121 = PyTuple_Pack(8, __pyx_n_s_LU, __pyx_n_s_normA, __pyx_n_s_norm, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_rcond, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__121)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__121);
  __Pyx_GIVEREF(__pyx_tuple__121);
  __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__121, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zgecon, 310, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 310, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":334
 * 
 * # Helper function for xGGEV
 * def ggev_postprocess(dtype, alphar, alphai, vl_r=None, vr_r=None):             # <<<<<<<<<<<<<<
 *     # depending on whether the eigenvalues are purely real or complex,
 *     # some post-processing of the eigenvalues and -vectors is necessary
 */
  __pyx_tuple__122 = PyTuple_Pack(10, __pyx_n_s_dtype, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_indx, __pyx_n_s_alpha, __pyx_n_s_vl, __pyx_n_s_i, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__122)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__122);
  __Pyx_GIVEREF(__pyx_tuple__122);
  __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(5, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__122, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ggev_postprocess, 334, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 334, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":366
 * 
 * 
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_tuple__123 = PyTuple_Pack(21, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_lwork, __pyx_n_s_jobvl, __pyx_n_s_jobvr, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_qwork, __pyx_n_s_work, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_alpha, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__123)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__123);
  __Pyx_GIVEREF(__pyx_tuple__123);
  __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(4, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__123, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sggev, 366, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 366, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":436
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_tuple__124 = PyTuple_Pack(21, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_lwork, __pyx_n_s_jobvl, __pyx_n_s_jobvr, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_qwork, __pyx_n_s_work, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_alpha, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__124)) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__124);
  __Pyx_GIVEREF(__pyx_tuple__124);
  __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(4, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__124, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dggev, 436, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 436, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":506
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_tuple__125 = PyTuple_Pack(18, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_lwork, __pyx_n_s_jobvl, __pyx_n_s_jobvr, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_qwork, __pyx_n_s_work, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__125)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__125);
  __Pyx_GIVEREF(__pyx_tuple__125);
  __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__125, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cggev, 506, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 506, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":576
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_tuple__126 = PyTuple_Pack(18, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_lwork, __pyx_n_s_jobvl, __pyx_n_s_jobvr, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_qwork, __pyx_n_s_work, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__126)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__126);
  __Pyx_GIVEREF(__pyx_tuple__126);
  __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__126, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zggev, 576, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 576, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":646
 * 
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_tuple__127 = PyTuple_Pack(15, __pyx_n_s_A, __pyx_n_s_calc_q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvs, __pyx_n_s_vs_ptr, __pyx_n_s_qwork, __pyx_n_s_vs, __pyx_n_s_wr, __pyx_n_s_wi, __pyx_n_s_work, __pyx_n_s_w); if (unlikely(!__pyx_tuple__127)) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__127);
  __Pyx_GIVEREF(__pyx_tuple__127);
  __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__127, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sgees, 646, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 646, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":698
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_tuple__128 = PyTuple_Pack(15, __pyx_n_s_A, __pyx_n_s_calc_q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvs, __pyx_n_s_vs_ptr, __pyx_n_s_qwork, __pyx_n_s_vs, __pyx_n_s_wr, __pyx_n_s_wi, __pyx_n_s_work, __pyx_n_s_w); if (unlikely(!__pyx_tuple__128)) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__128);
  __Pyx_GIVEREF(__pyx_tuple__128);
  __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__128, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dgees, 698, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 698, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":750
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_tuple__129 = PyTuple_Pack(14, __pyx_n_s_A, __pyx_n_s_calc_q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvs, __pyx_n_s_vs_ptr, __pyx_n_s_qwork, __pyx_n_s_vs, __pyx_n_s_w, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__129)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__129);
  __Pyx_GIVEREF(__pyx_tuple__129);
  __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__129, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cgees, 750, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(0, 750, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":799
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_tuple__130 = PyTuple_Pack(14, __pyx_n_s_A, __pyx_n_s_calc_q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvs, __pyx_n_s_vs_ptr, __pyx_n_s_qwork, __pyx_n_s_vs, __pyx_n_s_w, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__130)) __PYX_ERR(0, 799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__130);
  __Pyx_GIVEREF(__pyx_tuple__130);
  __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__130, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zgees, 799, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(0, 799, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":848
 * 
 * # Wrapper for xTRSEN
 * def strsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */
  __pyx_tuple__131 = PyTuple_Pack(18, __pyx_n_s_select, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_compq, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_wr, __pyx_n_s_wi, __pyx_n_s_work, __pyx_n_s_iwork, __pyx_n_s_w); if (unlikely(!__pyx_tuple__131)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__131);
  __Pyx_GIVEREF(__pyx_tuple__131);
  __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__131, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_strsen, 848, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(0, 848, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":906
 * 
 * 
 * def dtrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */
  __pyx_tuple__132 = PyTuple_Pack(18, __pyx_n_s_select, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_compq, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_wr, __pyx_n_s_wi, __pyx_n_s_work, __pyx_n_s_iwork, __pyx_n_s_w); if (unlikely(!__pyx_tuple__132)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__132);
  __Pyx_GIVEREF(__pyx_tuple__132);
  __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dtrsen, 906, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(0, 906, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":964
 * 
 * 
 * def ctrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */
  __pyx_tuple__133 = PyTuple_Pack(13, __pyx_n_s_select, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_info, __pyx_n_s_compq, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_w, __pyx_n_s_work); if (unlikely(!__pyx_tuple__133)) __PYX_ERR(0, 964, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__133);
  __Pyx_GIVEREF(__pyx_tuple__133);
  __pyx_codeobj__55 = (PyObject*)__Pyx_PyCode_New(4, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__133, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ctrsen, 964, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__55)) __PYX_ERR(0, 964, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1012
 * 
 * 
 * def ztrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */
  __pyx_tuple__134 = PyTuple_Pack(14, __pyx_n_s_select, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_MM, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_info, __pyx_n_s_compq, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_w, __pyx_n_s_work); if (unlikely(!__pyx_tuple__134)) __PYX_ERR(0, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__134);
  __Pyx_GIVEREF(__pyx_tuple__134);
  __pyx_codeobj__57 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__134, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ztrsen, 1012, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__57)) __PYX_ERR(0, 1012, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1061
 * 
 * # Helper function for xTREVC and xTGEVC
 * def txevc_postprocess(dtype, T, vreal, np.ndarray[l_logical] select):             # <<<<<<<<<<<<<<
 *     cdef int N, M, i, m, indx
 * 
 */
  __pyx_tuple__135 = PyTuple_Pack(12, __pyx_n_s_dtype, __pyx_n_s_T, __pyx_n_s_vreal, __pyx_n_s_select, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_i, __pyx_n_s_m, __pyx_n_s_indx, __pyx_n_s_selindx, __pyx_n_s_v, __pyx_n_s_k); if (unlikely(!__pyx_tuple__135)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__135);
  __Pyx_GIVEREF(__pyx_tuple__135);
  __pyx_codeobj__59 = (PyObject*)__Pyx_PyCode_New(4, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__135, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_txevc_postprocess, 1061, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__59)) __PYX_ERR(0, 1061, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1100
 * 
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __pyx_tuple__136 = PyTuple_Pack(22, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_r_ptr, __pyx_n_s_vr_r_ptr, __pyx_n_s_select_cpy, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_cmplxindx, __pyx_n_s_i, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__136)) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__136);
  __Pyx_GIVEREF(__pyx_tuple__136);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(5, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__136, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_strevc, 1100, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 1100, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1204
 * 
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __pyx_tuple__137 = PyTuple_Pack(22, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_r_ptr, __pyx_n_s_vr_r_ptr, __pyx_n_s_select_cpy, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_cmplxindx, __pyx_n_s_i, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__137)) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__137);
  __Pyx_GIVEREF(__pyx_tuple__137);
  __pyx_codeobj__69 = (PyObject*)__Pyx_PyCode_New(5, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dtrevc, 1204, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__69)) __PYX_ERR(0, 1204, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1307
 * 
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __pyx_tuple__138 = PyTuple_Pack(18, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__138)) __PYX_ERR(0, 1307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__138);
  __Pyx_GIVEREF(__pyx_tuple__138);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(5, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__138, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ctrevc, 1307, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 1307, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1388
 * 
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __pyx_tuple__139 = PyTuple_Pack(18, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__139)) __PYX_ERR(0, 1388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__139);
  __Pyx_GIVEREF(__pyx_tuple__139);
  __pyx_codeobj__71 = (PyObject*)__Pyx_PyCode_New(5, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__139, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ztrevc, 1388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__71)) __PYX_ERR(0, 1388, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1470
 * 
 * # wrappers for xGGES
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __pyx_tuple__140 = PyTuple_Pack(21, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_calc_q, __pyx_n_s_calc_z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvsl, __pyx_n_s_jobvsr, __pyx_n_s_vsl_ptr, __pyx_n_s_vsr_ptr, __pyx_n_s_qwork, __pyx_n_s_vsl, __pyx_n_s_vsr, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_alpha); if (unlikely(!__pyx_tuple__140)) __PYX_ERR(0, 1470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__140);
  __Pyx_GIVEREF(__pyx_tuple__140);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_sgges, 1470, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 1470, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1545
 * 
 * 
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __pyx_tuple__141 = PyTuple_Pack(21, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_calc_q, __pyx_n_s_calc_z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvsl, __pyx_n_s_jobvsr, __pyx_n_s_vsl_ptr, __pyx_n_s_vsr_ptr, __pyx_n_s_qwork, __pyx_n_s_vsl, __pyx_n_s_vsr, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_alpha); if (unlikely(!__pyx_tuple__141)) __PYX_ERR(0, 1545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__141);
  __Pyx_GIVEREF(__pyx_tuple__141);
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__141, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dgges, 1545, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 1545, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1620
 * 
 * 
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __pyx_tuple__142 = PyTuple_Pack(20, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_calc_q, __pyx_n_s_calc_z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvsl, __pyx_n_s_jobvsr, __pyx_n_s_vsl_ptr, __pyx_n_s_vsr_ptr, __pyx_n_s_qwork, __pyx_n_s_vsl, __pyx_n_s_vsr, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__142)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__142);
  __Pyx_GIVEREF(__pyx_tuple__142);
  __pyx_codeobj__76 = (PyObject*)__Pyx_PyCode_New(5, 0, 20, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__142, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_cgges, 1620, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__76)) __PYX_ERR(0, 1620, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1690
 * 
 * 
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __pyx_tuple__143 = PyTuple_Pack(20, __pyx_n_s_A, __pyx_n_s_B, __pyx_n_s_calc_q, __pyx_n_s_calc_z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_lwork, __pyx_n_s_sdim, __pyx_n_s_info, __pyx_n_s_jobvsl, __pyx_n_s_jobvsr, __pyx_n_s_vsl_ptr, __pyx_n_s_vsr_ptr, __pyx_n_s_qwork, __pyx_n_s_vsl, __pyx_n_s_vsr, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_rwork); if (unlikely(!__pyx_tuple__143)) __PYX_ERR(0, 1690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__143);
  __Pyx_GIVEREF(__pyx_tuple__143);
  __pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(5, 0, 20, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_zgges, 1690, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) __PYX_ERR(0, 1690, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1761
 * 
 * # wrappers for xTGSEN
 * def stgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 */
  __pyx_tuple__144 = PyTuple_Pack(24, __pyx_n_s_select, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_ijob, __pyx_n_s_wantq, __pyx_n_s_wantz, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_z_ptr, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_iwork, __pyx_n_s_alpha); if (unlikely(!__pyx_tuple__144)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__144);
  __Pyx_GIVEREF(__pyx_tuple__144);
  __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(6, 0, 24, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__144, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_stgsen, 1761, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(0, 1761, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1840
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */
  __pyx_tuple__145 = PyTuple_Pack(24, __pyx_n_s_select, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_ijob, __pyx_n_s_wantq, __pyx_n_s_wantz, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_z_ptr, __pyx_n_s_alphar, __pyx_n_s_alphai, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_iwork, __pyx_n_s_alpha); if (unlikely(!__pyx_tuple__145)) __PYX_ERR(0, 1840, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__145);
  __Pyx_GIVEREF(__pyx_tuple__145);
  __pyx_codeobj__82 = (PyObject*)__Pyx_PyCode_New(6, 0, 24, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__145, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dtgsen, 1840, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__82)) __PYX_ERR(0, 1840, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1919
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */
  __pyx_tuple__146 = PyTuple_Pack(22, __pyx_n_s_select, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_ijob, __pyx_n_s_wantq, __pyx_n_s_wantz, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_z_ptr, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_iwork); if (unlikely(!__pyx_tuple__146)) __PYX_ERR(0, 1919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__146);
  __Pyx_GIVEREF(__pyx_tuple__146);
  __pyx_codeobj__84 = (PyObject*)__Pyx_PyCode_New(6, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ctgsen, 1919, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__84)) __PYX_ERR(0, 1919, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":1990
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */
  __pyx_tuple__147 = PyTuple_Pack(22, __pyx_n_s_select, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_calc_ev, __pyx_n_s_N, __pyx_n_s_M, __pyx_n_s_lwork, __pyx_n_s_liwork, __pyx_n_s_qiwork, __pyx_n_s_info, __pyx_n_s_ijob, __pyx_n_s_wantq, __pyx_n_s_wantz, __pyx_n_s_qwork, __pyx_n_s_q_ptr, __pyx_n_s_z_ptr, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_work, __pyx_n_s_iwork); if (unlikely(!__pyx_tuple__147)) __PYX_ERR(0, 1990, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__147);
  __Pyx_GIVEREF(__pyx_tuple__147);
  __pyx_codeobj__86 = (PyObject*)__Pyx_PyCode_New(6, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__147, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ztgsen, 1990, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__86)) __PYX_ERR(0, 1990, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":2062
 * 
 * # xTGEVC
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */
  __pyx_tuple__148 = PyTuple_Pack(25, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_r_ptr, __pyx_n_s_vr_r_ptr, __pyx_n_s_select_cpy, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_backtr, __pyx_n_s_cmplxindx, __pyx_n_s_i, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__148)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__148);
  __Pyx_GIVEREF(__pyx_tuple__148);
  __pyx_codeobj__88 = (PyObject*)__Pyx_PyCode_New(7, 0, 25, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__148, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_stgevc, 2062, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__88)) __PYX_ERR(0, 2062, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":2173
 * 
 * 
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */
  __pyx_tuple__149 = PyTuple_Pack(25, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl_r, __pyx_n_s_vr_r, __pyx_n_s_vl_r_ptr, __pyx_n_s_vr_r_ptr, __pyx_n_s_select_cpy, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_backtr, __pyx_n_s_cmplxindx, __pyx_n_s_i, __pyx_n_s_vl, __pyx_n_s_vr); if (unlikely(!__pyx_tuple__149)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__149);
  __Pyx_GIVEREF(__pyx_tuple__149);
  __pyx_codeobj__89 = (PyObject*)__Pyx_PyCode_New(7, 0, 25, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__149, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_dtgevc, 2173, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__89)) __PYX_ERR(0, 2173, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":2285
 * 
 * 
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */
  __pyx_tuple__150 = PyTuple_Pack(21, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_rwork, __pyx_n_s_backtr); if (unlikely(!__pyx_tuple__150)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__150);
  __Pyx_GIVEREF(__pyx_tuple__150);
  __pyx_codeobj__90 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__150, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ctgevc, 2285, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__90)) __PYX_ERR(0, 2285, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":2374
 * 
 * 
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */
  __pyx_tuple__151 = PyTuple_Pack(21, __pyx_n_s_S, __pyx_n_s_T, __pyx_n_s_Q, __pyx_n_s_Z, __pyx_n_s_select, __pyx_n_s_left, __pyx_n_s_right, __pyx_n_s_N, __pyx_n_s_info, __pyx_n_s_M, __pyx_n_s_MM, __pyx_n_s_side, __pyx_n_s_howmny, __pyx_n_s_vl, __pyx_n_s_vr, __pyx_n_s_vl_ptr, __pyx_n_s_vr_ptr, __pyx_n_s_select_ptr, __pyx_n_s_work, __pyx_n_s_rwork, __pyx_n_s_backtr); if (unlikely(!__pyx_tuple__151)) __PYX_ERR(0, 2374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__151);
  __Pyx_GIVEREF(__pyx_tuple__151);
  __pyx_codeobj__91 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__151, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_ztgevc, 2374, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__91)) __PYX_ERR(0, 2374, __pyx_L1_error)

  /* "kwant/linalg/lapack.pyx":2463
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */
  __pyx_tuple__152 = PyTuple_Pack(12, __pyx_n_s_overwrite, __pyx_n_s_args, __pyx_n_s_mats, __pyx_n_s_i, __pyx_n_s_arr, __pyx_n_s_dtype, __pyx_n_s_lapacktype, __pyx_n_s_ret, __pyx_n_s_npmat, __pyx_n_s_ovwrt, __pyx_n_s_arr, __pyx_n_s_ovwrt); if (unlikely(!__pyx_tuple__152)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__152);
  __Pyx_GIVEREF(__pyx_tuple__152);
  __pyx_codeobj__92 = (PyObject*)__Pyx_PyCode_New(1, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__152, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_kwant_linalg_lapack_pyx, __pyx_n_s_prepare_for_lapack, 2463, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__92)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static 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_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_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 int __Pyx_modinit_global_init_code(void); /*proto*/
static int __Pyx_modinit_variable_export_code(void); /*proto*/
static int __Pyx_modinit_function_export_code(void); /*proto*/
static int __Pyx_modinit_type_init_code(void); /*proto*/
static int __Pyx_modinit_type_import_code(void); /*proto*/
static int __Pyx_modinit_variable_import_code(void); /*proto*/
static 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 ---*/
  __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
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(2, 9, __pyx_L1_error)
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) __PYX_ERR(1, 164, __pyx_L1_error)
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) __PYX_ERR(1, 186, __pyx_L1_error)
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) __PYX_ERR(1, 190, __pyx_L1_error)
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) __PYX_ERR(1, 199, __pyx_L1_error)
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) __PYX_ERR(1, 872, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __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
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}


#if PY_MAJOR_VERSION < 3
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC void
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#else
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
    #define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initlapack(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initlapack(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_lapack(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_lapack(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        result = PyDict_SetItemString(moddict, to_name, value);
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    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__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static int __pyx_pymod_exec_lapack(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  __Pyx_TraceDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
  #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_lapack(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __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(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #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("lapack", __pyx_methods, __pyx_k_Low_level_access_to_LAPACK_funct, 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)
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  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_kwant__linalg__lapack) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __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, "kwant.linalg.lapack")) {
      if (unlikely(PyDict_SetItemString(modules, "kwant.linalg.lapack", __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();
  (void)__Pyx_modinit_type_init_code();
  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  (void)__Pyx_modinit_variable_import_code();
  (void)__Pyx_modinit_function_import_code();
  /*--- 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_lapack(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error));

  /* "kwant/linalg/lapack.pyx":11
 * """Low-level access to LAPACK functions. """
 * 
 * __all__ = ['sgetrf', 'dgetrf', 'cgetrf', 'zgetrf',             # <<<<<<<<<<<<<<
 *            'sgetrs', 'dgetrs', 'cgetrs', 'zgetrs',
 *            'sgecon', 'dgecon', 'cgecon', 'zgecon',
 */
  __Pyx_TraceLine(11,0,__PYX_ERR(0, 11, __pyx_L1_error))
  __pyx_t_1 = PyList_New(41); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_u_sgetrf);
  __Pyx_GIVEREF(__pyx_n_u_sgetrf);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_u_sgetrf);
  __Pyx_INCREF(__pyx_n_u_dgetrf);
  __Pyx_GIVEREF(__pyx_n_u_dgetrf);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_dgetrf);
  __Pyx_INCREF(__pyx_n_u_cgetrf);
  __Pyx_GIVEREF(__pyx_n_u_cgetrf);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_cgetrf);
  __Pyx_INCREF(__pyx_n_u_zgetrf);
  __Pyx_GIVEREF(__pyx_n_u_zgetrf);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_zgetrf);
  __Pyx_INCREF(__pyx_n_u_sgetrs);
  __Pyx_GIVEREF(__pyx_n_u_sgetrs);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_u_sgetrs);
  __Pyx_INCREF(__pyx_n_u_dgetrs);
  __Pyx_GIVEREF(__pyx_n_u_dgetrs);
  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_u_dgetrs);
  __Pyx_INCREF(__pyx_n_u_cgetrs);
  __Pyx_GIVEREF(__pyx_n_u_cgetrs);
  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_u_cgetrs);
  __Pyx_INCREF(__pyx_n_u_zgetrs);
  __Pyx_GIVEREF(__pyx_n_u_zgetrs);
  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_u_zgetrs);
  __Pyx_INCREF(__pyx_n_u_sgecon);
  __Pyx_GIVEREF(__pyx_n_u_sgecon);
  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_u_sgecon);
  __Pyx_INCREF(__pyx_n_u_dgecon);
  __Pyx_GIVEREF(__pyx_n_u_dgecon);
  PyList_SET_ITEM(__pyx_t_1, 9, __pyx_n_u_dgecon);
  __Pyx_INCREF(__pyx_n_u_cgecon);
  __Pyx_GIVEREF(__pyx_n_u_cgecon);
  PyList_SET_ITEM(__pyx_t_1, 10, __pyx_n_u_cgecon);
  __Pyx_INCREF(__pyx_n_u_zgecon);
  __Pyx_GIVEREF(__pyx_n_u_zgecon);
  PyList_SET_ITEM(__pyx_t_1, 11, __pyx_n_u_zgecon);
  __Pyx_INCREF(__pyx_n_u_sggev);
  __Pyx_GIVEREF(__pyx_n_u_sggev);
  PyList_SET_ITEM(__pyx_t_1, 12, __pyx_n_u_sggev);
  __Pyx_INCREF(__pyx_n_u_dggev);
  __Pyx_GIVEREF(__pyx_n_u_dggev);
  PyList_SET_ITEM(__pyx_t_1, 13, __pyx_n_u_dggev);
  __Pyx_INCREF(__pyx_n_u_cggev);
  __Pyx_GIVEREF(__pyx_n_u_cggev);
  PyList_SET_ITEM(__pyx_t_1, 14, __pyx_n_u_cggev);
  __Pyx_INCREF(__pyx_n_u_zggev);
  __Pyx_GIVEREF(__pyx_n_u_zggev);
  PyList_SET_ITEM(__pyx_t_1, 15, __pyx_n_u_zggev);
  __Pyx_INCREF(__pyx_n_u_sgees);
  __Pyx_GIVEREF(__pyx_n_u_sgees);
  PyList_SET_ITEM(__pyx_t_1, 16, __pyx_n_u_sgees);
  __Pyx_INCREF(__pyx_n_u_dgees);
  __Pyx_GIVEREF(__pyx_n_u_dgees);
  PyList_SET_ITEM(__pyx_t_1, 17, __pyx_n_u_dgees);
  __Pyx_INCREF(__pyx_n_u_cgees);
  __Pyx_GIVEREF(__pyx_n_u_cgees);
  PyList_SET_ITEM(__pyx_t_1, 18, __pyx_n_u_cgees);
  __Pyx_INCREF(__pyx_n_u_zgees);
  __Pyx_GIVEREF(__pyx_n_u_zgees);
  PyList_SET_ITEM(__pyx_t_1, 19, __pyx_n_u_zgees);
  __Pyx_INCREF(__pyx_n_u_strsen);
  __Pyx_GIVEREF(__pyx_n_u_strsen);
  PyList_SET_ITEM(__pyx_t_1, 20, __pyx_n_u_strsen);
  __Pyx_INCREF(__pyx_n_u_dtrsen);
  __Pyx_GIVEREF(__pyx_n_u_dtrsen);
  PyList_SET_ITEM(__pyx_t_1, 21, __pyx_n_u_dtrsen);
  __Pyx_INCREF(__pyx_n_u_ctrsen);
  __Pyx_GIVEREF(__pyx_n_u_ctrsen);
  PyList_SET_ITEM(__pyx_t_1, 22, __pyx_n_u_ctrsen);
  __Pyx_INCREF(__pyx_n_u_ztrsen);
  __Pyx_GIVEREF(__pyx_n_u_ztrsen);
  PyList_SET_ITEM(__pyx_t_1, 23, __pyx_n_u_ztrsen);
  __Pyx_INCREF(__pyx_n_u_strevc);
  __Pyx_GIVEREF(__pyx_n_u_strevc);
  PyList_SET_ITEM(__pyx_t_1, 24, __pyx_n_u_strevc);
  __Pyx_INCREF(__pyx_n_u_dtrevc);
  __Pyx_GIVEREF(__pyx_n_u_dtrevc);
  PyList_SET_ITEM(__pyx_t_1, 25, __pyx_n_u_dtrevc);
  __Pyx_INCREF(__pyx_n_u_ctrevc);
  __Pyx_GIVEREF(__pyx_n_u_ctrevc);
  PyList_SET_ITEM(__pyx_t_1, 26, __pyx_n_u_ctrevc);
  __Pyx_INCREF(__pyx_n_u_ztrevc);
  __Pyx_GIVEREF(__pyx_n_u_ztrevc);
  PyList_SET_ITEM(__pyx_t_1, 27, __pyx_n_u_ztrevc);
  __Pyx_INCREF(__pyx_n_u_sgges);
  __Pyx_GIVEREF(__pyx_n_u_sgges);
  PyList_SET_ITEM(__pyx_t_1, 28, __pyx_n_u_sgges);
  __Pyx_INCREF(__pyx_n_u_dgges);
  __Pyx_GIVEREF(__pyx_n_u_dgges);
  PyList_SET_ITEM(__pyx_t_1, 29, __pyx_n_u_dgges);
  __Pyx_INCREF(__pyx_n_u_cgges);
  __Pyx_GIVEREF(__pyx_n_u_cgges);
  PyList_SET_ITEM(__pyx_t_1, 30, __pyx_n_u_cgges);
  __Pyx_INCREF(__pyx_n_u_zgges);
  __Pyx_GIVEREF(__pyx_n_u_zgges);
  PyList_SET_ITEM(__pyx_t_1, 31, __pyx_n_u_zgges);
  __Pyx_INCREF(__pyx_n_u_stgsen);
  __Pyx_GIVEREF(__pyx_n_u_stgsen);
  PyList_SET_ITEM(__pyx_t_1, 32, __pyx_n_u_stgsen);
  __Pyx_INCREF(__pyx_n_u_dtgsen);
  __Pyx_GIVEREF(__pyx_n_u_dtgsen);
  PyList_SET_ITEM(__pyx_t_1, 33, __pyx_n_u_dtgsen);
  __Pyx_INCREF(__pyx_n_u_ctgsen);
  __Pyx_GIVEREF(__pyx_n_u_ctgsen);
  PyList_SET_ITEM(__pyx_t_1, 34, __pyx_n_u_ctgsen);
  __Pyx_INCREF(__pyx_n_u_ztgsen);
  __Pyx_GIVEREF(__pyx_n_u_ztgsen);
  PyList_SET_ITEM(__pyx_t_1, 35, __pyx_n_u_ztgsen);
  __Pyx_INCREF(__pyx_n_u_stgevc);
  __Pyx_GIVEREF(__pyx_n_u_stgevc);
  PyList_SET_ITEM(__pyx_t_1, 36, __pyx_n_u_stgevc);
  __Pyx_INCREF(__pyx_n_u_dtgevc);
  __Pyx_GIVEREF(__pyx_n_u_dtgevc);
  PyList_SET_ITEM(__pyx_t_1, 37, __pyx_n_u_dtgevc);
  __Pyx_INCREF(__pyx_n_u_ctgevc);
  __Pyx_GIVEREF(__pyx_n_u_ctgevc);
  PyList_SET_ITEM(__pyx_t_1, 38, __pyx_n_u_ctgevc);
  __Pyx_INCREF(__pyx_n_u_ztgevc);
  __Pyx_GIVEREF(__pyx_n_u_ztgevc);
  PyList_SET_ITEM(__pyx_t_1, 39, __pyx_n_u_ztgevc);
  __Pyx_INCREF(__pyx_n_u_prepare_for_lapack);
  __Pyx_GIVEREF(__pyx_n_u_prepare_for_lapack);
  PyList_SET_ITEM(__pyx_t_1, 40, __pyx_n_u_prepare_for_lapack);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":23
 *            'prepare_for_lapack']
 * 
 * import numpy as np             # <<<<<<<<<<<<<<
 * cimport numpy as np
 * 
 */
  __Pyx_TraceLine(23,0,__PYX_ERR(0, 23, __pyx_L1_error))
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":28
 * # Strangely absolute imports from kwant.linalg.f_lapack don't work here.  So
 * # continue using traditional implicit relative imports.
 * from . import f_lapack             # <<<<<<<<<<<<<<
 * from . cimport f_lapack
 * from .f_lapack cimport l_int, l_logical
 */
  __Pyx_TraceLine(28,0,__PYX_ERR(0, 28, __pyx_L1_error))
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_f_lapack);
  __Pyx_GIVEREF(__pyx_n_s_f_lapack);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_f_lapack);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s__106, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_f_lapack); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_f_lapack, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":32
 * from .f_lapack cimport l_int, l_logical
 * 
 * int_dtype = f_lapack.l_int_dtype             # <<<<<<<<<<<<<<
 * logical_dtype = f_lapack.l_logical_dtype
 * 
 */
  __Pyx_TraceLine(32,0,__PYX_ERR(0, 32, __pyx_L1_error))
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_l_int_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_int_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":33
 * 
 * int_dtype = f_lapack.l_int_dtype
 * logical_dtype = f_lapack.l_logical_dtype             # <<<<<<<<<<<<<<
 * 
 * # exceptions
 */
  __Pyx_TraceLine(33,0,__PYX_ERR(0, 33, __pyx_L1_error))
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_f_lapack); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_l_logical_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __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_logical_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":37
 * # exceptions
 * 
 * class LinAlgError(RuntimeError):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
  __Pyx_TraceLine(37,0,__PYX_ERR(0, 37, __pyx_L1_error))
  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__107); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_tuple__107, __pyx_n_s_LinAlgError, __pyx_n_s_LinAlgError, (PyObject *) NULL, __pyx_n_s_kwant_linalg_lapack, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_LinAlgError, __pyx_tuple__107, __pyx_t_1, NULL, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_LinAlgError, __pyx_t_3) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __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;

  /* "kwant/linalg/lapack.pyx":42
 * 
 * # some helper functions
 * def filter_args(select, args):             # <<<<<<<<<<<<<<
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 */
  __Pyx_TraceLine(42,0,__PYX_ERR(0, 42, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_1filter_args, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_filter_args, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":45
 *     return tuple([arg for sel, arg in zip(select, args) if sel])
 * 
 * def assert_fortran_mat(*mats):             # <<<<<<<<<<<<<<
 *     # This is a workaround for a bug in NumPy version < 2.0,
 *     # where 1x1 matrices do not have the F_Contiguous flag set correctly.
 */
  __Pyx_TraceLine(45,0,__PYX_ERR(0, 45, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_3assert_fortran_mat, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_assert_fortran_mat, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":55
 * 
 * # Wrappers for xGETRF
 * def sgetrf(np.ndarray[np.float32_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __Pyx_TraceLine(55,0,__PYX_ERR(0, 55, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_5sgetrf, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sgetrf, __pyx_t_2) < 0) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":72
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def dgetrf(np.ndarray[np.float64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __Pyx_TraceLine(72,0,__PYX_ERR(0, 72, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_7dgetrf, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dgetrf, __pyx_t_2) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":89
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def cgetrf(np.ndarray[np.complex64_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __Pyx_TraceLine(89,0,__PYX_ERR(0, 89, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_9cgetrf, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cgetrf, __pyx_t_2) < 0) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":106
 *     return (A, ipiv, info > 0 or M != N)
 * 
 * def zgetrf(np.ndarray[np.complex128_t, ndim=2] A):             # <<<<<<<<<<<<<<
 *     cdef l_int M, N, info
 *     cdef np.ndarray[l_int, ndim=1] ipiv
 */
  __Pyx_TraceLine(106,0,__PYX_ERR(0, 106, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_11zgetrf, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zgetrf, __pyx_t_2) < 0) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":125
 * # Wrappers for xGETRS
 * 
 * def sgetrs(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __Pyx_TraceLine(125,0,__PYX_ERR(0, 125, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_13sgetrs, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sgetrs, __pyx_t_2) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":155
 *     return b
 * 
 * def dgetrs(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __Pyx_TraceLine(155,0,__PYX_ERR(0, 155, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_15dgetrs, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dgetrs, __pyx_t_2) < 0) __PYX_ERR(0, 155, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":185
 *     return b
 * 
 * def cgetrs(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __Pyx_TraceLine(185,0,__PYX_ERR(0, 185, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_17cgetrs, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cgetrs, __pyx_t_2) < 0) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":215
 *     return b
 * 
 * def zgetrs(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            np.ndarray[l_int, ndim=1] IPIV, B):
 *     cdef l_int N, NRHS, info
 */
  __Pyx_TraceLine(215,0,__PYX_ERR(0, 215, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_19zgetrs, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zgetrs, __pyx_t_2) < 0) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":247
 * # Wrappers for xGECON
 * 
 * def sgecon(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __Pyx_TraceLine(247,0,__PYX_ERR(0, 247, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_21sgecon, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sgecon, __pyx_t_2) < 0) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __Pyx_TraceLine(268,0,__PYX_ERR(0, 268, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_23dgecon, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dgecon, __pyx_t_2) < 0) __PYX_ERR(0, 268, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __Pyx_TraceLine(289,0,__PYX_ERR(0, 289, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_25cgecon, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cgecon, __pyx_t_2) < 0) __PYX_ERR(0, 289, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = b"1"):
 *     cdef l_int N, info
 */
  __Pyx_TraceLine(310,0,__PYX_ERR(0, 310, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_27zgecon, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zgecon, __pyx_t_2) < 0) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":334
 * 
 * # Helper function for xGGEV
 * def ggev_postprocess(dtype, alphar, alphai, vl_r=None, vr_r=None):             # <<<<<<<<<<<<<<
 *     # depending on whether the eigenvalues are purely real or complex,
 *     # some post-processing of the eigenvalues and -vectors is necessary
 */
  __Pyx_TraceLine(334,0,__PYX_ERR(0, 334, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_29ggev_postprocess, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ggev_postprocess, __pyx_t_2) < 0) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":366
 * 
 * 
 * def sggev(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           left=False, right=True):
 */
  __Pyx_TraceLine(366,0,__PYX_ERR(0, 366, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_31sggev, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sggev, __pyx_t_2) < 0) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":436
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __Pyx_TraceLine(436,0,__PYX_ERR(0, 436, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_33dggev, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dggev, __pyx_t_2) < 0) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":506
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __Pyx_TraceLine(506,0,__PYX_ERR(0, 506, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_35cggev, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cggev, __pyx_t_2) < 0) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":576
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */
  __Pyx_TraceLine(576,0,__PYX_ERR(0, 576, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_37zggev, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zggev, __pyx_t_2) < 0) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":646
 * 
 * # Wrapper for xGEES
 * def sgees(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __Pyx_TraceLine(646,0,__PYX_ERR(0, 646, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_39sgees, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sgees, __pyx_t_2) < 0) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":698
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __Pyx_TraceLine(698,0,__PYX_ERR(0, 698, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_41dgees, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dgees, __pyx_t_2) < 0) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":750
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __Pyx_TraceLine(750,0,__PYX_ERR(0, 750, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_43cgees, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cgees, __pyx_t_2) < 0) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":799
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __Pyx_TraceLine(799,0,__PYX_ERR(0, 799, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_45zgees, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zgees, __pyx_t_2) < 0) __PYX_ERR(0, 799, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":848
 * 
 * # Wrapper for xTRSEN
 * def strsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(848,0,__PYX_ERR(0, 848, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_47strsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_strsen, __pyx_t_2) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":906
 * 
 * 
 * def dtrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(906,0,__PYX_ERR(0, 906, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_49dtrsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtrsen, __pyx_t_2) < 0) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":964
 * 
 * 
 * def ctrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(964,0,__PYX_ERR(0, 964, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_51ctrsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 964, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctrsen, __pyx_t_2) < 0) __PYX_ERR(0, 964, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1012
 * 
 * 
 * def ztrsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(1012,0,__PYX_ERR(0, 1012, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_53ztrsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ztrsen, __pyx_t_2) < 0) __PYX_ERR(0, 1012, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1061
 * 
 * # Helper function for xTREVC and xTGEVC
 * def txevc_postprocess(dtype, T, vreal, np.ndarray[l_logical] select):             # <<<<<<<<<<<<<<
 *     cdef int N, M, i, m, indx
 * 
 */
  __Pyx_TraceLine(1061,0,__PYX_ERR(0, 1061, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_55txevc_postprocess, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_txevc_postprocess, __pyx_t_2) < 0) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1100
 * 
 * # Wrappers for xTREVC
 * def strevc(np.ndarray[np.float32_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __Pyx_TraceLine(1100,0,__PYX_ERR(0, 1100, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_57strevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_strevc, __pyx_t_2) < 0) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1204
 * 
 * 
 * def dtrevc(np.ndarray[np.float64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __Pyx_TraceLine(1204,0,__PYX_ERR(0, 1204, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_59dtrevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtrevc, __pyx_t_2) < 0) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1307
 * 
 * 
 * def ctrevc(np.ndarray[np.complex64_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __Pyx_TraceLine(1307,0,__PYX_ERR(0, 1307, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_61ctrevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctrevc, __pyx_t_2) < 0) __PYX_ERR(0, 1307, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1388
 * 
 * 
 * def ztrevc(np.ndarray[np.complex128_t, ndim=2] T,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 *            np.ndarray[l_logical] select=None,
 */
  __Pyx_TraceLine(1388,0,__PYX_ERR(0, 1388, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_63ztrevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ztrevc, __pyx_t_2) < 0) __PYX_ERR(0, 1388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1470
 * 
 * # wrappers for xGGES
 * def sgges(np.ndarray[np.float32_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float32_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __Pyx_TraceLine(1470,0,__PYX_ERR(0, 1470, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_65sgges, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sgges, __pyx_t_2) < 0) __PYX_ERR(0, 1470, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1545
 * 
 * 
 * def dgges(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __Pyx_TraceLine(1545,0,__PYX_ERR(0, 1545, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_67dgges, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dgges, __pyx_t_2) < 0) __PYX_ERR(0, 1545, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1620
 * 
 * 
 * def cgges(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __Pyx_TraceLine(1620,0,__PYX_ERR(0, 1620, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_69cgges, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cgges, __pyx_t_2) < 0) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1690
 * 
 * 
 * def zgges(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           calc_q=True, calc_z=True, calc_ev=True):
 */
  __Pyx_TraceLine(1690,0,__PYX_ERR(0, 1690, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_71zgges, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_zgges, __pyx_t_2) < 0) __PYX_ERR(0, 1690, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1761
 * 
 * # wrappers for xTGSEN
 * def stgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] S,
 *            np.ndarray[np.float32_t, ndim=2] T,
 */
  __Pyx_TraceLine(1761,0,__PYX_ERR(0, 1761, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_73stgsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stgsen, __pyx_t_2) < 0) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1840
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */
  __Pyx_TraceLine(1840,0,__PYX_ERR(0, 1840, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_75dtgsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1840, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtgsen, __pyx_t_2) < 0) __PYX_ERR(0, 1840, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1919
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */
  __Pyx_TraceLine(1919,0,__PYX_ERR(0, 1919, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_77ctgsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctgsen, __pyx_t_2) < 0) __PYX_ERR(0, 1919, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1990
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */
  __Pyx_TraceLine(1990,0,__PYX_ERR(0, 1990, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_79ztgsen, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1990, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ztgsen, __pyx_t_2) < 0) __PYX_ERR(0, 1990, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2062
 * 
 * # xTGEVC
 * def stgevc(np.ndarray[np.float32_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float32_t, ndim=2] T,
 *            np.ndarray[np.float32_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(2062,0,__PYX_ERR(0, 2062, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_81stgevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_stgevc, __pyx_t_2) < 0) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2173
 * 
 * 
 * def dtgevc(np.ndarray[np.float64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] T,
 *            np.ndarray[np.float64_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(2173,0,__PYX_ERR(0, 2173, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_83dtgevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dtgevc, __pyx_t_2) < 0) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2285
 * 
 * 
 * def ctgevc(np.ndarray[np.complex64_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] T,
 *            np.ndarray[np.complex64_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(2285,0,__PYX_ERR(0, 2285, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_85ctgevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctgevc, __pyx_t_2) < 0) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2374
 * 
 * 
 * def ztgevc(np.ndarray[np.complex128_t, ndim=2] S,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] T,
 *            np.ndarray[np.complex128_t, ndim=2] Q=None,
 */
  __Pyx_TraceLine(2374,0,__PYX_ERR(0, 2374, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_87ztgevc, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ztgevc, __pyx_t_2) < 0) __PYX_ERR(0, 2374, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2463
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */
  __Pyx_TraceLine(2463,0,__PYX_ERR(0, 2463, __pyx_L1_error))
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_89prepare_for_lapack, NULL, __pyx_n_s_kwant_linalg_lapack); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_prepare_for_lapack, __pyx_t_2) < 0) __PYX_ERR(0, 2463, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1
 * # Copyright 2011-2013 Kwant authors.             # <<<<<<<<<<<<<<
 * #
 * # This file is part of Kwant.  It is subject to the license terms in the file
 */
  __Pyx_TraceLine(1,0,__PYX_ERR(0, 1, __pyx_L1_error))
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  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;

  /* "../../../../../../usr/lib/python3/dist-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */
  __Pyx_TraceReturn(Py_None, 0);

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init kwant.linalg.lapack", 0, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init kwant.linalg.lapack");
  }
  __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((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"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;
}

/* 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_CheckExact(key)) || 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
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(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
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(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;
}

/* 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;
    tstate->tracing++;
    tstate->use_tracing = 0;
    __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;
    tstate->use_tracing = (tstate->c_profilefunc ||
                           (CYTHON_TRACE && tstate->c_tracefunc));
    tstate->tracing--;
    if (retval) {
        __Pyx_ErrRestoreInState(tstate, type, value, traceback);
        return tstate->use_tracing && 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) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyCodeObject *py_code = 0;
    #if PY_MAJOR_VERSION < 3
    py_funcname = PyString_FromString(funcname);
    py_srcfile = PyString_FromString(srcfile);
    #else
    py_funcname = PyUnicode_FromString(funcname);
    py_srcfile = PyUnicode_FromString(srcfile);
    #endif
    if (!py_funcname | !py_srcfile) goto bad;
    py_code = PyCode_New(
        0,
        #if PY_MAJOR_VERSION >= 3
        0,
        #endif
        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);
    return py_code;
}
#endif

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->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

/* 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;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* 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;
}

/* 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((0 <= wrapped_i) & (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((0 <= wrapped_i) & (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((n >= 0) & (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((n >= 0) & (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));
}

/* 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()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* 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_COMPILING_IN_PYPY
        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);
#else
        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);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#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;
}

/* 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 '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 '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 '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;
    int ndim = ctx->head->field->type->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;
    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 '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->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;
        }
    }
  }
}

/* BufferGetAndValidate */
  static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (unlikely(info->buf == NULL)) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}
static void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static int __Pyx__GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  buf->buf = NULL;
  if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) {
    __Pyx_ZeroBuffer(buf);
    return -1;
  }
  if (unlikely(buf->ndim != nd)) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__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 "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_SafeReleaseBuffer(buf);
  return -1;
}

/* GetModuleGlobalName */
  static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    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);
    if (likely(result)) {
        Py_INCREF(result);
    } else if (unlikely(PyErr_Occurred())) {
        result = NULL;
    } else {
#else
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* 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)));
    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)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
      #if CYTHON_FAST_PYCALL
#include "frameobject.h"
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 = f->f_localsplus;
    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, int 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, nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* 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 (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
            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

/* 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;
}

/* BufferFallbackError */
      static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

/* PyIntBinop */
      #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int 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))) {
        const long b = intval;
        long a;
        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;
                    }
                    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;
                    }
                    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;
                    }
                    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;
                    }
                    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;
                    }
                    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;
                    }
                    CYTHON_FALLTHROUGH;
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                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);
}
#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
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) {
#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

/* PyIntBinop */
        #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #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;
    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
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #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

/* None */
        static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* 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((n >= 0) & (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);
}

/* 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();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#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
}

/* RaiseNoneIterError */
          static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* SaveResetException */
          #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if PY_VERSION_HEX >= 0x030700A3
    *type = tstate->exc_state.exc_type;
    *value = tstate->exc_state.exc_value;
    *tb = tstate->exc_state.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 PY_VERSION_HEX >= 0x030700A3
    tmp_type = tstate->exc_state.exc_type;
    tmp_value = tstate->exc_state.exc_value;
    tmp_tb = tstate->exc_state.exc_traceback;
    tstate->exc_state.exc_type = type;
    tstate->exc_state.exc_value = value;
    tstate->exc_state.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

/* 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

/* 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 PY_VERSION_HEX >= 0x030700A3
    tmp_type = tstate->exc_state.exc_type;
    tmp_value = tstate->exc_state.exc_value;
    tmp_tb = tstate->exc_state.exc_traceback;
    tstate->exc_state.exc_type = local_type;
    tstate->exc_state.exc_value = local_value;
    tstate->exc_state.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;
}

/* 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 (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, 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;
}

/* 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;
}

/* CalculateMetaclass */
            static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

/* Py3ClassCreate */
            static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

/* 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)) {
      use_cline = __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;
        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (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"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    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);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    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;
    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) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __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);
}

/* 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 = 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 = 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:
                        z = __Pyx_c_prod_float(a, a);
                        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) {
                    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, -1);
                }
            } 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 = 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 = 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:
                        z = __Pyx_c_prod_double(a, a);
                        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) {
                    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, -1);
                }
            } 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

#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_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__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)) {}
        else if (__Pyx_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view);
    view->obj = NULL;
    Py_DECREF(obj);
}
#endif


            /* CIntToPy */
            static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    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);
    }
}

/* CIntToPy */
            static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    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);
    }
}

/* 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;\
    }

/* CIntToPy */
            static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value) {
    const enum NPY_TYPES neg_one = (enum NPY_TYPES) -1, const_zero = (enum NPY_TYPES) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum NPY_TYPES) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(enum NPY_TYPES) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= 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(enum NPY_TYPES),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
            static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    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
            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 long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    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
            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;
}

/* 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

/* CheckBinaryVersion */
            static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        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;
}

/* ModuleImport */
            #ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

/* TypeImport */
            #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    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;
#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;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#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 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(x);
  }
#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 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 */
