/* Generated by Cython 0.19 on Tue Sep 30 17:36:23 2014 */

#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
#else
#define CYTHON_USE_PYLONG_INTERNALS 0
#endif
#endif
#endif
#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 < 0x02040000
    #error Cython requires Python 2.4+.
#else
#include <stddef.h> /* For offsetof */
#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
#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_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define CYTHON_FORMAT_SSIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
                                (PyErr_Format(PyExc_TypeError, \
                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
                                 (PyObject*)0))
  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
                                  !PyComplex_Check(o))
  #define PyIndex_Check __Pyx_PyIndex_Check
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
  #define CYTHON_FORMAT_SSIZE_T "z"
  #define __Pyx_PyIndex_Check PyIndex_Check
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)
  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;
  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#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, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#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)
#endif
#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_TPFLAGS_HAVE_VERSION_TAG 0
#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_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #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_READ(k, d, i)   ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#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
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#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_CheckExact(obj) || PyUnicode_CheckExact(obj) || \
                                         PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (Py_TYPE(obj) == &PyBaseString_Type)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#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
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_VERSION_HEX < 0x03020000
  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) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifndef CYTHON_INLINE
  #if 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
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
   a quiet NaN. */
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#if PY_MAJOR_VERSION >= 3
  #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

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__kwant__linalg__lapack
#define __PYX_HAVE_API__kwant__linalg__lapack
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#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
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/

#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
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(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_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromUString(s)  __Pyx_PyObject_FromString((char*)s)
#define __Pyx_PyBytes_FromUString(s)   __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyStr_FromUString(s)     __Pyx_PyStr_FromString((char*)s)
#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return u_end - u - 1;
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#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_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
#if CYTHON_COMPILING_IN_CPYTHON
#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 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params() {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    if (strcmp(PyBytes_AsString(default_encoding), "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        const char* default_encoding_c = PyBytes_AS_STRING(default_encoding);
        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 == NULL) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (ascii_chars_b == NULL || strncmp(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 '%s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
    }
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return 0;
bad:
    Py_XDECREF(sys);
    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() {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    default_encoding_c = PyBytes_AS_STRING(default_encoding);
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(sys);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


#ifdef __GNUC__
  /* Test for GCC > 2.95 */
  #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
    #define likely(x)   __builtin_expect(!!(x), 1)
    #define unlikely(x) __builtin_expect(!!(x), 0)
  #else /* __GNUC__ > 2 ... */
    #define likely(x)   (x)
    #define unlikely(x) (x)
  #endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */

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

#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[] = {
  "lapack.pyx",
  "numpy.pxd",
  "type.pxd",
};
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name; /* for error messages only */
  struct __Pyx_StructField_* fields;
  size_t size;     /* sizeof(type) */
  size_t arraysize[8]; /* length of array in each dimension */
  int ndim;
  char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject, c_H_ar */
  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;


/* "numpy.pxd":723
 * # 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;

/* "numpy.pxd":724
 * 
 * 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;

/* "numpy.pxd":725
 * 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;

/* "numpy.pxd":726
 * 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;

/* "numpy.pxd":730
 * #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;

/* "numpy.pxd":731
 * 
 * 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;

/* "numpy.pxd":732
 * 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;

/* "numpy.pxd":733
 * 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;

/* "numpy.pxd":737
 * #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;

/* "numpy.pxd":738
 * 
 * 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;

/* "numpy.pxd":747
 * # 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;

/* "numpy.pxd":748
 * # 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;

/* "numpy.pxd":749
 * 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;

/* "numpy.pxd":751
 * 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;

/* "numpy.pxd":752
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "numpy.pxd":753
 * 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;

/* "numpy.pxd":755
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "numpy.pxd":756
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "numpy.pxd":758
 * 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;

/* "numpy.pxd":759
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "numpy.pxd":760
 * 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;
#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

#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


/*--- Type declarations ---*/

/* "numpy.pxd":762
 * 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;

/* "numpy.pxd":763
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "numpy.pxd":764
 * 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;

/* "numpy.pxd":766
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
#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); /*proto*/
  #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 /* CYTHON_REFNANNY */
#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)

#if CYTHON_COMPILING_IN_CPYTHON
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);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*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); /*proto*/

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

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

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

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

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

#if CYTHON_COMPILING_IN_CPYTHON
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

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

#define __Pyx_GetItemInt(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_Fast(o, i, is_list, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
#define __Pyx_GetItemInt_List(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_List_Fast(o, i, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func, is_list, wraparound, boundscheck) \
    (((size) <= sizeof(Py_ssize_t)) ? \
    __Pyx_GetItemInt_Tuple_Fast(o, i, wraparound, boundscheck) : \
    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE 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);

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

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

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact); /*proto*/

static CYTHON_INLINE int  __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);

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

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

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

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

#if CYTHON_COMPILING_IN_CPYTHON
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

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

#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(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
    #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

static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eqf(a, b)   ((a)==(b))
    #define __Pyx_c_sumf(a, b)  ((a)+(b))
    #define __Pyx_c_difff(a, b) ((a)-(b))
    #define __Pyx_c_prodf(a, b) ((a)*(b))
    #define __Pyx_c_quotf(a, b) ((a)/(b))
    #define __Pyx_c_negf(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zerof(z) ((z)==(float)0)
    #define __Pyx_c_conjf(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_absf(z)     (::std::abs(z))
        #define __Pyx_c_powf(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zerof(z) ((z)==0)
    #define __Pyx_c_conjf(z)    (conjf(z))
    #if 1
        #define __Pyx_c_absf(z)     (cabsf(z))
        #define __Pyx_c_powf(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq(a, b)   ((a)==(b))
    #define __Pyx_c_sum(a, b)  ((a)+(b))
    #define __Pyx_c_diff(a, b) ((a)-(b))
    #define __Pyx_c_prod(a, b) ((a)*(b))
    #define __Pyx_c_quot(a, b) ((a)/(b))
    #define __Pyx_c_neg(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero(z) ((z)==(double)0)
    #define __Pyx_c_conj(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (::std::abs(z))
        #define __Pyx_c_pow(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero(z) ((z)==0)
    #define __Pyx_c_conj(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (cabs(z))
        #define __Pyx_c_pow(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

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


static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0};
static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1};

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

static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/

static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
                                   PyObject *qualname, PyObject *modname); /*proto*/

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static int __Pyx_check_binary_version(void);

#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

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

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

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __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);

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

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


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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

/* 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.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"
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_xrange;
static PyObject *__pyx_builtin_AssertionError;
static PyObject *__pyx_builtin_range;
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 char __pyx_k_1[] = "Input matrix must be Fortran contiguous";
static char __pyx_k_3[] = "Argument error in sgetrf";
static char __pyx_k_4[] = "Argument error in dgetrf";
static char __pyx_k_5[] = "Argument error in cgetrf";
static char __pyx_k_6[] = "Argument error in zgetrf";
static char __pyx_k_7[] = "In dgetrs: B must be a Fortran ordered NumPy array";
static char __pyx_k_9[] = "In sgetrs: B must be a vector or matrix";
static char __pyx_k_11[] = "Argument error in sgetrs";
static char __pyx_k_13[] = "In dgetrs: B must be a vector or matrix";
static char __pyx_k_15[] = "Argument error in dgetrs";
static char __pyx_k_17[] = "In cgetrs: B must be a vector or matrix";
static char __pyx_k_19[] = "Argument error in cgetrs";
static char __pyx_k_21[] = "In zgetrs: B must be a vector or matrix";
static char __pyx_k_23[] = "Argument error in zgetrs";
static char __pyx_k_24[] = "Argument error in sgecon";
static char __pyx_k_25[] = "Argument error in dgecon";
static char __pyx_k_26[] = "Argument error in cgecon";
static char __pyx_k_27[] = "Argument error in zgecon";
static char __pyx_k_38[] = "Argument error in sggev";
static char __pyx_k_39[] = "QZ iteration failed to converge in sggev";
static char __pyx_k_43[] = "Argument error in dggev";
static char __pyx_k_44[] = "QZ iteration failed to converge in dggev";
static char __pyx_k_49[] = "Argument error in cggev";
static char __pyx_k_50[] = "QZ iteration failed to converge in cggev";
static char __pyx_k_55[] = "Argument error in zggev";
static char __pyx_k_56[] = "QZ iteration failed to converge in zggev";
static char __pyx_k_60[] = "Argument error in sgees";
static char __pyx_k_61[] = "QR iteration failed to converge in sgees";
static char __pyx_k_65[] = "Argument error in dgees";
static char __pyx_k_66[] = "QR iteration failed to converge in dgees";
static char __pyx_k_70[] = "Argument error in cgees";
static char __pyx_k_71[] = "QR iteration failed to converge in cgees";
static char __pyx_k_75[] = "Argument error in zgees";
static char __pyx_k_76[] = "QR iteration failed to converge in zgees";
static char __pyx_k_79[] = "Argument error in strsen";
static char __pyx_k_80[] = "Reordering failed; problem is very ill-conditioned";
static char __pyx_k_83[] = "Argument error in dtrsen";
static char __pyx_k_86[] = "Argument error in ctrsen";
static char __pyx_k_89[] = "Argument error in ztrsen";
static char __pyx_k__1[] = "1";
static char __pyx_k__A[] = "A";
static char __pyx_k__B[] = "B";
static char __pyx_k__F[] = "F";
static char __pyx_k__H[] = "H";
static char __pyx_k__I[] = "I";
static char __pyx_k__L[] = "L";
static char __pyx_k__M[] = "M";
static char __pyx_k__N[] = "N";
static char __pyx_k__O[] = "O";
static char __pyx_k__Q[] = "Q";
static char __pyx_k__R[] = "R";
static char __pyx_k__S[] = "S";
static char __pyx_k__T[] = "T";
static char __pyx_k__V[] = "V";
static char __pyx_k__Z[] = "Z";
static char __pyx_k__b[] = "b";
static char __pyx_k__c[] = "c";
static char __pyx_k__d[] = "d";
static char __pyx_k__f[] = "f";
static char __pyx_k__g[] = "g";
static char __pyx_k__h[] = "h";
static char __pyx_k__i[] = "i";
static char __pyx_k__k[] = "k";
static char __pyx_k__l[] = "l";
static char __pyx_k__m[] = "m";
static char __pyx_k__q[] = "q";
static char __pyx_k__s[] = "s";
static char __pyx_k__v[] = "v";
static char __pyx_k__w[] = "w";
static char __pyx_k__z[] = "z";
static char __pyx_k_101[] = "Argument error in strevc";
static char __pyx_k_102[] = "Unexpected number of eigenvectors returned in strevc";
static char __pyx_k_105[] = "Argument error in dtrevc";
static char __pyx_k_106[] = "Unexpected number of eigenvectors returned in dtrevc";
static char __pyx_k_109[] = "Argument error in ctrevc";
static char __pyx_k_110[] = "Unexpected number of eigenvectors returned in ctrevc";
static char __pyx_k_113[] = "Argument error in ztrevc";
static char __pyx_k_114[] = "Unexpected number of eigenvectors returned in ztrevc";
static char __pyx_k_118[] = "QZ iteration failed to converge in sgges";
static char __pyx_k_123[] = "QZ iteration failed to converge in dgges";
static char __pyx_k_128[] = "QZ iteration failed to converge in cgges";
static char __pyx_k_133[] = "QZ iteration failed to converge in zgges";
static char __pyx_k_136[] = "Argument error in stgsen";
static char __pyx_k_139[] = "Argument error in dtgsen";
static char __pyx_k_142[] = "Argument error in ctgsen";
static char __pyx_k_145[] = "Argument error in ztgsen";
static char __pyx_k_149[] = "Argument error in stgevc";
static char __pyx_k_150[] = "Unexpected number of eigenvectors returned in stgevc";
static char __pyx_k_153[] = "Argument error in dtgevc";
static char __pyx_k_154[] = "Unexpected number of eigenvectors returned in dtgevc";
static char __pyx_k_157[] = "Argument error in ctgevc";
static char __pyx_k_158[] = "Unexpected number of eigenvectors returned in ctgevc";
static char __pyx_k_161[] = "Argument error in ztgevc";
static char __pyx_k_162[] = "Unexpected number of eigenvectors returned in ztgevc";
static char __pyx_k_163[] = "Argument cannot be interpreted as a numeric array";
static char __pyx_k_165[] = "Unexpected data type from common_type";
static char __pyx_k_167[] = "Dimensionality of array is not 1 or 2";
static char __pyx_k_169[] = "ndarray is not C contiguous";
static char __pyx_k_171[] = "ndarray is not Fortran contiguous";
static char __pyx_k_173[] = "Non-native byte order not supported";
static char __pyx_k_175[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_176[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_179[] = "Format string allocated too short.";
static char __pyx_k_181[] = "Low-level access to LAPACK functions. ";
static char __pyx_k_182[] = "kwant.linalg.lapack";
static char __pyx_k_185[] = "/home/cwg/work/our/src/11-kwant/kwant/linalg/lapack.pyx";
static char __pyx_k__LU[] = "LU";
static char __pyx_k__MM[] = "MM";
static char __pyx_k__Zd[] = "Zd";
static char __pyx_k__Zf[] = "Zf";
static char __pyx_k__Zg[] = "Zg";
static char __pyx_k__np[] = "np";
static char __pyx_k__vl[] = "vl";
static char __pyx_k__vr[] = "vr";
static char __pyx_k__vs[] = "vs";
static char __pyx_k__wi[] = "wi";
static char __pyx_k__wr[] = "wr";
static char __pyx_k__arg[] = "arg";
static char __pyx_k__arr[] = "arr";
static char __pyx_k__dot[] = "dot";
static char __pyx_k__mat[] = "mat";
static char __pyx_k__ret[] = "ret";
static char __pyx_k__sel[] = "sel";
static char __pyx_k__vsl[] = "vsl";
static char __pyx_k__vsr[] = "vsr";
static char __pyx_k__zip[] = "zip";
static char __pyx_k__IPIV[] = "IPIV";
static char __pyx_k__NRHS[] = "NRHS";
static char __pyx_k__args[] = "args";
static char __pyx_k__beta[] = "beta";
static char __pyx_k__conj[] = "conj";
static char __pyx_k__copy[] = "copy";
static char __pyx_k__ijob[] = "ijob";
static char __pyx_k__imag[] = "imag";
static char __pyx_k__indx[] = "indx";
static char __pyx_k__info[] = "info";
static char __pyx_k__ipiv[] = "ipiv";
static char __pyx_k__left[] = "left";
static char __pyx_k__mats[] = "mats";
static char __pyx_k__ndim[] = "ndim";
static char __pyx_k__norm[] = "norm";
static char __pyx_k__ones[] = "ones";
static char __pyx_k__sdim[] = "sdim";
static char __pyx_k__side[] = "side";
static char __pyx_k__size[] = "size";
static char __pyx_k__vl_r[] = "vl_r";
static char __pyx_k__vr_r[] = "vr_r";
static char __pyx_k__work[] = "work";
static char __pyx_k__alpha[] = "alpha";
static char __pyx_k__array[] = "array";
static char __pyx_k__cgees[] = "cgees";
static char __pyx_k__cgges[] = "cgges";
static char __pyx_k__cggev[] = "cggev";
static char __pyx_k__compq[] = "compq";
static char __pyx_k__dgees[] = "dgees";
static char __pyx_k__dgges[] = "dgges";
static char __pyx_k__dggev[] = "dggev";
static char __pyx_k__dtype[] = "dtype";
static char __pyx_k__empty[] = "empty";
static char __pyx_k__flags[] = "flags";
static char __pyx_k__iwork[] = "iwork";
static char __pyx_k__jobvl[] = "jobvl";
static char __pyx_k__jobvr[] = "jobvr";
static char __pyx_k__jobvs[] = "jobvs";
static char __pyx_k__lwork[] = "lwork";
static char __pyx_k__normA[] = "normA";
static char __pyx_k__npmat[] = "npmat";
static char __pyx_k__numpy[] = "numpy";
static char __pyx_k__order[] = "order";
static char __pyx_k__ovwrt[] = "ovwrt";
static char __pyx_k__q_ptr[] = "q_ptr";
static char __pyx_k__qwork[] = "qwork";
static char __pyx_k__range[] = "range";
static char __pyx_k__rcond[] = "rcond";
static char __pyx_k__right[] = "right";
static char __pyx_k__rwork[] = "rwork";
static char __pyx_k__sgees[] = "sgees";
static char __pyx_k__sgges[] = "sgges";
static char __pyx_k__sggev[] = "sggev";
static char __pyx_k__shape[] = "shape";
static char __pyx_k__vreal[] = "vreal";
static char __pyx_k__wantq[] = "wantq";
static char __pyx_k__wantz[] = "wantz";
static char __pyx_k__z_ptr[] = "z_ptr";
static char __pyx_k__zgees[] = "zgees";
static char __pyx_k__zgges[] = "zgges";
static char __pyx_k__zggev[] = "zggev";
static char __pyx_k__alphai[] = "alphai";
static char __pyx_k__alphar[] = "alphar";
static char __pyx_k__astype[] = "astype";
static char __pyx_k__backtr[] = "backtr";
static char __pyx_k__calc_q[] = "calc_q";
static char __pyx_k__calc_z[] = "calc_z";
static char __pyx_k__cgecon[] = "cgecon";
static char __pyx_k__cgetrf[] = "cgetrf";
static char __pyx_k__cgetrs[] = "cgetrs";
static char __pyx_k__ctgevc[] = "ctgevc";
static char __pyx_k__ctgsen[] = "ctgsen";
static char __pyx_k__ctrevc[] = "ctrevc";
static char __pyx_k__ctrsen[] = "ctrsen";
static char __pyx_k__dgecon[] = "dgecon";
static char __pyx_k__dgetrf[] = "dgetrf";
static char __pyx_k__dgetrs[] = "dgetrs";
static char __pyx_k__dtgevc[] = "dtgevc";
static char __pyx_k__dtgsen[] = "dtgsen";
static char __pyx_k__dtrevc[] = "dtrevc";
static char __pyx_k__dtrsen[] = "dtrsen";
static char __pyx_k__howmny[] = "howmny";
static char __pyx_k__jobvsl[] = "jobvsl";
static char __pyx_k__jobvsr[] = "jobvsr";
static char __pyx_k__liwork[] = "liwork";
static char __pyx_k__number[] = "number";
static char __pyx_k__qiwork[] = "qiwork";
static char __pyx_k__select[] = "select";
static char __pyx_k__sgecon[] = "sgecon";
static char __pyx_k__sgetrf[] = "sgetrf";
static char __pyx_k__sgetrs[] = "sgetrs";
static char __pyx_k__stgevc[] = "stgevc";
static char __pyx_k__stgsen[] = "stgsen";
static char __pyx_k__strevc[] = "strevc";
static char __pyx_k__strsen[] = "strsen";
static char __pyx_k__vl_ptr[] = "vl_ptr";
static char __pyx_k__vr_ptr[] = "vr_ptr";
static char __pyx_k__vs_ptr[] = "vs_ptr";
static char __pyx_k__xrange[] = "xrange";
static char __pyx_k__zgecon[] = "zgecon";
static char __pyx_k__zgetrf[] = "zgetrf";
static char __pyx_k__zgetrs[] = "zgetrs";
static char __pyx_k__ztgevc[] = "ztgevc";
static char __pyx_k__ztgsen[] = "ztgsen";
static char __pyx_k__ztrevc[] = "ztrevc";
static char __pyx_k__ztrsen[] = "ztrsen";
static char __pyx_k____all__[] = "__all__";
static char __pyx_k__calc_ev[] = "calc_ev";
static char __pyx_k__float32[] = "float32";
static char __pyx_k__float64[] = "float64";
static char __pyx_k__nonzero[] = "nonzero";
static char __pyx_k__selindx[] = "selindx";
static char __pyx_k__vsl_ptr[] = "vsl_ptr";
static char __pyx_k__vsr_ptr[] = "vsr_ptr";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__diagonal[] = "diagonal";
static char __pyx_k__f_lapack[] = "f_lapack";
static char __pyx_k__vl_r_ptr[] = "vl_r_ptr";
static char __pyx_k__vr_r_ptr[] = "vr_r_ptr";
static char __pyx_k____class__[] = "__class__";
static char __pyx_k__cmplxindx[] = "cmplxindx";
static char __pyx_k__complex64[] = "complex64";
static char __pyx_k__int_dtype[] = "int_dtype";
static char __pyx_k__overwrite[] = "overwrite";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k____import__[] = "__import__";
static char __pyx_k____module__[] = "__module__";
static char __pyx_k__asanyarray[] = "asanyarray";
static char __pyx_k__complex128[] = "complex128";
static char __pyx_k__issubdtype[] = "issubdtype";
static char __pyx_k__lapacktype[] = "lapacktype";
static char __pyx_k__select_cpy[] = "select_cpy";
static char __pyx_k__select_ptr[] = "select_ptr";
static char __pyx_k__LinAlgError[] = "LinAlgError";
static char __pyx_k__common_type[] = "common_type";
static char __pyx_k__filter_args[] = "filter_args";
static char __pyx_k__l_int_dtype[] = "l_int_dtype";
static char __pyx_k__C_CONTIGUOUS[] = "C_CONTIGUOUS";
static char __pyx_k__F_CONTIGUOUS[] = "F_CONTIGUOUS";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k____qualname__[] = "__qualname__";
static char __pyx_k____metaclass__[] = "__metaclass__";
static char __pyx_k__logical_dtype[] = "logical_dtype";
static char __pyx_k__AssertionError[] = "AssertionError";
static char __pyx_k__asfortranarray[] = "asfortranarray";
static char __pyx_k____pyx_getbuffer[] = "__pyx_getbuffer";
static char __pyx_k__l_logical_dtype[] = "l_logical_dtype";
static char __pyx_k__ggev_postprocess[] = "ggev_postprocess";
static char __pyx_k__ascontiguousarray[] = "ascontiguousarray";
static char __pyx_k__txevc_postprocess[] = "txevc_postprocess";
static char __pyx_k__assert_fortran_mat[] = "assert_fortran_mat";
static char __pyx_k__prepare_for_lapack[] = "prepare_for_lapack";
static char __pyx_k____pyx_releasebuffer[] = "__pyx_releasebuffer";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_101;
static PyObject *__pyx_kp_s_102;
static PyObject *__pyx_kp_s_105;
static PyObject *__pyx_kp_s_106;
static PyObject *__pyx_kp_s_109;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_110;
static PyObject *__pyx_kp_s_113;
static PyObject *__pyx_kp_s_114;
static PyObject *__pyx_kp_s_118;
static PyObject *__pyx_kp_s_123;
static PyObject *__pyx_kp_s_128;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_133;
static PyObject *__pyx_kp_s_136;
static PyObject *__pyx_kp_s_139;
static PyObject *__pyx_kp_s_142;
static PyObject *__pyx_kp_s_145;
static PyObject *__pyx_kp_s_149;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_s_150;
static PyObject *__pyx_kp_s_153;
static PyObject *__pyx_kp_s_154;
static PyObject *__pyx_kp_s_157;
static PyObject *__pyx_kp_s_158;
static PyObject *__pyx_kp_s_161;
static PyObject *__pyx_kp_s_162;
static PyObject *__pyx_kp_s_163;
static PyObject *__pyx_kp_s_165;
static PyObject *__pyx_kp_s_167;
static PyObject *__pyx_kp_u_169;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_u_171;
static PyObject *__pyx_kp_u_173;
static PyObject *__pyx_kp_u_175;
static PyObject *__pyx_kp_u_176;
static PyObject *__pyx_kp_u_179;
static PyObject *__pyx_n_s_182;
static PyObject *__pyx_kp_s_185;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_21;
static PyObject *__pyx_kp_s_23;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_25;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_kp_s_27;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_38;
static PyObject *__pyx_kp_s_39;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_44;
static PyObject *__pyx_kp_s_49;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_50;
static PyObject *__pyx_kp_s_55;
static PyObject *__pyx_kp_s_56;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_60;
static PyObject *__pyx_kp_s_61;
static PyObject *__pyx_kp_s_65;
static PyObject *__pyx_kp_s_66;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_70;
static PyObject *__pyx_kp_s_71;
static PyObject *__pyx_kp_s_75;
static PyObject *__pyx_kp_s_76;
static PyObject *__pyx_kp_s_79;
static PyObject *__pyx_kp_s_80;
static PyObject *__pyx_kp_s_83;
static PyObject *__pyx_kp_s_86;
static PyObject *__pyx_kp_s_89;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__A;
static PyObject *__pyx_n_s__AssertionError;
static PyObject *__pyx_n_s__B;
static PyObject *__pyx_n_s__C_CONTIGUOUS;
static PyObject *__pyx_n_s__F;
static PyObject *__pyx_n_s__F_CONTIGUOUS;
static PyObject *__pyx_n_s__IPIV;
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_n_s__Q;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__S;
static PyObject *__pyx_n_s__T;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s__Z;
static PyObject *__pyx_n_s____all__;
static PyObject *__pyx_n_s____class__;
static PyObject *__pyx_n_s____import__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____metaclass__;
static PyObject *__pyx_n_s____module__;
static PyObject *__pyx_n_s____pyx_getbuffer;
static PyObject *__pyx_n_s____pyx_releasebuffer;
static PyObject *__pyx_n_s____qualname__;
static PyObject *__pyx_n_s____test__;
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_s__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_s__cgees;
static PyObject *__pyx_n_s__cgetrf;
static PyObject *__pyx_n_s__cgetrs;
static PyObject *__pyx_n_s__cgges;
static PyObject *__pyx_n_s__cggev;
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_s__ctgsen;
static PyObject *__pyx_n_s__ctrevc;
static PyObject *__pyx_n_s__ctrsen;
static PyObject *__pyx_n_s__d;
static PyObject *__pyx_n_s__dgecon;
static PyObject *__pyx_n_s__dgees;
static PyObject *__pyx_n_s__dgetrf;
static PyObject *__pyx_n_s__dgetrs;
static PyObject *__pyx_n_s__dgges;
static PyObject *__pyx_n_s__dggev;
static PyObject *__pyx_n_s__diagonal;
static PyObject *__pyx_n_s__dot;
static PyObject *__pyx_n_s__dtgevc;
static PyObject *__pyx_n_s__dtgsen;
static PyObject *__pyx_n_s__dtrevc;
static PyObject *__pyx_n_s__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__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__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__mat;
static PyObject *__pyx_n_s__mats;
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_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_for_lapack;
static PyObject *__pyx_n_s__q_ptr;
static PyObject *__pyx_n_s__qiwork;
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_s__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_s__sgees;
static PyObject *__pyx_n_s__sgetrf;
static PyObject *__pyx_n_s__sgetrs;
static PyObject *__pyx_n_s__sgges;
static PyObject *__pyx_n_s__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_s__stgsen;
static PyObject *__pyx_n_s__strevc;
static PyObject *__pyx_n_s__strsen;
static PyObject *__pyx_n_s__txevc_postprocess;
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_s__xrange;
static PyObject *__pyx_n_s__z;
static PyObject *__pyx_n_s__z_ptr;
static PyObject *__pyx_n_s__zgecon;
static PyObject *__pyx_n_s__zgees;
static PyObject *__pyx_n_s__zgetrf;
static PyObject *__pyx_n_s__zgetrs;
static PyObject *__pyx_n_s__zgges;
static PyObject *__pyx_n_s__zggev;
static PyObject *__pyx_n_s__zip;
static PyObject *__pyx_n_s__ztgevc;
static PyObject *__pyx_n_s__ztgsen;
static PyObject *__pyx_n_s__ztrevc;
static PyObject *__pyx_n_s__ztrsen;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_15;
static PyObject *__pyx_k_36;
static PyObject *__pyx_k_37;
static PyObject *__pyx_k_41;
static PyObject *__pyx_k_42;
static PyObject *__pyx_k_46;
static PyObject *__pyx_k_47;
static PyObject *__pyx_k_52;
static PyObject *__pyx_k_53;
static PyObject *__pyx_k_58;
static PyObject *__pyx_k_59;
static PyObject *__pyx_k_63;
static PyObject *__pyx_k_64;
static PyObject *__pyx_k_68;
static PyObject *__pyx_k_69;
static PyObject *__pyx_k_73;
static PyObject *__pyx_k_74;
static PyObject *__pyx_k_78;
static PyObject *__pyx_k_82;
static PyObject *__pyx_k_85;
static PyObject *__pyx_k_88;
static PyObject *__pyx_k_99;
static PyObject *__pyx_k_100;
static PyObject *__pyx_k_103;
static PyObject *__pyx_k_104;
static PyObject *__pyx_k_107;
static PyObject *__pyx_k_108;
static PyObject *__pyx_k_111;
static PyObject *__pyx_k_112;
static PyObject *__pyx_k_115;
static PyObject *__pyx_k_116;
static PyObject *__pyx_k_117;
static PyObject *__pyx_k_120;
static PyObject *__pyx_k_121;
static PyObject *__pyx_k_122;
static PyObject *__pyx_k_125;
static PyObject *__pyx_k_126;
static PyObject *__pyx_k_127;
static PyObject *__pyx_k_130;
static PyObject *__pyx_k_131;
static PyObject *__pyx_k_132;
static PyObject *__pyx_k_135;
static PyObject *__pyx_k_138;
static PyObject *__pyx_k_141;
static PyObject *__pyx_k_144;
static PyObject *__pyx_k_147;
static PyObject *__pyx_k_148;
static PyObject *__pyx_k_151;
static PyObject *__pyx_k_152;
static PyObject *__pyx_k_155;
static PyObject *__pyx_k_156;
static PyObject *__pyx_k_159;
static PyObject *__pyx_k_160;
static PyObject *__pyx_k_tuple_2;
static PyObject *__pyx_k_tuple_8;
static PyObject *__pyx_k_slice_28;
static PyObject *__pyx_k_slice_29;
static PyObject *__pyx_k_slice_30;
static PyObject *__pyx_k_slice_31;
static PyObject *__pyx_k_slice_32;
static PyObject *__pyx_k_slice_33;
static PyObject *__pyx_k_slice_34;
static PyObject *__pyx_k_slice_35;
static PyObject *__pyx_k_slice_91;
static PyObject *__pyx_k_slice_92;
static PyObject *__pyx_k_slice_93;
static PyObject *__pyx_k_slice_94;
static PyObject *__pyx_k_slice_95;
static PyObject *__pyx_k_slice_96;
static PyObject *__pyx_k_slice_97;
static PyObject *__pyx_k_slice_98;
static PyObject *__pyx_k_tuple_10;
static PyObject *__pyx_k_tuple_12;
static PyObject *__pyx_k_tuple_14;
static PyObject *__pyx_k_tuple_16;
static PyObject *__pyx_k_tuple_18;
static PyObject *__pyx_k_tuple_20;
static PyObject *__pyx_k_tuple_22;
static PyObject *__pyx_k_tuple_40;
static PyObject *__pyx_k_tuple_45;
static PyObject *__pyx_k_tuple_48;
static PyObject *__pyx_k_tuple_51;
static PyObject *__pyx_k_tuple_54;
static PyObject *__pyx_k_tuple_57;
static PyObject *__pyx_k_tuple_62;
static PyObject *__pyx_k_tuple_67;
static PyObject *__pyx_k_tuple_72;
static PyObject *__pyx_k_tuple_77;
static PyObject *__pyx_k_tuple_81;
static PyObject *__pyx_k_tuple_84;
static PyObject *__pyx_k_tuple_87;
static PyObject *__pyx_k_tuple_90;
static PyObject *__pyx_k_tuple_119;
static PyObject *__pyx_k_tuple_124;
static PyObject *__pyx_k_tuple_129;
static PyObject *__pyx_k_tuple_134;
static PyObject *__pyx_k_tuple_137;
static PyObject *__pyx_k_tuple_140;
static PyObject *__pyx_k_tuple_143;
static PyObject *__pyx_k_tuple_146;
static PyObject *__pyx_k_tuple_164;
static PyObject *__pyx_k_tuple_166;
static PyObject *__pyx_k_tuple_168;
static PyObject *__pyx_k_tuple_170;
static PyObject *__pyx_k_tuple_172;
static PyObject *__pyx_k_tuple_174;
static PyObject *__pyx_k_tuple_177;
static PyObject *__pyx_k_tuple_178;
static PyObject *__pyx_k_tuple_180;
static PyObject *__pyx_k_tuple_183;
static PyObject *__pyx_k_tuple_186;
static PyObject *__pyx_k_tuple_188;
static PyObject *__pyx_k_tuple_190;
static PyObject *__pyx_k_tuple_192;
static PyObject *__pyx_k_tuple_194;
static PyObject *__pyx_k_tuple_196;
static PyObject *__pyx_k_tuple_198;
static PyObject *__pyx_k_tuple_200;
static PyObject *__pyx_k_tuple_202;
static PyObject *__pyx_k_tuple_204;
static PyObject *__pyx_k_tuple_206;
static PyObject *__pyx_k_tuple_208;
static PyObject *__pyx_k_tuple_210;
static PyObject *__pyx_k_tuple_212;
static PyObject *__pyx_k_tuple_214;
static PyObject *__pyx_k_tuple_216;
static PyObject *__pyx_k_tuple_218;
static PyObject *__pyx_k_tuple_220;
static PyObject *__pyx_k_tuple_222;
static PyObject *__pyx_k_tuple_224;
static PyObject *__pyx_k_tuple_226;
static PyObject *__pyx_k_tuple_228;
static PyObject *__pyx_k_tuple_230;
static PyObject *__pyx_k_tuple_232;
static PyObject *__pyx_k_tuple_234;
static PyObject *__pyx_k_tuple_236;
static PyObject *__pyx_k_tuple_238;
static PyObject *__pyx_k_tuple_240;
static PyObject *__pyx_k_tuple_242;
static PyObject *__pyx_k_tuple_244;
static PyObject *__pyx_k_tuple_246;
static PyObject *__pyx_k_tuple_248;
static PyObject *__pyx_k_tuple_250;
static PyObject *__pyx_k_tuple_252;
static PyObject *__pyx_k_tuple_254;
static PyObject *__pyx_k_tuple_256;
static PyObject *__pyx_k_tuple_258;
static PyObject *__pyx_k_tuple_260;
static PyObject *__pyx_k_tuple_262;
static PyObject *__pyx_k_tuple_264;
static PyObject *__pyx_k_tuple_266;
static PyObject *__pyx_k_tuple_268;
static PyObject *__pyx_k_tuple_270;
static PyObject *__pyx_k_tuple_272;
static PyObject *__pyx_k_codeobj_184;
static PyObject *__pyx_k_codeobj_187;
static PyObject *__pyx_k_codeobj_189;
static PyObject *__pyx_k_codeobj_191;
static PyObject *__pyx_k_codeobj_193;
static PyObject *__pyx_k_codeobj_195;
static PyObject *__pyx_k_codeobj_197;
static PyObject *__pyx_k_codeobj_199;
static PyObject *__pyx_k_codeobj_201;
static PyObject *__pyx_k_codeobj_203;
static PyObject *__pyx_k_codeobj_205;
static PyObject *__pyx_k_codeobj_207;
static PyObject *__pyx_k_codeobj_209;
static PyObject *__pyx_k_codeobj_211;
static PyObject *__pyx_k_codeobj_213;
static PyObject *__pyx_k_codeobj_215;
static PyObject *__pyx_k_codeobj_217;
static PyObject *__pyx_k_codeobj_219;
static PyObject *__pyx_k_codeobj_221;
static PyObject *__pyx_k_codeobj_223;
static PyObject *__pyx_k_codeobj_225;
static PyObject *__pyx_k_codeobj_227;
static PyObject *__pyx_k_codeobj_229;
static PyObject *__pyx_k_codeobj_231;
static PyObject *__pyx_k_codeobj_233;
static PyObject *__pyx_k_codeobj_235;
static PyObject *__pyx_k_codeobj_237;
static PyObject *__pyx_k_codeobj_239;
static PyObject *__pyx_k_codeobj_241;
static PyObject *__pyx_k_codeobj_243;
static PyObject *__pyx_k_codeobj_245;
static PyObject *__pyx_k_codeobj_247;
static PyObject *__pyx_k_codeobj_249;
static PyObject *__pyx_k_codeobj_251;
static PyObject *__pyx_k_codeobj_253;
static PyObject *__pyx_k_codeobj_255;
static PyObject *__pyx_k_codeobj_257;
static PyObject *__pyx_k_codeobj_259;
static PyObject *__pyx_k_codeobj_261;
static PyObject *__pyx_k_codeobj_263;
static PyObject *__pyx_k_codeobj_265;
static PyObject *__pyx_k_codeobj_267;
static PyObject *__pyx_k_codeobj_269;
static PyObject *__pyx_k_codeobj_271;
static PyObject *__pyx_k_codeobj_273;

/* 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 = {__Pyx_NAMESTR("filter_args"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_1filter_args, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__args)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("filter_args", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "filter_args") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

static PyObject *__pyx_pf_5kwant_6linalg_6lapack_filter_args(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_select, PyObject *__pyx_v_args) {
  PyObject *__pyx_v_sel = NULL;
  PyObject *__pyx_v_arg = NULL;
  PyObject *__pyx_r = NULL;
  __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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("filter_args", 0);

  /* "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_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_select);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_select);
  __Pyx_GIVEREF(__pyx_v_select);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __pyx_t_3 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (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_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __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_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __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_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      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_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_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_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_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_L5_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_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF(__pyx_v_sel);
    __pyx_v_sel = __pyx_t_6;
    __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_v_arg);
    __pyx_v_arg = __pyx_t_7;
    __pyx_t_7 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_sel); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_10) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_arg))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)PyList_AsTuple(((PyObject*)__pyx_t_1))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_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_v_sel);
  __Pyx_XDECREF(__pyx_v_arg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("assert_fortran_mat"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_3assert_fortran_mat, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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);
  __Pyx_XDECREF(__pyx_v_mats);
  __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.
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("assert_fortran_mat", 0);

  /* "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_t_1 = ((PyObject *)__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_COMPILING_IN_CPYTHON
    __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_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF(__pyx_v_mat);
    __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_t_4 = (__pyx_v_mat != Py_None);
    if (__pyx_t_4) {
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_6) {
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      if (__pyx_t_8) {

        /* "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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mat, __pyx_n_s__flags); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_5 = PyObject_GetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = (!__pyx_t_6);
        __pyx_t_6 = __pyx_t_7;
      } else {
        __pyx_t_6 = __pyx_t_8;
      }
      __pyx_t_8 = __pyx_t_6;
    } else {
      __pyx_t_8 = __pyx_t_4;
    }
    if (__pyx_t_8) {

      /* "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_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __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_5);
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sgetrf"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_5sgetrf, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_5sgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_4sgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_4;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  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;
  int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sgetrf", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_v_N;
  __pyx_t_5 = __pyx_v_M;
  if ((__pyx_t_4 < __pyx_t_5)) {
    __pyx_t_6 = __pyx_t_4;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  __pyx_t_3 = PyInt_FromLong(__pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":66
 * 
 *     f_lapack.sgetrf_(&M, &N, <float *>A.data, &M,
 *                      <l_int *>ipiv.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info >= 0, "Argument error in sgetrf"
 */
  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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info >= 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_3));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
    __pyx_t_15 = (__pyx_v_M != __pyx_v_N);
    __pyx_t_16 = __pyx_t_15;
  } else {
    __pyx_t_16 = __pyx_t_14;
  }
  __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dgetrf"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_7dgetrf, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_7dgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_6dgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_4;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  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;
  int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dgetrf", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_v_N;
  __pyx_t_5 = __pyx_v_M;
  if ((__pyx_t_4 < __pyx_t_5)) {
    __pyx_t_6 = __pyx_t_4;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  __pyx_t_3 = PyInt_FromLong(__pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":83
 * 
 *     f_lapack.dgetrf_(&M, &N, <double *>A.data, &M,
 *                      <l_int *>ipiv.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info >= 0, "Argument error in dgetrf"
 */
  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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info >= 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_4));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
    __pyx_t_15 = (__pyx_v_M != __pyx_v_N);
    __pyx_t_16 = __pyx_t_15;
  } else {
    __pyx_t_16 = __pyx_t_14;
  }
  __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cgetrf"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_9cgetrf, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_9cgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_8cgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_4;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  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;
  int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cgetrf", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_v_N;
  __pyx_t_5 = __pyx_v_M;
  if ((__pyx_t_4 < __pyx_t_5)) {
    __pyx_t_6 = __pyx_t_4;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  __pyx_t_3 = PyInt_FromLong(__pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":100
 * 
 *     f_lapack.cgetrf_(&M, &N, <float complex *>A.data, &M,
 *                      <l_int *>ipiv.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info >= 0, "Argument error in cgetrf"
 */
  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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info >= 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_5));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
    __pyx_t_15 = (__pyx_v_M != __pyx_v_N);
    __pyx_t_16 = __pyx_t_15;
  } else {
    __pyx_t_16 = __pyx_t_14;
  }
  __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zgetrf"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_11zgetrf, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_5kwant_6linalg_6lapack_11zgetrf(PyObject *__pyx_self, PyObject *__pyx_v_A) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_10zgetrf(__pyx_self, ((PyArrayObject *)__pyx_v_A));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_4;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_5;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  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;
  int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zgetrf", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_v_N;
  __pyx_t_5 = __pyx_v_M;
  if ((__pyx_t_4 < __pyx_t_5)) {
    __pyx_t_6 = __pyx_t_4;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  __pyx_t_3 = PyInt_FromLong(__pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_9 = 0;
  __pyx_v_ipiv = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "kwant/linalg/lapack.pyx":117
 * 
 *     f_lapack.zgetrf_(&M, &N, <double complex *>A.data, &M,
 *                      <l_int *>ipiv.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info >= 0, "Argument error in zgetrf"
 */
  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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info >= 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_6));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_14 = (__pyx_v_info > 0);
  if (!__pyx_t_14) {
    __pyx_t_15 = (__pyx_v_M != __pyx_v_N);
    __pyx_t_16 = __pyx_t_15;
  } else {
    __pyx_t_16 = __pyx_t_14;
  }
  __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ipiv));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ipiv));
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sgetrs"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_13sgetrs, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgetrs", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgetrs", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sgetrs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_12sgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sgetrs", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_4 = __Pyx_TypeCheck(__pyx_v_B, ((PyObject*)__pyx_ptype_5numpy_ndarray)); 
  __pyx_t_5 = (!__pyx_t_4);
  if (!__pyx_t_5) {

    /* "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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!__pyx_t_6) {
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      if (__pyx_t_8) {

        /* "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_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = (!__pyx_t_6);
        __pyx_t_6 = __pyx_t_7;
      } else {
        __pyx_t_6 = __pyx_t_8;
      }
      __pyx_t_8 = __pyx_t_6;
    } else {
      __pyx_t_8 = __pyx_t_4;
    }
    __pyx_t_4 = __pyx_t_8;
  } else {
    __pyx_t_4 = __pyx_t_5;
  }
  if (__pyx_t_4) {

    /* "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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "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:
 */
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_B);
  __pyx_v_b = ((PyArrayObject *)__pyx_v_B);

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

  /* "kwant/linalg/lapack.pyx":142
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = B.shape[1]
 *     else:
 */
  switch (__pyx_v_b->nd) {

    /* "kwant/linalg/lapack.pyx":140
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    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_v_NRHS = 1;
    break;

    /* "kwant/linalg/lapack.pyx":142
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = B.shape[1]
 *     else:
 */
    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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_NRHS = __pyx_t_9;
    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_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "kwant/linalg/lapack.pyx":149
 *     f_lapack.sgetrs_("N", &N, &NRHS, <float *>LU.data, &N,
 *                      <l_int *>IPIV.data, <float *>b.data, &N,
 *                      &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgetrs"
 */
  sgetrs_(__pyx_k__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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_11));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dgetrs"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_15dgetrs, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgetrs", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgetrs", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dgetrs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_14dgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dgetrs", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_4 = __Pyx_TypeCheck(__pyx_v_B, ((PyObject*)__pyx_ptype_5numpy_ndarray)); 
  __pyx_t_5 = (!__pyx_t_4);
  if (!__pyx_t_5) {

    /* "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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!__pyx_t_6) {
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      if (__pyx_t_8) {

        /* "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_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = (!__pyx_t_6);
        __pyx_t_6 = __pyx_t_7;
      } else {
        __pyx_t_6 = __pyx_t_8;
      }
      __pyx_t_8 = __pyx_t_6;
    } else {
      __pyx_t_8 = __pyx_t_4;
    }
    __pyx_t_4 = __pyx_t_8;
  } else {
    __pyx_t_4 = __pyx_t_5;
  }
  if (__pyx_t_4) {

    /* "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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "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:
 */
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_B);
  __pyx_v_b = ((PyArrayObject *)__pyx_v_B);

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

  /* "kwant/linalg/lapack.pyx":172
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
  switch (__pyx_v_b->nd) {

    /* "kwant/linalg/lapack.pyx":170
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    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_v_NRHS = 1;
    break;

    /* "kwant/linalg/lapack.pyx":172
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    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_v_NRHS = (__pyx_v_b->dimensions[1]);
    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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "kwant/linalg/lapack.pyx":179
 *     f_lapack.dgetrs_("N", &N, &NRHS, <double *>LU.data, &N,
 *                      <l_int *>IPIV.data, <double *>b.data, &N,
 *                      &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgetrs"
 */
  dgetrs_(__pyx_k__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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_15));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cgetrs"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_17cgetrs, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgetrs", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgetrs", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cgetrs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_16cgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cgetrs", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_4 = __Pyx_TypeCheck(__pyx_v_B, ((PyObject*)__pyx_ptype_5numpy_ndarray)); 
  __pyx_t_5 = (!__pyx_t_4);
  if (!__pyx_t_5) {

    /* "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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!__pyx_t_6) {
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      if (__pyx_t_8) {

        /* "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_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = (!__pyx_t_6);
        __pyx_t_6 = __pyx_t_7;
      } else {
        __pyx_t_6 = __pyx_t_8;
      }
      __pyx_t_8 = __pyx_t_6;
    } else {
      __pyx_t_8 = __pyx_t_4;
    }
    __pyx_t_4 = __pyx_t_8;
  } else {
    __pyx_t_4 = __pyx_t_5;
  }
  if (__pyx_t_4) {

    /* "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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "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:
 */
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_B);
  __pyx_v_b = ((PyArrayObject *)__pyx_v_B);

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

  /* "kwant/linalg/lapack.pyx":202
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
  switch (__pyx_v_b->nd) {

    /* "kwant/linalg/lapack.pyx":200
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    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_v_NRHS = 1;
    break;

    /* "kwant/linalg/lapack.pyx":202
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    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_v_NRHS = (__pyx_v_b->dimensions[1]);
    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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "kwant/linalg/lapack.pyx":209
 *     f_lapack.cgetrs_("N", &N, &NRHS, <float complex *>LU.data, &N,
 *                      <l_int *>IPIV.data, <float complex *>b.data, &N,
 *                      &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgetrs"
 */
  cgetrs_(__pyx_k__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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_19));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_b));
  __pyx_r = ((PyObject *)__pyx_v_b);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zgetrs"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_19zgetrs, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__IPIV)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgetrs", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgetrs", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "zgetrs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_IPIV), __pyx_ptype_5numpy_ndarray, 1, "IPIV", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_18zgetrs(__pyx_self, __pyx_v_LU, __pyx_v_IPIV, __pyx_v_B);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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
 */

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zgetrs", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_t_4 = __Pyx_TypeCheck(__pyx_v_B, ((PyObject*)__pyx_ptype_5numpy_ndarray)); 
  __pyx_t_5 = (!__pyx_t_4);
  if (!__pyx_t_5) {

    /* "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_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__ndim); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!__pyx_t_6) {
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      if (__pyx_t_8) {

        /* "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_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_B, __pyx_n_s__flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_7 = (!__pyx_t_6);
        __pyx_t_6 = __pyx_t_7;
      } else {
        __pyx_t_6 = __pyx_t_8;
      }
      __pyx_t_8 = __pyx_t_6;
    } else {
      __pyx_t_8 = __pyx_t_4;
    }
    __pyx_t_4 = __pyx_t_8;
  } else {
    __pyx_t_4 = __pyx_t_5;
  }
  if (__pyx_t_4) {

    /* "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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "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:
 */
  if (!(likely(((__pyx_v_B) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_B, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_v_B);
  __pyx_v_b = ((PyArrayObject *)__pyx_v_B);

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

  /* "kwant/linalg/lapack.pyx":232
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
  switch (__pyx_v_b->nd) {

    /* "kwant/linalg/lapack.pyx":230
 *     b = B
 *     N = LU.shape[0]
 *     if b.ndim == 1:             # <<<<<<<<<<<<<<
 *         NRHS = 1
 *     elif b.ndim == 2:
 */
    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_v_NRHS = 1;
    break;

    /* "kwant/linalg/lapack.pyx":232
 *     if b.ndim == 1:
 *         NRHS = 1
 *     elif b.ndim == 2:             # <<<<<<<<<<<<<<
 *         NRHS = b.shape[1]
 *     else:
 */
    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_v_NRHS = (__pyx_v_b->dimensions[1]);
    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_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "kwant/linalg/lapack.pyx":239
 *     f_lapack.zgetrs_("N", &N, &NRHS, <double complex *>LU.data, &N,
 *                      <l_int *>IPIV.data, <double complex *>b.data, &N,
 *                      &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgetrs"
 */
  zgetrs_(__pyx_k__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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_23));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sgecon"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_21sgecon, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgecon", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_norm = ((char *)__pyx_k__1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_20sgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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 = "1"):
 *     cdef l_int N, info
 */

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_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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sgecon", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((4 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":262
 *     f_lapack.sgecon_(norm, &N, <float *>LU.data, &N, &normA,
 *                      &rcond, <float *>work.data,
 *                      <l_int *>iwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgecon"
 */
  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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_24));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dgecon"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_23dgecon, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgecon", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_norm = ((char *)__pyx_k__1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_22dgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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 = "1"):
 *     cdef l_int N, info
 */

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_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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dgecon", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((4 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":283
 *     f_lapack.dgecon_(norm, &N, <double *>LU.data, &N, &normA,
 *                      &rcond, <double *>work.data,
 *                      <l_int *>iwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgecon"
 */
  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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_25));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cgecon"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_25cgecon, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgecon", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_norm = ((char *)__pyx_k__1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_24cgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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 = "1"):
 *     cdef l_int N, info
 */

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_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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cgecon", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":304
 *     f_lapack.cgecon_(norm, &N, <float complex *>LU.data, &N, &normA,
 *                      &rcond, <float complex *>work.data,
 *                      <float *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgecon"
 */
  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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_26));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __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_XDECREF(__pyx_r);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zgecon"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_27zgecon, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__LU)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__normA)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgecon", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[2]) {
      __pyx_v_norm = __Pyx_PyObject_AsString(values[2]); if (unlikely((!__pyx_v_norm) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_norm = ((char *)__pyx_k__1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("zgecon", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_26zgecon(__pyx_self, __pyx_v_LU, __pyx_v_normA, __pyx_v_norm);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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 = "1"):
 *     cdef l_int N, info
 */

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_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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zgecon", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_LU));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_LU));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_LU));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":325
 *     f_lapack.zgecon_(norm, &N, <double complex *>LU.data, &N, &normA,
 *                      &rcond, <double complex *>work.data,
 *                      <double *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgecon"
 */
  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
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_27));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":329
 *     assert info == 0, "Argument error in zgecon"
 * 
 *     return rcond             # <<<<<<<<<<<<<<
 * 
 * # Wrappers for xGGEV
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_rcond); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ggev_postprocess"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_29ggev_postprocess, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};

    /* "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
 */
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dtype)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphar)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ggev_postprocess", 0, 3, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphai)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ggev_postprocess", 0, 3, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__vl_r);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __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);
  __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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ggev_postprocess", 0);

  /* "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_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_alphai, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __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, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_indx = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":340
 *     indx = (alphai > 0.0).nonzero()[0]
 * 
 *     if indx.size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_indx, __pyx_n_s__size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "kwant/linalg/lapack.pyx":341
 * 
 *     if indx.size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 * 
 *         if vl_r != None:
 */
    __pyx_t_1 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_v_alphai); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(__pyx_v_alphar, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_alpha = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "kwant/linalg/lapack.pyx":343
 *         alpha = alphar + 1j * alphai
 * 
 *         if vl_r != None:             # <<<<<<<<<<<<<<
 *             vl = np.array(vl_r, dtype = dtype)
 *             for i in indx:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_vl_r, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "kwant/linalg/lapack.pyx":344
 * 
 *         if vl_r != None:
 *             vl = np.array(vl_r, dtype = dtype)             # <<<<<<<<<<<<<<
 *             for i in indx:
 *                 vl.imag[:, i] = vl_r[:,i+1]
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_vl_r);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_vl_r);
      __Pyx_GIVEREF(__pyx_v_vl_r);
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_v_vl = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":345
 *         if vl_r != 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])
 */
      if (PyList_CheckExact(__pyx_v_indx) || PyTuple_CheckExact(__pyx_v_indx)) {
        __pyx_t_5 = __pyx_v_indx; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
        __pyx_t_7 = NULL;
      } else {
        __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_indx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext;
      }
      for (;;) {
        if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_4 = __pyx_t_7(__pyx_t_5);
          if (unlikely(!__pyx_t_4)) {
            if (PyErr_Occurred()) {
              if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_4);
        }
        __Pyx_XDECREF(__pyx_v_i);
        __pyx_v_i = __pyx_t_4;
        __pyx_t_4 = 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_t_4 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_k_slice_28);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_28);
        __Pyx_GIVEREF(__pyx_k_slice_28);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = PyObject_GetItem(__pyx_v_vl_r, ((PyObject *)__pyx_t_1)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_vl, __pyx_n_s__imag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_k_slice_29);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_k_slice_29);
        __Pyx_GIVEREF(__pyx_k_slice_29);
        __Pyx_INCREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        if (PyObject_SetItem(__pyx_t_1, ((PyObject *)__pyx_t_2), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__conj); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_k_slice_30);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_k_slice_30);
        __Pyx_GIVEREF(__pyx_k_slice_30);
        __Pyx_INCREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        __pyx_t_1 = PyObject_GetItem(__pyx_v_vl, ((PyObject *)__pyx_t_4)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
        __pyx_t_4 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_k_slice_31);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_k_slice_31);
        __Pyx_GIVEREF(__pyx_k_slice_31);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        if (PyObject_SetItem(__pyx_v_vl, ((PyObject *)__pyx_t_2), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L4;
    }
    /*else*/ {

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

    /* "kwant/linalg/lapack.pyx":351
 *             vl = None
 * 
 *         if vr_r != None:             # <<<<<<<<<<<<<<
 *             vr = np.array(vr_r, dtype = dtype)
 *             for i in indx:
 */
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_vr_r, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_3) {

      /* "kwant/linalg/lapack.pyx":352
 * 
 *         if vr_r != None:
 *             vr = np.array(vr_r, dtype = dtype)             # <<<<<<<<<<<<<<
 *             for i in indx:
 *                 vr.imag[:, i] = vr_r[:,i+1]
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_vr_r);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_vr_r);
      __Pyx_GIVEREF(__pyx_v_vr_r);
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_v_vr = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "kwant/linalg/lapack.pyx":353
 *         if vr_r != 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])
 */
      if (PyList_CheckExact(__pyx_v_indx) || PyTuple_CheckExact(__pyx_v_indx)) {
        __pyx_t_4 = __pyx_v_indx; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0;
        __pyx_t_7 = NULL;
      } else {
        __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_indx); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext;
      }
      for (;;) {
        if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_4)) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_4)) {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_2 = __pyx_t_7(__pyx_t_4);
          if (unlikely(!__pyx_t_2)) {
            if (PyErr_Occurred()) {
              if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF(__pyx_v_i);
        __pyx_v_i = __pyx_t_2;
        __pyx_t_2 = 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_t_2 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_k_slice_32);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_k_slice_32);
        __Pyx_GIVEREF(__pyx_k_slice_32);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_GetItem(__pyx_v_vr_r, ((PyObject *)__pyx_t_5)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_vr, __pyx_n_s__imag); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_k_slice_33);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_33);
        __Pyx_GIVEREF(__pyx_k_slice_33);
        __Pyx_INCREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        if (PyObject_SetItem(__pyx_t_5, ((PyObject *)__pyx_t_1), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__conj); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_k_slice_34);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_k_slice_34);
        __Pyx_GIVEREF(__pyx_k_slice_34);
        __Pyx_INCREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        __pyx_t_5 = PyObject_GetItem(__pyx_v_vr, ((PyObject *)__pyx_t_2)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __pyx_t_2 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_k_slice_35);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_35);
        __Pyx_GIVEREF(__pyx_k_slice_35);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        if (PyObject_SetItem(__pyx_v_vr, ((PyObject *)__pyx_t_1), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

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

    /* "kwant/linalg/lapack.pyx":359
 *             vr = None
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 *         vl = vl_r
 *         vr = vr_r
 */
    __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_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_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_XDECREF(__pyx_r);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sggev"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_31sggev, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_36;
    values[3] = __pyx_k_37;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sggev", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __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):
 */

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_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)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sggev", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __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":375
 *     cdef np.ndarray[np.float32_t, ndim=1] work, alphar, alphai, beta
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":378
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":379
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":380
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":382
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":383
 * 
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float *>vl_r.data
 *         jobvl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

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

    /* "kwant/linalg/lapack.pyx":385
 *         vl_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vl_ptr = <float *>vl_r.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r = None
 */
    __pyx_v_jobvl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":387
 *         jobvl = "V"
 *     else:
 *         vl_r = None             # <<<<<<<<<<<<<<
 *         vl_ptr = NULL
 *         jobvl = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vl_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":388
 *     else:
 *         vl_r = None
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":389
 *         vl_r = None
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_jobvl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":391
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":392
 * 
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float *>vr_r.data
 *         jobvr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":394
 *         vr_r = np.empty((N,N), dtype = np.float32, order='F')
 *         vr_ptr = <float *>vr_r.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r = None
 */
    __pyx_v_jobvr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":396
 *         jobvr = "V"
 *     else:
 *         vr_r = None             # <<<<<<<<<<<<<<
 *         vr_ptr = NULL
 *         jobvr = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vr_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":397
 *     else:
 *         vr_r = None
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":398
 *         vr_r = None
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvr = __pyx_k__N;
  }
  __pyx_L4:;

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

  /* "kwant/linalg/lapack.pyx":408
 *                     <float *>beta.data,
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     &qwork, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sggev"
 */
  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":410
 *                     &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in sggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":413
 * 
 *     lwork = <l_int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":421
 *                     <float *>beta.data,
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     <float *>work.data, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":423
 *                     <float *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sggev")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":424
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sggev"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":426
 *         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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":428
 *     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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__ggev_postprocess); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_alphar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alphar));
  __Pyx_INCREF(((PyObject *)__pyx_v_alphai));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_alphai));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alphai));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vl_r));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_vr_r));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_2 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 2; __pyx_t_4 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_5), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L7_unpacking_done:;
  }
  __pyx_v_alpha = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_vl = __pyx_t_2;
  __pyx_t_2 = 0;
  __pyx_v_vr = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":430
 *     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_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  __pyx_t_4 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_t_3 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dggev"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_33dggev, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_41;
    values[3] = __pyx_k_42;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dggev", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dggev", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __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":442
 *     cdef np.ndarray[np.float64_t, ndim=1] work, alphar, alphai, beta
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":445
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":446
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":447
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":449
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":450
 * 
 *     if left:
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double *>vl_r.data
 *         jobvl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

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

    /* "kwant/linalg/lapack.pyx":452
 *         vl_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vl_ptr = <double *>vl_r.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_r = None
 */
    __pyx_v_jobvl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":454
 *         jobvl = "V"
 *     else:
 *         vl_r = None             # <<<<<<<<<<<<<<
 *         vl_ptr = NULL
 *         jobvl = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vl_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":455
 *     else:
 *         vl_r = None
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":456
 *         vl_r = None
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_jobvl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":458
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":459
 * 
 *     if right:
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double *>vr_r.data
 *         jobvr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":461
 *         vr_r = np.empty((N,N), dtype = np.float64, order='F')
 *         vr_ptr = <double *>vr_r.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_r = None
 */
    __pyx_v_jobvr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":463
 *         jobvr = "V"
 *     else:
 *         vr_r = None             # <<<<<<<<<<<<<<
 *         vr_ptr = NULL
 *         jobvr = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vr_r = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":464
 *     else:
 *         vr_r = None
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":465
 *         vr_r = None
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvr = __pyx_k__N;
  }
  __pyx_L4:;

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

  /* "kwant/linalg/lapack.pyx":475
 *                     <double *>beta.data,
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     &qwork, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dggev"
 */
  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":477
 *                     &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in dggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_43));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":480
 * 
 *     lwork = <l_int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":488
 *                     <double *>beta.data,
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     <double *>work.data, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":490
 *                     <double *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dggev")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":491
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dggev"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":493
 *         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)
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_43));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":495
 *     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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__ggev_postprocess); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_alphar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alphar));
  __Pyx_INCREF(((PyObject *)__pyx_v_alphai));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_alphai));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alphai));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_vl_r));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_vr_r));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_2 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 2; __pyx_t_4 = __pyx_t_13(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_5), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L7_unpacking_done:;
  }
  __pyx_v_alpha = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_vl = __pyx_t_2;
  __pyx_t_2 = 0;
  __pyx_v_vr = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":497
 *     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_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  __pyx_t_4 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(__pyx_v_vl);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_vl);
  __Pyx_GIVEREF(__pyx_v_vl);
  __Pyx_INCREF(__pyx_v_vr);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_vr);
  __Pyx_GIVEREF(__pyx_v_vr);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_t_3 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cggev"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_35cggev, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_46;
    values[3] = __pyx_k_47;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cggev", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  PyArrayObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cggev", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __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":510
 *     cdef np.ndarray[np.float32_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":513
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":514
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":516
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":517
 * 
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *         jobvl = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":519
 *         vl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_jobvl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":521
 *         jobvl = "V"
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":522
 *     else:
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_jobvl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":524
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":525
 * 
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *         jobvr = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vr = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

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

    /* "kwant/linalg/lapack.pyx":527
 *         vr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_jobvr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":529
 *         jobvr = "V"
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":530
 *     else:
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     rwork = np.empty(8 * N, dtype = np.float32)
 */
    __pyx_v_jobvr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":532
 *         jobvr = "N"
 * 
 *     rwork = np.empty(8 * N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong((8 * __pyx_v_N)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_13 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

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

  /* "kwant/linalg/lapack.pyx":536
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_48), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __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_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_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_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":543
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     &qwork, &lwork,
 *                     <float *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cggev"
 */
  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":545
 *                     <float *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in cggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_49));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":549
 *     lwork = <l_int>qwork.real
 * 
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__complex64); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __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_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_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_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_work));
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":557
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     <float complex *>work.data, &lwork,
 *                     <float *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":559
 *                     <float *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cggev")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":560
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cggev"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":562
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_49));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":564
 *     assert info == 0, "Argument error in cggev"
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_vl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr));
  PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_vr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zggev"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_37zggev, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_52;
    values[3] = __pyx_k_53;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zggev", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  PyArrayObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zggev", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __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":577
 *     cdef np.ndarray[np.float64_t, ndim=1] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":580
 * 
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex128)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":581
 *     N = A.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":583
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":584
 * 
 *     if left:
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *         jobvl = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":586
 *         vl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data
 *         jobvl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_jobvl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":588
 *         jobvl = "V"
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvl = "N"
 * 
 */
    __pyx_v_vl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":589
 *     else:
 *         vl_ptr = NULL
 *         jobvl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_jobvl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":591
 *         jobvl = "N"
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":592
 * 
 *     if right:
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *         jobvr = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vr = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

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

    /* "kwant/linalg/lapack.pyx":594
 *         vr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data
 *         jobvr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_jobvr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":596
 *         jobvr = "V"
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvr = "N"
 * 
 */
    __pyx_v_vr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":597
 *     else:
 *         vr_ptr = NULL
 *         jobvr = "N"             # <<<<<<<<<<<<<<
 * 
 *     rwork = np.empty(8 * N, dtype = np.float64)
 */
    __pyx_v_jobvr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":599
 *         jobvr = "N"
 * 
 *     rwork = np.empty(8 * N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong((8 * __pyx_v_N)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_13 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

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

  /* "kwant/linalg/lapack.pyx":603
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_54), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __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_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_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_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":610
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     &qwork, &lwork,
 *                     <double *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zggev"
 */
  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":612
 *                     <double *>rwork.data, &info)
 * 
 *     assert info == 0, "Argument error in zggev"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <l_int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_55));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":615
 * 
 *     lwork = <l_int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__complex128); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __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_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_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_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_work));
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":623
 *                     vl_ptr, &N, vr_ptr, &N,
 *                     <double complex *>work.data, &lwork,
 *                     <double *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":625
 *                     <double *>rwork.data, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zggev")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":626
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zggev"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":628
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_55));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":630
 *     assert info == 0, "Argument error in zggev"
 * 
 *     return filter_args((True, True, left, right), (alpha, beta, vl, vr))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_left);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_left);
  __Pyx_GIVEREF(__pyx_v_left);
  __Pyx_INCREF(__pyx_v_right);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_right);
  __Pyx_GIVEREF(__pyx_v_right);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __Pyx_INCREF(((PyObject *)__pyx_v_vl));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_vl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vr));
  PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_vr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sgees"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_39sgees, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[1] = __pyx_k_58;
    values[2] = __pyx_k_59;
    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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_38sgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":634
 * 
 * # 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
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sgees", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __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":642
 *     cdef np.ndarray[np.float32_t] wr, wi, work
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":645
 * 
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float32)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":646
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":648
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":649
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <float *>vs.data
 *         jobvs = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":651
 *         vs = np.empty((N,N), dtype = np.float32, order='F')
 *         vs_ptr = <float *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __pyx_v_jobvs = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":653
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":654
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvs = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":657
 * 
 *     # 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_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":660
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgees"
 */
  sgees_(__pyx_v_jobvs, __pyx_k__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":662
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in sgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_60));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":665
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":670
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  sgees_(__pyx_v_jobvs, __pyx_k__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":672
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in sgees")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":673
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in sgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgees"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_62), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":675
 *         raise LinAlgError("QR iteration failed to converge in sgees")
 * 
 *     assert info == 0, "Argument error in sgees"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_60));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":677
 *     assert info == 0, "Argument error in sgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":678
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __pyx_t_4 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_4, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_w = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

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

  /* "kwant/linalg/lapack.pyx":682
 *         w = wr
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dgees"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_41dgees, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[1] = __pyx_k_63;
    values[2] = __pyx_k_64;
    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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_40dgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dgees", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __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":693
 *     cdef np.ndarray[np.float64_t] wr, wi, work
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":696
 * 
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":697
 *     N = A.shape[0]
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":699
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":700
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <double *>vs.data
 *         jobvs = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":702
 *         vs = np.empty((N,N), dtype = np.float64, order='F')
 *         vs_ptr = <double *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __pyx_v_jobvs = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":704
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":705
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvs = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":708
 * 
 *     # 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_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":711
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgees"
 */
  dgees_(__pyx_v_jobvs, __pyx_k__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":713
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in dgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_65));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":716
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":721
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  dgees_(__pyx_v_jobvs, __pyx_k__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":723
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in dgees")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":724
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in dgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgees"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":726
 *         raise LinAlgError("QR iteration failed to converge in dgees")
 * 
 *     assert info == 0, "Argument error in dgees"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_65));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":728
 *     assert info == 0, "Argument error in dgees"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":729
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __pyx_t_4 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_4, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_w = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

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

  /* "kwant/linalg/lapack.pyx":733
 *         w = wr
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cgees"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_43cgees, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[1] = __pyx_k_68;
    values[2] = __pyx_k_69;
    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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_42cgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cgees", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __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":745
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":748
 * 
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":749
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":751
 *     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_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":752
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <float complex *>vs.data
 *         jobvs = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":754
 *         vs = np.empty((N,N), dtype = np.complex64, order='F')
 *         vs_ptr = <float complex *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __pyx_v_jobvs = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":756
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":757
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvs = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":760
 * 
 *     # 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_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":763
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgees"
 */
  cgees_(__pyx_v_jobvs, __pyx_k__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":765
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in cgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_70));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":768
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":774
 *                     &sdim, <float complex *>w.data, vs_ptr, &N,
 *                     <float complex *>work.data, &lwork,
 *                     <float *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  cgees_(__pyx_v_jobvs, __pyx_k__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":776
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in cgees")
 * 
 */
  __pyx_t_12 = (__pyx_v_info > 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":777
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in cgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgees"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_72), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":779
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_70));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":781
 *     assert info == 0, "Argument error in cgees"
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zgees"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_45zgees, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[1] = __pyx_k_73;
    values[2] = __pyx_k_74;
    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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5kwant_6linalg_6lapack_44zgees(__pyx_self, __pyx_v_A, __pyx_v_calc_q, __pyx_v_calc_ev);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zgees", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __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":793
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(A)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":796
 * 
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":797
 *     N = A.shape[0]
 *     w = np.empty(N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if calc_q:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":799
 *     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_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":800
 * 
 *     if calc_q:
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vs_ptr = <double complex *>vs.data
 *         jobvs = "V"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vs = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

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

    /* "kwant/linalg/lapack.pyx":802
 *         vs = np.empty((N,N), dtype = np.complex128, order='F')
 *         vs_ptr = <double complex *>vs.data
 *         jobvs = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vs_ptr = NULL
 */
    __pyx_v_jobvs = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":804
 *         jobvs = "V"
 *     else:
 *         vs_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvs = "N"
 * 
 */
    __pyx_v_vs_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":805
 *     else:
 *         vs_ptr = NULL
 *         jobvs = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvs = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":808
 * 
 *     # 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_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":811
 *     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)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  zgees_(__pyx_v_jobvs, __pyx_k__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":813
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":816
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":822
 *                     &sdim, <double complex *>w.data, vs_ptr, &N,
 *                     <double complex *>work.data, &lwork,
 *                     <double *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  zgees_(__pyx_v_jobvs, __pyx_k__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":824
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QR iteration failed to converge in zgees")
 * 
 */
  __pyx_t_12 = (__pyx_v_info > 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":825
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in zgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_77), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":827
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":829
 *     assert info == 0, "Argument error in zgees"
 * 
 *     return filter_args((True, calc_q, calc_ev), (A, vs, w))             # <<<<<<<<<<<<<<
 * 
 * # Wrapper for xTRSEN
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_vs));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_vs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vs));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("strsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_47strsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":834
 * 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);
    values[3] = __pyx_k_78;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("strsen", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":832
 * 
 * # 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,
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("strsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __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":842
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":845
 * 
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float32)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":846
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float32)
 *     wi = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

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

    /* "kwant/linalg/lapack.pyx":849
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <float *>Q.data
 *     else:
 */
    __pyx_v_compq = __pyx_k__V;

    /* "kwant/linalg/lapack.pyx":850
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <float *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __pyx_v_q_ptr = ((float *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":852
 *         q_ptr = <float *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_compq = __pyx_k__N;

    /* "kwant/linalg/lapack.pyx":853
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

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

  /* "kwant/linalg/lapack.pyx":860
 *                      &N, <float *>T.data, &N, q_ptr, &N,
 *                      <float *>wr.data, <float *>wi.data, &M, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strsen"
 */
  strsen_(__pyx_k__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":862
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in strsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_79));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":865
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

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

  /* "kwant/linalg/lapack.pyx":867
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((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_12, &__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_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_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":874
 *                      <float *>wr.data, <float *>wi.data, &M, NULL, NULL,
 *                      <float *>work.data, &lwork,
 *                      <int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  strsen_(__pyx_k__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":876
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":877
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strsen"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_81), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":879
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in strsen"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_79));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":881
 *     assert info == 0, "Argument error in strsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":882
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __pyx_t_3 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_w = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

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

  /* "kwant/linalg/lapack.pyx":886
 *         w = wr
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dtrsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_49dtrsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":891
 * 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);
    values[3] = __pyx_k_82;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtrsen", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dtrsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __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":899
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":902
 * 
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     wi = np.empty(N, dtype = np.float64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wr = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":903
 *     N = T.shape[0]
 *     wr = np.empty(N, dtype = np.float64)
 *     wi = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_wi = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

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

    /* "kwant/linalg/lapack.pyx":906
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <double *>Q.data
 *     else:
 */
    __pyx_v_compq = __pyx_k__V;

    /* "kwant/linalg/lapack.pyx":907
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <double *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __pyx_v_q_ptr = ((double *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":909
 *         q_ptr = <double *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_compq = __pyx_k__N;

    /* "kwant/linalg/lapack.pyx":910
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

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

  /* "kwant/linalg/lapack.pyx":917
 *                      &N, <double *>T.data, &N, q_ptr, &N,
 *                      <double *>wr.data, <double *>wi.data, &M, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrsen"
 */
  dtrsen_(__pyx_k__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":919
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in dtrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_83));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":922
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

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

  /* "kwant/linalg/lapack.pyx":924
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = f_lapack.l_int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((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_12, &__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_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_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":931
 *                      <double *>wr.data, <double *>wi.data, &M, NULL, NULL,
 *                      <double *>work.data, &lwork,
 *                      <int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  dtrsen_(__pyx_k__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":933
 *                      <int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":934
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrsen"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_84), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":936
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in dtrsen"             # <<<<<<<<<<<<<<
 * 
 *     if wi.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_83));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":938
 *     assert info == 0, "Argument error in dtrsen"
 * 
 *     if wi.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         w = wr + 1j * wi
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_wi), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":939
 * 
 *     if wi.nonzero()[0].size:
 *         w = wr + 1j * wi             # <<<<<<<<<<<<<<
 *     else:
 *         w = wr
 */
    __pyx_t_3 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, ((PyObject *)__pyx_v_wi)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_wr), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_w = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

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

  /* "kwant/linalg/lapack.pyx":943
 *         w = wr
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(__pyx_v_w);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_w);
  __Pyx_GIVEREF(__pyx_v_w);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ctrsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_51ctrsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":948
 * 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);
    values[3] = __pyx_k_85;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctrsen", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ctrsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __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":955
 *     cdef np.ndarray[np.complex64_t] w, work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":958
 * 
 *     N = T.shape[0]
 *     w = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

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

    /* "kwant/linalg/lapack.pyx":961
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <float complex *>Q.data
 *     else:
 */
    __pyx_v_compq = __pyx_k__V;

    /* "kwant/linalg/lapack.pyx":962
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <float complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __pyx_v_q_ptr = ((__pyx_t_float_complex *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":964
 *         q_ptr = <float complex *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_compq = __pyx_k__N;

    /* "kwant/linalg/lapack.pyx":965
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

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

  /* "kwant/linalg/lapack.pyx":972
 *                      &N, <float complex *>T.data, &N, q_ptr, &N,
 *                      <float complex *>w.data, &M, NULL, NULL,
 *                      &qwork, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrsen"
 */
  ctrsen_(__pyx_k__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":974
 *                      &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in ctrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_86));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":977
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":983
 *                      &N, <float complex *>T.data, &N, q_ptr, &N,
 *                      <float complex *>w.data, &M, NULL, NULL,
 *                      <float complex *>work.data, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  ctrsen_(__pyx_k__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":985
 *                      <float complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":986
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrsen"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_87), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":988
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_86));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":990
 *     assert info == 0, "Argument error in ctrsen"
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ztrsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_53ztrsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":995
 * 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);
    values[3] = __pyx_k_88;
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztrsen", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ztrsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __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":1002
 *     cdef np.ndarray[np.complex128_t] w, work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1005
 * 
 *     N = T.shape[0]
 *     w = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_w = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

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

    /* "kwant/linalg/lapack.pyx":1008
 * 
 *     if Q is not None:
 *         compq = "V"             # <<<<<<<<<<<<<<
 *         q_ptr = <double complex *>Q.data
 *     else:
 */
    __pyx_v_compq = __pyx_k__V;

    /* "kwant/linalg/lapack.pyx":1009
 *     if Q is not None:
 *         compq = "V"
 *         q_ptr = <double complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         compq = "N"
 */
    __pyx_v_q_ptr = ((__pyx_t_double_complex *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1011
 *         q_ptr = <double complex *>Q.data
 *     else:
 *         compq = "N"             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_compq = __pyx_k__N;

    /* "kwant/linalg/lapack.pyx":1012
 *     else:
 *         compq = "N"
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

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

  /* "kwant/linalg/lapack.pyx":1019
 *                      &N, <double complex *>T.data, &N, q_ptr, &N,
 *                      <double complex *>w.data, &M, NULL, NULL,
 *                      &qwork, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrsen"
 */
  ztrsen_(__pyx_k__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":1021
 *                      &qwork, &lwork, &info)
 * 
 *     assert info == 0, "Argument error in ztrsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_89));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1024
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1030
 *                      &N, <double complex *>T.data, &N, q_ptr, &N,
 *                      <double complex *>w.data, &M, NULL, NULL,
 *                      <double complex *>work.data, &lwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  ztrsen_(__pyx_k__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":1032
 *                      <double complex *>work.data, &lwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1033
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrsen"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_90), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1035
 *         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))
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_89));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1037
 *     assert info == 0, "Argument error in ztrsen"
 * 
 *     return filter_args((True, Q is not None, calc_ev), (T, Q, w))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_w));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_w));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_w));
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("txevc_postprocess"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_55txevc_postprocess, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dtype)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__vreal)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("txevc_postprocess", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "txevc_postprocess") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyArrayObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("txevc_postprocess", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __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":1044
 *     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_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_T, __pyx_n_s__shape); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_N = __pyx_t_3;

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

    /* "kwant/linalg/lapack.pyx":1046
 *     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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
    {
      __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_8, &__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_9, &__pyx_t_10, &__pyx_t_11);
        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_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
      }
      __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_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_select));
    __pyx_v_select = ((PyArrayObject *)__pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1047
 *     if select is None:
 *         select = np.ones(N, dtype = f_lapack.l_logical_dtype)
 *     selindx = select.nonzero()[0]             # <<<<<<<<<<<<<<
 *     M = selindx.size
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_selindx = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "kwant/linalg/lapack.pyx":1048
 *         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_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_selindx, __pyx_n_s__size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_M = __pyx_t_3;

  /* "kwant/linalg/lapack.pyx":1050
 *     M = selindx.size
 * 
 *     v = np.empty((N, M), dtype = dtype, order='F')             # <<<<<<<<<<<<<<
 * 
 *     indx = 0
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_v_v = __pyx_t_7;
  __pyx_t_7 = 0;

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

  /* "kwant/linalg/lapack.pyx":1053
 * 
 *     indx = 0
 *     for m in xrange(M):             # <<<<<<<<<<<<<<
 *         k = selindx[m]
 * 
 */
  __pyx_t_3 = __pyx_v_M;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_3; __pyx_t_12+=1) {
    __pyx_v_m = __pyx_t_12;

    /* "kwant/linalg/lapack.pyx":1054
 *     indx = 0
 *     for m in xrange(M):
 *         k = selindx[m]             # <<<<<<<<<<<<<<
 * 
 *         if k < N-1 and T[k+1,k]:
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_selindx, __pyx_v_m, sizeof(int), PyInt_FromLong, 0, 1, 1); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_XDECREF(__pyx_v_k);
    __pyx_v_k = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "kwant/linalg/lapack.pyx":1056
 *         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_t_7 = PyInt_FromLong((__pyx_v_N - 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_k, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {
      __pyx_t_1 = PyNumber_Add(__pyx_v_k, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_k);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_k);
      __Pyx_GIVEREF(__pyx_v_k);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(__pyx_v_T, ((PyObject *)__pyx_t_7)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_14 = __pyx_t_13;
    } else {
      __pyx_t_14 = __pyx_t_4;
    }
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1059
 *             # 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_t_1 = PyInt_FromLong(__pyx_v_indx); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_k_slice_91);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_k_slice_91);
      __Pyx_GIVEREF(__pyx_k_slice_91);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(__pyx_v_vreal, ((PyObject *)__pyx_t_7)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __pyx_t_7 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_5 = PyInt_FromLong((__pyx_v_indx + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_k_slice_92);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_k_slice_92);
      __Pyx_GIVEREF(__pyx_k_slice_92);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_GetItem(__pyx_v_vreal, ((PyObject *)__pyx_t_2)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __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 = PyInt_FromLong(__pyx_v_m); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_k_slice_93);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_93);
      __Pyx_GIVEREF(__pyx_k_slice_93);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      if (PyObject_SetItem(__pyx_v_v, ((PyObject *)__pyx_t_1), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "kwant/linalg/lapack.pyx":1063
 *             # 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_t_5 = PyNumber_Add(__pyx_v_k, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_5); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_4 = (!__pyx_t_14);
      if (__pyx_t_4) {

        /* "kwant/linalg/lapack.pyx":1064
 *             # 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_v_indx = (__pyx_v_indx + 2);
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }

    /* "kwant/linalg/lapack.pyx":1065
 *             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_t_1 = PyObject_RichCompare(__pyx_v_k, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {
      __pyx_t_1 = PyNumber_Subtract(__pyx_v_k, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_k);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_k);
      __Pyx_GIVEREF(__pyx_v_k);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(__pyx_v_T, ((PyObject *)__pyx_t_5)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_13 = __pyx_t_14;
    } else {
      __pyx_t_13 = __pyx_t_4;
    }
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1068
 *             # 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_t_1 = PyInt_FromLong(__pyx_v_indx); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_k_slice_94);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_k_slice_94);
      __Pyx_GIVEREF(__pyx_k_slice_94);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetItem(__pyx_v_vreal, ((PyObject *)__pyx_t_5)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyInt_FromLong((__pyx_v_indx + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_k_slice_95);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_k_slice_95);
      __Pyx_GIVEREF(__pyx_k_slice_95);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(__pyx_v_vreal, ((PyObject *)__pyx_t_7)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __pyx_t_7 = PyNumber_Multiply(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyInt_FromLong(__pyx_v_m); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_k_slice_96);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_96);
      __Pyx_GIVEREF(__pyx_k_slice_96);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      if (PyObject_SetItem(__pyx_v_v, ((PyObject *)__pyx_t_1), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":1070
 *             v[:, m] = vreal[:, indx] - 1j * vreal[:, indx + 1]
 * 
 *             indx += 2             # <<<<<<<<<<<<<<
 *         else:
 *             # real eigenvalue
 */
      __pyx_v_indx = (__pyx_v_indx + 2);
      goto __pyx_L6;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1073
 *         else:
 *             # real eigenvalue
 *             v[:, m] = vreal[:, indx]             # <<<<<<<<<<<<<<
 * 
 *             indx += 1
 */
      __pyx_t_2 = PyInt_FromLong(__pyx_v_indx); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_k_slice_97);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_k_slice_97);
      __Pyx_GIVEREF(__pyx_k_slice_97);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(__pyx_v_vreal, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyInt_FromLong(__pyx_v_m); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_k_slice_98);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_k_slice_98);
      __Pyx_GIVEREF(__pyx_k_slice_98);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      if (PyObject_SetItem(__pyx_v_v, ((PyObject *)__pyx_t_7), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

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

  /* "kwant/linalg/lapack.pyx":1076
 * 
 *             indx += 1
 *     return v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_v);
  __pyx_r = __pyx_v_v;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("strevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_57strevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1081
 * # 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":1082
 * 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);
    values[3] = __pyx_k_99;
    values[4] = __pyx_k_100;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1080
 * 
 * # 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,
 */

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_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;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyArrayObject *__pyx_t_17 = NULL;
  PyArrayObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("strevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __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":1092
 *     cdef np.ndarray[np.float32_t] work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1095
 * 
 *     N = T.shape[0]
 *     work = np.empty(4*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((4 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1097
 *     work = np.empty(4*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

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

  /* "kwant/linalg/lapack.pyx":1099
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1100
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1101
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1102
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1104
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1106
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1107
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":1108
 *     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_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":1112
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    __Pyx_INCREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __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, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_cmplxindx = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1113
 *         # 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
 */
    if (PyList_CheckExact(__pyx_v_cmplxindx) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_3 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_3); __pyx_t_15 = 0;
      __pyx_t_16 = NULL;
    } else {
      __pyx_t_15 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_1 = __pyx_t_16(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF(__pyx_v_i);
      __pyx_v_i = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1114
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_5); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_13) {

        /* "kwant/linalg/lapack.pyx":1115
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # Select is overwritten in strevc.
 */
        __pyx_v_MM = (__pyx_v_MM + 1);
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1118
 * 
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_17 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_17 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "kwant/linalg/lapack.pyx":1120
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1122
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1123
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1124
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1125
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_howmny = __pyx_k__B;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1127
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L8:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1129
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1130
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {
      __pyx_t_11 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_12 = __pyx_t_11;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1131
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L10;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1133
 *             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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__float32); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L10:;

    /* "kwant/linalg/lapack.pyx":1134
 *         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_v_vl_r_ptr = ((float *)__pyx_v_vl_r->data);
    goto __pyx_L9;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1136
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L9:;

  /* "kwant/linalg/lapack.pyx":1138
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1139
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_12) {
      __pyx_t_13 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_11 = __pyx_t_13;
    } else {
      __pyx_t_11 = __pyx_t_12;
    }
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1140
 *     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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
      goto __pyx_L12;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1142
 *             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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":1143
 *         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_v_vr_r_ptr = ((float *)__pyx_v_vr_r->data);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1145
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.strevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":1150
 *                      &N, <float *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 *                      <float *>work.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strevc"
 */
  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":1152
 *                      <float *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in strevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in strevc"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_101));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1153
 * 
 *     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:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_102));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1155
 *     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_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_11) {
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1156
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1157
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__dot); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "kwant/linalg/lapack.pyx":1158
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1159
 *             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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__dot); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "kwant/linalg/lapack.pyx":1163
 *     # 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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1164
 *     # eigenvectors.
 *     if np.diagonal(T, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1165
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_v_vl = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "kwant/linalg/lapack.pyx":1166
 *         if left:
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1167
 *             vl = txevc_postprocess(np.complex64, T, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_v_vr = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L18;
    }
    __pyx_L18:;
    goto __pyx_L16;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1169
 *             vr = txevc_postprocess(np.complex64, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1170
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":1171
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1172
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);
      goto __pyx_L20;
    }
    __pyx_L20:;
  }
  __pyx_L16:;

  /* "kwant/linalg/lapack.pyx":1174
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_t_11;
  } else {
    __pyx_t_12 = __pyx_t_13;
  }
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1175
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    __pyx_r = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":1176
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1177
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1179
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }
  __pyx_L21:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dtrevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_59dtrevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1183
 * 
 * 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":1184
 * 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);
    values[3] = __pyx_k_103;
    values[4] = __pyx_k_104;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1182
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyArrayObject *__pyx_t_17 = NULL;
  PyArrayObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dtrevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __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":1194
 *     cdef np.ndarray[np.float64_t] work
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1197
 * 
 *     N = T.shape[0]
 *     work = np.empty(4*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((4 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1199
 *     work = np.empty(4*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

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

  /* "kwant/linalg/lapack.pyx":1201
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1202
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1203
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1204
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1206
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1208
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1209
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":1210
 *     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_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":1214
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_T));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_T));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
    __Pyx_INCREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __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, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_cmplxindx = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1215
 *         # 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
 */
    if (PyList_CheckExact(__pyx_v_cmplxindx) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_3 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_3); __pyx_t_15 = 0;
      __pyx_t_16 = NULL;
    } else {
      __pyx_t_15 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_1 = __pyx_t_16(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF(__pyx_v_i);
      __pyx_v_i = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":1216
 *         cmplxindx = np.diagonal(T, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_5); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_13) {

        /* "kwant/linalg/lapack.pyx":1217
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # Select is overwritten in dtrevc.
 */
        __pyx_v_MM = (__pyx_v_MM + 1);
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1220
 * 
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_17 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_17 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "kwant/linalg/lapack.pyx":1222
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1224
 *         select_ptr = <l_logical *>select_cpy.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1225
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1226
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1227
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_howmny = __pyx_k__B;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1229
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L8:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1231
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl_r = np.asfortranarray(Q.copy())
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1232
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {
      __pyx_t_11 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_12 = __pyx_t_11;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1233
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L10;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1235
 *             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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__float64); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L10:;

    /* "kwant/linalg/lapack.pyx":1236
 *         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_v_vl_r_ptr = ((double *)__pyx_v_vl_r->data);
    goto __pyx_L9;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1238
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L9:;

  /* "kwant/linalg/lapack.pyx":1240
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr_r = np.asfortranarray(Q.copy())
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1241
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_12) {
      __pyx_t_13 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_11 = __pyx_t_13;
    } else {
      __pyx_t_11 = __pyx_t_12;
    }
    if (__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":1242
 *     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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
      goto __pyx_L12;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1244
 *             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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_18 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":1245
 *         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_v_vr_r_ptr = ((double *)__pyx_v_vr_r->data);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1247
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dtrevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":1252
 *                      &N, <double *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 *                      <double *>work.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrevc"
 */
  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":1254
 *                      <double *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in dtrevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtrevc"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_105));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1255
 * 
 *     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:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_106));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1257
 *     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_t_11 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_11) {
    __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1258
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1259
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__dot); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "kwant/linalg/lapack.pyx":1260
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Q, vr_r))
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1261
 *             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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__dot); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_18 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "kwant/linalg/lapack.pyx":1264
 * 
 *     # 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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1265
 *     # 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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1266
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_v_vl = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "kwant/linalg/lapack.pyx":1267
 *         if left:
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1268
 *             vl = txevc_postprocess(np.complex128, T, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_T));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_v_vr = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L18;
    }
    __pyx_L18:;
    goto __pyx_L16;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1270
 *             vr = txevc_postprocess(np.complex128, T, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1271
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":1272
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1273
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);
      goto __pyx_L20;
    }
    __pyx_L20:;
  }
  __pyx_L16:;

  /* "kwant/linalg/lapack.pyx":1275
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_t_11;
  } else {
    __pyx_t_12 = __pyx_t_13;
  }
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1276
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    __pyx_r = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":1277
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1278
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1280
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }
  __pyx_L21:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ctrevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_61ctrevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1284
 * 
 * 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":1285
 * 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);
    values[3] = __pyx_k_107;
    values[4] = __pyx_k_108;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1285; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1283
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_13;
  int __pyx_t_14;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ctrevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __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":1295
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1297
 *     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_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1298
 * 
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1299
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)
 *     rwork = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1301
 *     rwork = np.empty(N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

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

  /* "kwant/linalg/lapack.pyx":1303
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1304
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1305
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1306
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1308
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1310
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_14 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1311
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":1312
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_MM = __pyx_t_15;

    /* "kwant/linalg/lapack.pyx":1313
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1315
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1316
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1317
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __pyx_t_14 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1318
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_howmny = __pyx_k__B;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1320
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L5:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1322
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1323
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_14 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_14) {
      __pyx_t_12 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_13 = __pyx_t_12;
    } else {
      __pyx_t_13 = __pyx_t_14;
    }
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1324
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1326
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *     else:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_1 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L7:;

    /* "kwant/linalg/lapack.pyx":1327
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_vl_ptr = ((__pyx_t_float_complex *)__pyx_v_vl->data);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1329
 *         vl_ptr = <float complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1331
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1332
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {
      __pyx_t_14 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_12 = __pyx_t_14;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1333
 *     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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L9;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1335
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *     else:
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":1336
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_vr_ptr = ((__pyx_t_float_complex *)__pyx_v_vr->data);
    goto __pyx_L8;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1338
 *         vr_ptr = <float complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ctrevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":1343
 *                      &N, <float complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 *                      <float complex *>work.data, <float *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrevc"
 */
  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":1345
 *                      <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"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_109));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1346
 * 
 *     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:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_110));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1348
 *     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_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_12) {
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1349
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1350
 *     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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__dot); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl));
      PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vl));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
      __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl));
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "kwant/linalg/lapack.pyx":1351
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1352
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__dot); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr));
      PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_vr));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
      __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr));
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "kwant/linalg/lapack.pyx":1354
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_14;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1355
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L13;
  }

  /* "kwant/linalg/lapack.pyx":1356
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1357
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1359
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }
  __pyx_L13:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ztrevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_63ztrevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1363
 * 
 * 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":1364
 * 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);
    values[3] = __pyx_k_111;
    values[4] = __pyx_k_112;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1364; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1362
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_13;
  int __pyx_t_14;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_15;
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ztrevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __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":1374
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(T, Q)             # <<<<<<<<<<<<<<
 * 
 *     N = T.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1376
 *     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_v_N = (__pyx_v_T->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1377
 * 
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1378
 *     N = T.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)
 *     rwork = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1380
 *     rwork = np.empty(N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

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

  /* "kwant/linalg/lapack.pyx":1382
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1383
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":1384
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1385
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1387
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1389
 *         return
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_14 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1390
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":1391
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_MM = __pyx_t_15;

    /* "kwant/linalg/lapack.pyx":1392
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1394
 *         select_ptr = <l_logical *>select.data
 *     else:
 *         MM = N             # <<<<<<<<<<<<<<
 *         select_ptr = NULL
 *         if Q is not None:
 */
    __pyx_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":1395
 *     else:
 *         MM = N
 *         select_ptr = NULL             # <<<<<<<<<<<<<<
 *         if Q is not None:
 *             howmny = "B"
 */
    __pyx_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1396
 *         MM = N
 *         select_ptr = NULL
 *         if Q is not None:             # <<<<<<<<<<<<<<
 *             howmny = "B"
 *         else:
 */
    __pyx_t_14 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1397
 *         select_ptr = NULL
 *         if Q is not None:
 *             howmny = "B"             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_howmny = __pyx_k__B;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1399
 *             howmny = "B"
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L5:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1401
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vl = np.asfortranarray(Q.copy())
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1402
 * 
 *     if left:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_14 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_14) {
      __pyx_t_12 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_13 = __pyx_t_12;
    } else {
      __pyx_t_13 = __pyx_t_14;
    }
    if (__pyx_t_13) {

      /* "kwant/linalg/lapack.pyx":1403
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1405
 *             vl = np.asfortranarray(Q.copy())
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *     else:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_1 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L7:;

    /* "kwant/linalg/lapack.pyx":1406
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_vl_ptr = ((__pyx_t_double_complex *)__pyx_v_vl->data);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1408
 *         vl_ptr = <double complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1410
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if Q is not None and select is None:
 *             vr = np.asfortranarray(Q.copy())
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1411
 * 
 *     if right:
 *         if Q is not None and select is None:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 */
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    if (__pyx_t_13) {
      __pyx_t_14 = (((PyObject *)__pyx_v_select) == Py_None);
      __pyx_t_12 = __pyx_t_14;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":1412
 *     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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_Q), __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L9;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":1414
 *             vr = np.asfortranarray(Q.copy())
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *     else:
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":1415
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_vr_ptr = ((__pyx_t_double_complex *)__pyx_v_vr->data);
    goto __pyx_L8;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1417
 *         vr_ptr = <double complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ztrevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":1422
 *                      &N, <double complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 *                      <double complex *>work.data, <double *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrevc"
 */
  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":1424
 *                      <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"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_113));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1425
 * 
 *     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:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_114));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1427
 *     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_t_12 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_12) {
    __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":1428
 * 
 *     if select is not None and Q is not None:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1429
 *     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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__dot); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl));
      PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vl));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
      __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl));
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "kwant/linalg/lapack.pyx":1430
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {

      /* "kwant/linalg/lapack.pyx":1431
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Q, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__dot); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr));
      PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_vr));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
      __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr));
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "kwant/linalg/lapack.pyx":1433
 *             vr = np.asfortranarray(np.dot(Q, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_14;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1434
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L13;
  }

  /* "kwant/linalg/lapack.pyx":1435
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":1436
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1438
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }
  __pyx_L13:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("sgges"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_65sgges, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_115;
    values[3] = __pyx_k_116;
    values[4] = __pyx_k_117;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sgges", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1442
 * 
 * # 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):
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sgges", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __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":1451
 *     cdef np.ndarray[np.float32_t] alphar, alphai, beta, work
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1454
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1455
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1456
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1458
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1459
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <float *>vsl.data
 *         jobvsl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1460
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __pyx_v_vsl_ptr = ((float *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1461
 *         vsl = np.empty((N,N), dtype = np.float32, order='F')
 *         vsl_ptr = <float *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __pyx_v_jobvsl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1463
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1464
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1465
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __pyx_v_jobvsl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1467
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1468
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <float *>vsr.data
 *         jobvsr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1469
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __pyx_v_vsr_ptr = ((float *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1470
 *         vsr = np.empty((N,N), dtype = np.float32, order='F')
 *         vsr_ptr = <float *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __pyx_v_jobvsr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1472
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1473
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1474
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvsr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1477
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.sgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <float *>A.data, &N,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1484
 *                     <float *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     &qwork, &lwork, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  sgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1486
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1489
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1498
 *                     <float *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     <float *>work.data, &lwork, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  sgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1500
 *                     <float *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in sgges")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1501
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_119), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1503
 *         raise LinAlgError("QZ iteration failed to converge in sgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1505
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1506
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __pyx_t_3 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_alpha = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1508
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1510
 *         alpha = alphar
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1511
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dgges"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_67dgges, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_120;
    values[3] = __pyx_k_121;
    values[4] = __pyx_k_122;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dgges", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1515; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1514
 * 
 * 
 * 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):
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dgges", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __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":1523
 *     cdef np.ndarray[np.float64_t] alphar, alphai, beta, work
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1526
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1527
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1528
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1530
 *     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_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1531
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <double *>vsl.data
 *         jobvsl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1532
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __pyx_v_vsl_ptr = ((double *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1533
 *         vsl = np.empty((N,N), dtype = np.float64, order='F')
 *         vsl_ptr = <double *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __pyx_v_jobvsl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1535
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1536
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1537
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __pyx_v_jobvsl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1539
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1540
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <double *>vsr.data
 *         jobvsr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1541
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __pyx_v_vsr_ptr = ((double *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1542
 *         vsr = np.empty((N,N), dtype = np.float64, order='F')
 *         vsr_ptr = <double *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __pyx_v_jobvsr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1544
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
    __pyx_t_12 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_12 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1545
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1546
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvsr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1549
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <double *>A.data, &N,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1556
 *                     <double *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     &qwork, &lwork, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  dgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1558
 *                     &qwork, &lwork, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1561
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1570
 *                     <double *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     <double *>work.data, &lwork, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  dgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1572
 *                     <double *>work.data, &lwork, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in dgges")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1573
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_124), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1575
 *         raise LinAlgError("QZ iteration failed to converge in dgges")
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1577
 *     assert info == 0, "Argument error in zgees"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1578
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __pyx_t_3 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_alpha = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1580
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1582
 *         alpha = alphar
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (A, B, vsl, vsr, alpha, beta))
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1583
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("cgges"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_69cgges, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_125;
    values[3] = __pyx_k_126;
    values[4] = __pyx_k_127;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cgges", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1586
 * 
 * 
 * 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):
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cgges", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __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":1596
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1599
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1600
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1601
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong((8 * __pyx_v_N)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __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_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_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_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_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1603
 *     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_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1604
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <float complex *>vsl.data
 *         jobvsl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1605
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __pyx_v_vsl_ptr = ((__pyx_t_float_complex *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1606
 *         vsl = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsl_ptr = <float complex *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __pyx_v_jobvsl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1608
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1609
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1610
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __pyx_v_jobvsl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1612
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1613
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <float complex *>vsr.data
 *         jobvsr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1614
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __pyx_v_vsr_ptr = ((__pyx_t_float_complex *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1615
 *         vsr = np.empty((N,N), dtype = np.complex64, order='F')
 *         vsr_ptr = <float complex *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __pyx_v_jobvsr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1617
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1618
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1619
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvsr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1622
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.cgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <float complex *>A.data, &N,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1628
 *                     <float complex *>alpha.data, <float complex *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  cgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1630
 *                     &qwork, &lwork, <float *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1633
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1642
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     <float complex *>work.data, &lwork,
 *                     <float *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  cgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1644
 *                     <float *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in cgges")
 * 
 */
  __pyx_t_12 = (__pyx_v_info > 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1645
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_129), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1647
 *         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),
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1649
 *     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_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1650
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("zgges"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_71zgges, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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};
    values[2] = __pyx_k_130;
    values[3] = __pyx_k_131;
    values[4] = __pyx_k_132;
    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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__A)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__B)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("zgges", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__calc_z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_B), __pyx_ptype_5numpy_ndarray, 1, "B", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1653
 * 
 * 
 * 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):
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zgges", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __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":1663
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(A, B)             # <<<<<<<<<<<<<<
 * 
 *     N = A.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

  /* "kwant/linalg/lapack.pyx":1666
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1667
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1668
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong((8 * __pyx_v_N)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __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_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_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_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_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1670
 *     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_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_q); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1671
 * 
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vsl_ptr = <double complex *>vsl.data
 *         jobvsl = "V"
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vsl = ((PyArrayObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":1672
 *     if calc_q:
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data             # <<<<<<<<<<<<<<
 *         jobvsl = "V"
 *     else:
 */
    __pyx_v_vsl_ptr = ((__pyx_t_double_complex *)__pyx_v_vsl->data);

    /* "kwant/linalg/lapack.pyx":1673
 *         vsl = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsl_ptr = <double complex *>vsl.data
 *         jobvsl = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsl = None
 */
    __pyx_v_jobvsl = __pyx_k__V;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1675
 *         jobvsl = "V"
 *     else:
 *         vsl = None             # <<<<<<<<<<<<<<
 *         vsl_ptr = NULL
 *         jobvsl = "N"
 */
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsl.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsl = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1676
 *     else:
 *         vsl = None
 *         vsl_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsl = "N"
 * 
 */
    __pyx_v_vsl_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1677
 *         vsl = None
 *         vsl_ptr = NULL
 *         jobvsl = "N"             # <<<<<<<<<<<<<<
 * 
 *     if calc_z:
 */
    __pyx_v_jobvsl = __pyx_k__N;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1679
 *         jobvsl = "N"
 * 
 *     if calc_z:             # <<<<<<<<<<<<<<
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_calc_z); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1680
 * 
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vsr_ptr = <double complex *>vsr.data
 *         jobvsr = "V"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __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_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __pyx_v_vsr = ((PyArrayObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":1681
 *     if calc_z:
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data             # <<<<<<<<<<<<<<
 *         jobvsr = "V"
 *     else:
 */
    __pyx_v_vsr_ptr = ((__pyx_t_double_complex *)__pyx_v_vsr->data);

    /* "kwant/linalg/lapack.pyx":1682
 *         vsr = np.empty((N,N), dtype = np.complex128, order='F')
 *         vsr_ptr = <double complex *>vsr.data
 *         jobvsr = "V"             # <<<<<<<<<<<<<<
 *     else:
 *         vsr = None
 */
    __pyx_v_jobvsr = __pyx_k__V;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1684
 *         jobvsr = "V"
 *     else:
 *         vsr = None             # <<<<<<<<<<<<<<
 *         vsr_ptr = NULL
 *         jobvsr = "N"
 */
    __pyx_t_13 = ((PyArrayObject *)Py_None);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vsr.rcbuffer->pybuffer);
      __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_13 = 0;
    __Pyx_INCREF(Py_None);
    __pyx_v_vsr = ((PyArrayObject *)Py_None);

    /* "kwant/linalg/lapack.pyx":1685
 *     else:
 *         vsr = None
 *         vsr_ptr = NULL             # <<<<<<<<<<<<<<
 *         jobvsr = "N"
 * 
 */
    __pyx_v_vsr_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":1686
 *         vsr = None
 *         vsr_ptr = NULL
 *         jobvsr = "N"             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_jobvsr = __pyx_k__N;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1689
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.zgges_(jobvsl, jobvsr, "N", NULL,
 *                     &N, <double complex *>A.data, &N,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1695
 *                     <double complex *>alpha.data, <double complex *>beta.data,
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  zgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1697
 *                     &qwork, &lwork, <double *>rwork.data, NULL, &info)
 * 
 *     assert info == 0, "Argument error in zgees"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1700
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1709
 *                     vsl_ptr, &N, vsr_ptr, &N,
 *                     <double complex *>work.data, &lwork,
 *                     <double *>rwork.data, NULL, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  zgges_(__pyx_v_jobvsl, __pyx_v_jobvsr, __pyx_k__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":1711
 *                     <double *>rwork.data, NULL, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("QZ iteration failed to converge in zgges")
 * 
 */
  __pyx_t_12 = (__pyx_v_info > 0);
  if (__pyx_t_12) {

    /* "kwant/linalg/lapack.pyx":1712
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1714
 *         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),
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_75));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1716
 *     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_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_calc_q);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_calc_q);
  __Pyx_GIVEREF(__pyx_v_calc_q);
  __Pyx_INCREF(__pyx_v_calc_z);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_calc_z);
  __Pyx_GIVEREF(__pyx_v_calc_z);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1717
 * 
 *     return filter_args((True, True, calc_q, calc_z, calc_ev, calc_ev),
 *                        (A, B, vsl, vsr, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_A));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_A));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_A));
  __Pyx_INCREF(((PyObject *)__pyx_v_B));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_B));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_B));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsl));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_vsl));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsl));
  __Pyx_INCREF(((PyObject *)__pyx_v_vsr));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_v_vsr));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_vsr));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("stgsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_73stgsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1724
 *            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":1725
 *            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);
    values[5] = __pyx_k_135;
    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);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgsen", 0, 3, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgsen", 0, 3, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1721
 * 
 * # 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,
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stgsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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":1733
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1735
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1736
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1737
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1738
 *     alphar = np.empty(N, dtype = np.float32)
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1739
 *     alphai = np.empty(N, dtype = np.float32)
 *     beta = np.empty(N, dtype = np.float32)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1741
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float *>Q.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1742
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <float *>Q.data
 *     else:
 */
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1743
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <float *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __pyx_v_q_ptr = ((float *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1745
 *         q_ptr = <float *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1746
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1748
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float *>Z.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1749
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <float *>Z.data
 *     else:
 */
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1750
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <float *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __pyx_v_z_ptr = ((float *)__pyx_v_Z->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1752
 *         z_ptr = <float *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1753
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1756
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1757
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.stgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <float *>S.data, &N,
 */
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1764
 *                      <float *>beta.data,
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgsen"
 */
  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":1766
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in stgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_136));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1769
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1770
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1771
 *     work = np.empty(lwork, dtype = np.float32)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__int_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_12, &__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_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_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_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1781
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      <float *>work.data, &lwork,
 *                      <l_int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":1783
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1784
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgsen"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_137), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1786
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in stgsen"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_136));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1788
 *     assert info == 0, "Argument error in stgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1789
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __pyx_t_4 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_alpha = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1791
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1793
 *         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_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "kwant/linalg/lapack.pyx":1794
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __pyx_t_13 = PyTuple_New(6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1795
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_5, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
  __pyx_t_13 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dtgsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_75dtgsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1801
 *            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":1802
 *            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);
    values[5] = __pyx_k_138;
    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);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgsen", 0, 3, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgsen", 0, 3, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1798
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dtgsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __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":1810
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1812
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1813
 * 
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphar.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphar.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphar = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1814
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alphai.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alphai.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alphai = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1815
 *     alphar = np.empty(N, dtype = np.float64)
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1816
 *     alphai = np.empty(N, dtype = np.float64)
 *     beta = np.empty(N, dtype = np.float64)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1818
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double *>Q.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1819
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <double *>Q.data
 *     else:
 */
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1820
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <double *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __pyx_v_q_ptr = ((double *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1822
 *         q_ptr = <double *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1823
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1825
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double *>Z.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1826
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <double *>Z.data
 *     else:
 */
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1827
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <double *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __pyx_v_z_ptr = ((double *)__pyx_v_Z->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1829
 *         z_ptr = <double *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1830
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1833
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1834
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.dtgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <double *>S.data, &N,
 */
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1841
 *                      <double *>beta.data,
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgsen"
 */
  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":1843
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in dtgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_139));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

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

  /* "kwant/linalg/lapack.pyx":1846
 * 
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1847
 *     lwork = <int>qwork
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1848
 *     work = np.empty(lwork, dtype = np.float64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__int_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_12, &__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_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_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_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1858
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      <double *>work.data, &lwork,
 *                      <l_int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":1860
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1861
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgsen"
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_140), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1863
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 *     assert info == 0, "Argument error in dtgsen"             # <<<<<<<<<<<<<<
 * 
 *     if alphai.nonzero()[0].size:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_139));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1865
 *     assert info == 0, "Argument error in dtgsen"
 * 
 *     if alphai.nonzero()[0].size:             # <<<<<<<<<<<<<<
 *         alpha = alphar + 1j * alphai
 *     else:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_alphai), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1866
 * 
 *     if alphai.nonzero()[0].size:
 *         alpha = alphar + 1j * alphai             # <<<<<<<<<<<<<<
 *     else:
 *         alpha = alphar
 */
    __pyx_t_4 = PyComplex_FromDoubles(0.0, 1.0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, ((PyObject *)__pyx_v_alphai)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_v_alphar), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_alpha = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1868
 *         alpha = alphar + 1j * alphai
 *     else:
 *         alpha = alphar             # <<<<<<<<<<<<<<
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_alphar));
    __pyx_v_alpha = ((PyObject *)__pyx_v_alphar);
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":1870
 *         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_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "kwant/linalg/lapack.pyx":1871
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __pyx_t_13 = PyTuple_New(6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1872
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_5, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(__pyx_v_alpha);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_alpha);
  __Pyx_GIVEREF(__pyx_v_alpha);
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_5, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
  __pyx_t_13 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ctgsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_77ctgsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1878
 *            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":1879
 *            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);
    values[5] = __pyx_k_141;
    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);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgsen", 0, 3, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgsen", 0, 3, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1875
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ctgsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __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":1887
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1889
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1890
 * 
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex64)
 *     ijob = 0
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1891
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1892
 *     alpha = np.empty(N, dtype = np.complex64)
 *     beta = np.empty(N, dtype = np.complex64)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1894
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <float complex *>Q.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1895
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <float complex *>Q.data
 *     else:
 */
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1896
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <float complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __pyx_v_q_ptr = ((__pyx_t_float_complex *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1898
 *         q_ptr = <float complex *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1899
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1901
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <float complex *>Z.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1902
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <float complex *>Z.data
 *     else:
 */
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1903
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <float complex *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __pyx_v_z_ptr = ((__pyx_t_float_complex *)__pyx_v_Z->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1905
 *         z_ptr = <float complex *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1906
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1909
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1910
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ctgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <float complex *>S.data, &N,
 */
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1916
 *                      <float complex *>alpha.data, <float complex *>beta.data,
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgsen"
 */
  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":1918
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in ctgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_142));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1920
 *     assert info == 0, "Argument error in ctgsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork
 */
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1921
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1922
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1923
 *     work = np.empty(lwork, dtype = np.complex64)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__int_dtype); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_5);
  {
    __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_12, &__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_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_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1932
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      <float complex *>work.data, &lwork,
 *                      <l_int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":1934
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1935
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgsen"
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_143), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":1937
 *         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,
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_142));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1939
 *     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_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "kwant/linalg/lapack.pyx":1940
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __pyx_t_13 = PyTuple_New(6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1941
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __pyx_t_13 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ztgsen"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_79ztgsen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":1947
 *            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":1948
 *            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);
    values[5] = __pyx_k_144;
    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);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgsen", 0, 3, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgsen", 0, 3, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_S), __pyx_ptype_5numpy_ndarray, 1, "S", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":1944
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */

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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ztgsen", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __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":1956
 *     cdef np.ndarray[l_int] iwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":1958
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":1959
 * 
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     beta = np.empty(N, dtype = np.complex128)
 *     ijob = 0
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_alpha.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_alpha.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_alpha = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":1960
 *     N = S.shape[0]
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     ijob = 0
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_beta.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_beta.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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_beta = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":1961
 *     alpha = np.empty(N, dtype = np.complex128)
 *     beta = np.empty(N, dtype = np.complex128)
 *     ijob = 0             # <<<<<<<<<<<<<<
 * 
 *     if Q is not None:
 */
  __pyx_v_ijob = 0;

  /* "kwant/linalg/lapack.pyx":1963
 *     ijob = 0
 * 
 *     if Q is not None:             # <<<<<<<<<<<<<<
 *         wantq = 1
 *         q_ptr = <double complex *>Q.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1964
 * 
 *     if Q is not None:
 *         wantq = 1             # <<<<<<<<<<<<<<
 *         q_ptr = <double complex *>Q.data
 *     else:
 */
    __pyx_v_wantq = 1;

    /* "kwant/linalg/lapack.pyx":1965
 *     if Q is not None:
 *         wantq = 1
 *         q_ptr = <double complex *>Q.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantq = 0
 */
    __pyx_v_q_ptr = ((__pyx_t_double_complex *)__pyx_v_Q->data);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1967
 *         q_ptr = <double complex *>Q.data
 *     else:
 *         wantq = 0             # <<<<<<<<<<<<<<
 *         q_ptr = NULL
 * 
 */
    __pyx_v_wantq = 0;

    /* "kwant/linalg/lapack.pyx":1968
 *     else:
 *         wantq = 0
 *         q_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if Z is not None:
 */
    __pyx_v_q_ptr = NULL;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":1970
 *         q_ptr = NULL
 * 
 *     if Z is not None:             # <<<<<<<<<<<<<<
 *         wantz = 1
 *         z_ptr = <double complex *>Z.data
 */
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":1971
 * 
 *     if Z is not None:
 *         wantz = 1             # <<<<<<<<<<<<<<
 *         z_ptr = <double complex *>Z.data
 *     else:
 */
    __pyx_v_wantz = 1;

    /* "kwant/linalg/lapack.pyx":1972
 *     if Z is not None:
 *         wantz = 1
 *         z_ptr = <double complex *>Z.data             # <<<<<<<<<<<<<<
 *     else:
 *         wantz = 0
 */
    __pyx_v_z_ptr = ((__pyx_t_double_complex *)__pyx_v_Z->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":1974
 *         z_ptr = <double complex *>Z.data
 *     else:
 *         wantz = 0             # <<<<<<<<<<<<<<
 *         z_ptr = NULL
 * 
 */
    __pyx_v_wantz = 0;

    /* "kwant/linalg/lapack.pyx":1975
 *     else:
 *         wantz = 0
 *         z_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # workspace query
 */
    __pyx_v_z_ptr = NULL;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":1978
 * 
 *     # workspace query
 *     lwork = -1             # <<<<<<<<<<<<<<
 *     liwork = -1
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 */
  __pyx_v_lwork = -1;

  /* "kwant/linalg/lapack.pyx":1979
 *     # workspace query
 *     lwork = -1
 *     liwork = -1             # <<<<<<<<<<<<<<
 *     f_lapack.ztgsen_(&ijob, &wantq, &wantz, <l_logical *>select.data,
 *                      &N, <double complex *>S.data, &N,
 */
  __pyx_v_liwork = -1;

  /* "kwant/linalg/lapack.pyx":1985
 *                      <double complex *>alpha.data, <double complex *>beta.data,
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      &qwork, &lwork, &qiwork, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgsen"
 */
  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":1987
 *                      &qwork, &lwork, &qiwork, &liwork, &info)
 * 
 *     assert info == 0, "Argument error in ztgsen"             # <<<<<<<<<<<<<<
 * 
 *     lwork = <int>qwork.real
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_145));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":1989
 *     assert info == 0, "Argument error in ztgsen"
 * 
 *     lwork = <int>qwork.real             # <<<<<<<<<<<<<<
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork
 */
  __pyx_v_lwork = ((int)__Pyx_CREAL(__pyx_v_qwork));

  /* "kwant/linalg/lapack.pyx":1990
 * 
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyInt_FromLong(__pyx_v_lwork); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_2);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":1991
 *     lwork = <int>qwork.real
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork             # <<<<<<<<<<<<<<
 *     iwork = np.empty(liwork, dtype = int_dtype)
 * 
 */
  __pyx_v_liwork = __pyx_v_qiwork;

  /* "kwant/linalg/lapack.pyx":1992
 *     work = np.empty(lwork, dtype = np.complex128)
 *     liwork = qiwork
 *     iwork = np.empty(liwork, dtype = int_dtype)             # <<<<<<<<<<<<<<
 * 
 *     # Now the real calculation
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromLong(__pyx_v_liwork); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__int_dtype); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_5);
  {
    __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_12, &__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_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_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_iwork = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":2001
 *                      q_ptr, &N, z_ptr, &N, &M, NULL, NULL, NULL,
 *                      <double complex *>work.data, &lwork,
 *                      <l_int *>iwork.data, &liwork, &info)             # <<<<<<<<<<<<<<
 * 
 *     if info > 0:
 */
  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":2003
 *                      <l_int *>iwork.data, &liwork, &info)
 * 
 *     if info > 0:             # <<<<<<<<<<<<<<
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")
 * 
 */
  __pyx_t_11 = (__pyx_v_info > 0);
  if (__pyx_t_11) {

    /* "kwant/linalg/lapack.pyx":2004
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgsen"
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__LinAlgError); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_146), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "kwant/linalg/lapack.pyx":2006
 *         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,
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_145));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2008
 *     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_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__filter_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = (((PyObject *)__pyx_v_Q) != Py_None);
  __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_11 = (((PyObject *)__pyx_v_Z) != Py_None);
  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_11); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "kwant/linalg/lapack.pyx":2009
 * 
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),             # <<<<<<<<<<<<<<
 *                        (S, T, Q, Z, alpha, beta))
 * 
 */
  __pyx_t_13 = PyTuple_New(6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __Pyx_INCREF(__pyx_v_calc_ev);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_v_calc_ev);
  __Pyx_GIVEREF(__pyx_v_calc_ev);
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2010
 *     return filter_args((True, True, Q is not None, Z is not None,
 *                         calc_ev, calc_ev),
 *                        (S, T, Q, Z, alpha, beta))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __Pyx_INCREF(((PyObject *)__pyx_v_alpha));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_v_alpha));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alpha));
  __Pyx_INCREF(((PyObject *)__pyx_v_beta));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_v_beta));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_beta));
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __pyx_t_13 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("stgevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_81stgevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":2016
 * 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":2017
 *            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":2018
 *            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);
    values[5] = __pyx_k_147;
    values[6] = __pyx_k_148;
    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);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stgevc", 0, 2, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2014
 * 
 * # 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,
 */

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_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;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyArrayObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  PyArrayObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stgevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __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":2028
 *     cdef np.ndarray[np.float32_t] work
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2030
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(6*N, dtype = np.float32)
 * 
 */
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2031
 * 
 *     N = S.shape[0]
 *     work = np.empty(6*N, dtype = np.float32)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((6 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":2033
 *     work = np.empty(6*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

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

  /* "kwant/linalg/lapack.pyx":2035
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2036
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2037
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2038
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2040
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2042
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2044
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2045
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":2046
 *     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_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":2050
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    __Pyx_INCREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __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, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_cmplxindx = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":2051
 *         # 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
 */
    if (PyList_CheckExact(__pyx_v_cmplxindx) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_3 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_3); __pyx_t_15 = 0;
      __pyx_t_16 = NULL;
    } else {
      __pyx_t_15 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_1 = __pyx_t_16(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF(__pyx_v_i);
      __pyx_v_i = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":2052
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_5); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_13) {

        /* "kwant/linalg/lapack.pyx":2053
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # select is overwritten in stgevc
 */
        __pyx_v_MM = (__pyx_v_MM + 1);
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":2056
 * 
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_17 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_17 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "kwant/linalg/lapack.pyx":2058
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2060
 *         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_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2061
 *     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_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2062
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {
        __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
        if (__pyx_t_12) {
          __pyx_t_18 = (((PyObject *)__pyx_v_Z) != Py_None);
          __pyx_t_19 = __pyx_t_18;
        } else {
          __pyx_t_19 = __pyx_t_12;
        }
        __pyx_t_12 = __pyx_t_19;
      } else {
        __pyx_t_12 = __pyx_t_11;
      }
      __pyx_t_11 = __pyx_t_12;
    } else {
      __pyx_t_11 = __pyx_t_13;
    }
    if (!__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":2063
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_13) {
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_19 = (!__pyx_t_12);
        if (__pyx_t_19) {
          __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
          __pyx_t_18 = __pyx_t_12;
        } else {
          __pyx_t_18 = __pyx_t_19;
        }
        __pyx_t_19 = __pyx_t_18;
      } else {
        __pyx_t_19 = __pyx_t_13;
      }
      if (!__pyx_t_19) {

        /* "kwant/linalg/lapack.pyx":2064
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_13) {
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_12 = (!__pyx_t_18);
          if (__pyx_t_12) {
            __pyx_t_18 = (((PyObject *)__pyx_v_Z) != Py_None);
            __pyx_t_20 = __pyx_t_18;
          } else {
            __pyx_t_20 = __pyx_t_12;
          }
          __pyx_t_12 = __pyx_t_20;
        } else {
          __pyx_t_12 = __pyx_t_13;
        }
        __pyx_t_13 = __pyx_t_12;
      } else {
        __pyx_t_13 = __pyx_t_19;
      }
      __pyx_t_19 = __pyx_t_13;
    } else {
      __pyx_t_19 = __pyx_t_11;
    }
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2065
 *             (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_v_howmny = __pyx_k__B;

      /* "kwant/linalg/lapack.pyx":2066
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_backtr = 1;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2068
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L8:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":2070
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2071
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2072
 *     if left:
 *         if backtr:
 *             vl_r = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_v_Q);
      goto __pyx_L10;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2074
 *             vl_r = Q
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float32); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L10:;

    /* "kwant/linalg/lapack.pyx":2075
 *         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_v_vl_r_ptr = ((float *)__pyx_v_vl_r->data);
    goto __pyx_L9;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2077
 *         vl_r_ptr = <float *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L9:;

  /* "kwant/linalg/lapack.pyx":2079
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2080
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2081
 *     if right:
 *         if backtr:
 *             vr_r = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2081; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_v_Z);
      goto __pyx_L12;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2083
 *             vr_r = Z
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float32, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
      __pyx_t_2 = 0;
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":2084
 *         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_v_vr_r_ptr = ((float *)__pyx_v_vr_r->data);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2086
 *         vr_r_ptr = <float *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.stgevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":2092
 *                      <float *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 *                      <float *>work.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgevc"
 */
  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":2094
 *                      <float *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in stgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_149));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2095
 * 
 *     assert info == 0, "Argument error in stgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in stgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_150));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2097
 *     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_t_19 = (!__pyx_v_backtr);
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2098
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2099
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__dot); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "kwant/linalg/lapack.pyx":2100
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2101
 *             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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_Z));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "kwant/linalg/lapack.pyx":2104
 * 
 *     # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2105
 *     # 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_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2106
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_v_vl = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "kwant/linalg/lapack.pyx":2107
 *         if left:
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2108
 *             vl = txevc_postprocess(np.complex64, S, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__complex64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_v_vr = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L18;
    }
    __pyx_L18:;
    goto __pyx_L16;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2110
 *             vr = txevc_postprocess(np.complex64, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2111
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":2112
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2113
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);
      goto __pyx_L20;
    }
    __pyx_L20:;
  }
  __pyx_L16:;

  /* "kwant/linalg/lapack.pyx":2115
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_11;
  } else {
    __pyx_t_13 = __pyx_t_19;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2116
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":2117
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2118
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2120
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }
  __pyx_L21:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("dtgevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_83dtgevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":2125
 * 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":2126
 *            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":2127
 *            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);
    values[5] = __pyx_k_151;
    values[6] = __pyx_k_152;
    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);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("dtgevc", 0, 2, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2123
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_12;
  int __pyx_t_13;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  PyObject *(*__pyx_t_16)(PyObject *);
  PyArrayObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  PyArrayObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("dtgevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __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":2137
 *     cdef np.ndarray[np.float64_t] work
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2139
 *     assert_fortran_mat(S, T, Q, Z)
 * 
 *     N = S.shape[0]             # <<<<<<<<<<<<<<
 *     work = np.empty(6*N, dtype = np.float64)
 * 
 */
  __pyx_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2140
 * 
 *     N = S.shape[0]
 *     work = np.empty(6*N, dtype = np.float64)             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((6 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 2140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":2142
 *     work = np.empty(6*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_11) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_11;
  }
  if (__pyx_t_13) {

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

  /* "kwant/linalg/lapack.pyx":2144
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2145
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2146
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2147
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2149
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2151
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2153
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_13 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2154
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         # Correct for possible additional storage if a single complex
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":2155
 *     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_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_MM = __pyx_t_14;

    /* "kwant/linalg/lapack.pyx":2159
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_S));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
    __Pyx_INCREF(__pyx_int_neg_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
    __Pyx_GIVEREF(__pyx_int_neg_1);
    __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __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, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_cmplxindx = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":2160
 *         # 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
 */
    if (PyList_CheckExact(__pyx_v_cmplxindx) || PyTuple_CheckExact(__pyx_v_cmplxindx)) {
      __pyx_t_3 = __pyx_v_cmplxindx; __Pyx_INCREF(__pyx_t_3); __pyx_t_15 = 0;
      __pyx_t_16 = NULL;
    } else {
      __pyx_t_15 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_cmplxindx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_1); __pyx_t_15++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_1 = __pyx_t_16(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF(__pyx_v_i);
      __pyx_v_i = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "kwant/linalg/lapack.pyx":2161
 *         cmplxindx = np.diagonal(S, -1).nonzero()[0]
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):             # <<<<<<<<<<<<<<
 *                 MM += 1
 * 
 */
      __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_select), __pyx_t_5); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_13))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_13) {

        /* "kwant/linalg/lapack.pyx":2162
 *         for i in cmplxindx:
 *             if bool(select[i]) != bool(select[i+1]):
 *                 MM += 1             # <<<<<<<<<<<<<<
 * 
 *         # select is overwritten in dtgevc
 */
        __pyx_v_MM = (__pyx_v_MM + 1);
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "kwant/linalg/lapack.pyx":2165
 * 
 *         # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__array); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_select));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_select));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_17 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_select_cpy.rcbuffer->pybuffer, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5kwant_6linalg_8f_lapack_l_logical, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_17 = 0;
    __pyx_v_select_cpy = ((PyArrayObject *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "kwant/linalg/lapack.pyx":2167
 *         select_cpy = np.array(select, dtype = f_lapack.l_logical_dtype,
 *                               order = 'F')
 *         select_ptr = <l_logical *>select_cpy.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select_cpy->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2169
 *         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_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2170
 *     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_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2171
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_13) {
      __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {
        __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
        if (__pyx_t_12) {
          __pyx_t_18 = (((PyObject *)__pyx_v_Z) != Py_None);
          __pyx_t_19 = __pyx_t_18;
        } else {
          __pyx_t_19 = __pyx_t_12;
        }
        __pyx_t_12 = __pyx_t_19;
      } else {
        __pyx_t_12 = __pyx_t_11;
      }
      __pyx_t_11 = __pyx_t_12;
    } else {
      __pyx_t_11 = __pyx_t_13;
    }
    if (!__pyx_t_11) {

      /* "kwant/linalg/lapack.pyx":2172
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_13) {
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_19 = (!__pyx_t_12);
        if (__pyx_t_19) {
          __pyx_t_12 = (((PyObject *)__pyx_v_Q) != Py_None);
          __pyx_t_18 = __pyx_t_12;
        } else {
          __pyx_t_18 = __pyx_t_19;
        }
        __pyx_t_19 = __pyx_t_18;
      } else {
        __pyx_t_19 = __pyx_t_13;
      }
      if (!__pyx_t_19) {

        /* "kwant/linalg/lapack.pyx":2173
 *         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_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_13) {
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_12 = (!__pyx_t_18);
          if (__pyx_t_12) {
            __pyx_t_18 = (((PyObject *)__pyx_v_Z) != Py_None);
            __pyx_t_20 = __pyx_t_18;
          } else {
            __pyx_t_20 = __pyx_t_12;
          }
          __pyx_t_12 = __pyx_t_20;
        } else {
          __pyx_t_12 = __pyx_t_13;
        }
        __pyx_t_13 = __pyx_t_12;
      } else {
        __pyx_t_13 = __pyx_t_19;
      }
      __pyx_t_19 = __pyx_t_13;
    } else {
      __pyx_t_19 = __pyx_t_11;
    }
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2174
 *             (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_v_howmny = __pyx_k__B;

      /* "kwant/linalg/lapack.pyx":2175
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_backtr = 1;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2177
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L8:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":2179
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl_r = Q
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2180
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl_r = Q
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2181
 *     if left:
 *         if backtr:
 *             vl_r = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_v_Q);
      goto __pyx_L10;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2183
 *             vl_r = Q
 *         else:
 *             vl_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L10:;

    /* "kwant/linalg/lapack.pyx":2184
 *         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_v_vl_r_ptr = ((double *)__pyx_v_vl_r->data);
    goto __pyx_L9;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2186
 *         vl_r_ptr = <double *>vl_r.data
 *     else:
 *         vl_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_r_ptr = NULL;
  }
  __pyx_L9:;

  /* "kwant/linalg/lapack.pyx":2188
 *         vl_r_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr_r = Z
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2189
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr_r = Z
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2190
 *     if right:
 *         if backtr:
 *             vr_r = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_v_Z);
      goto __pyx_L12;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2192
 *             vr_r = Z
 *         else:
 *             vr_r = np.empty((N, MM), dtype = np.float64, order='F')             # <<<<<<<<<<<<<<
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
      __pyx_t_2 = 0;
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_4);
      __pyx_t_4 = 0;
    }
    __pyx_L12:;

    /* "kwant/linalg/lapack.pyx":2193
 *         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_v_vr_r_ptr = ((double *)__pyx_v_vr_r->data);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2195
 *         vr_r_ptr = <double *>vr_r.data
 *     else:
 *         vr_r_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.dtgevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_r_ptr = NULL;
  }
  __pyx_L11:;

  /* "kwant/linalg/lapack.pyx":2201
 *                      <double *>T.data, &N,
 *                      vl_r_ptr, &N, vr_r_ptr, &N, &MM, &M,
 *                      <double *>work.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgevc"
 */
  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":2203
 *                      <double *>work.data, &info)
 * 
 *     assert info == 0, "Argument error in dtgevc"             # <<<<<<<<<<<<<<
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_153));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2204
 * 
 *     assert info == 0, "Argument error in dtgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in dtgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_154));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2206
 *     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_t_19 = (!__pyx_v_backtr);
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2207
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2208
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__dot); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl_r = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "kwant/linalg/lapack.pyx":2209
 *         if left:
 *             vl_r = np.asfortranarray(np.dot(Q, vl_r))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr_r = np.asfortranarray(np.dot(Z, vr_r))
 * 
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2210
 *             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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_Z));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr_r.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr_r = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "kwant/linalg/lapack.pyx":2214
 *     # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__diagonal); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(__pyx_int_neg_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__nonzero); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_19) {

    /* "kwant/linalg/lapack.pyx":2215
 *     # eigenvectors.
 *     if np.diagonal(S, -1).nonzero()[0].size:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2216
 *     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_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vl_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_v_vl = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "kwant/linalg/lapack.pyx":2217
 *         if left:
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2218
 *             vl = txevc_postprocess(np.complex128, S, vl_r, select)
 *         if right:
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)             # <<<<<<<<<<<<<<
 *     else:
 *         if left:
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__txevc_postprocess); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__complex128); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_S));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_S));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_vr_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr_r));
      __Pyx_INCREF(((PyObject *)__pyx_v_select));
      PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_select));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_select));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_v_vr = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L18;
    }
    __pyx_L18:;
    goto __pyx_L16;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2220
 *             vr = txevc_postprocess(np.complex128, S, vr_r, select)
 *     else:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = vl_r
 *         if right:
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2221
 *     else:
 *         if left:
 *             vl = vl_r             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = vr_r
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vl_r));
      __pyx_v_vl = ((PyObject *)__pyx_v_vl_r);
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "kwant/linalg/lapack.pyx":2222
 *         if left:
 *             vl = vl_r
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = vr_r
 * 
 */
    __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_19) {

      /* "kwant/linalg/lapack.pyx":2223
 *             vl = vl_r
 *         if right:
 *             vr = vr_r             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_vr_r));
      __pyx_v_vr = ((PyObject *)__pyx_v_vr_r);
      goto __pyx_L20;
    }
    __pyx_L20:;
  }
  __pyx_L16:;

  /* "kwant/linalg/lapack.pyx":2225
 *             vr = vr_r
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_19) {
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_11;
  } else {
    __pyx_t_13 = __pyx_t_19;
  }
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2226
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_vl);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_vl);
    __Pyx_GIVEREF(__pyx_v_vl);
    __Pyx_INCREF(__pyx_v_vr);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_vr);
    __Pyx_GIVEREF(__pyx_v_vr);
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L21;
  }

  /* "kwant/linalg/lapack.pyx":2227
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_13) {

    /* "kwant/linalg/lapack.pyx":2228
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vl)) { __Pyx_RaiseUnboundLocalError("vl"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vl);
    __pyx_r = __pyx_v_vl;
    goto __pyx_L0;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2230
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    if (unlikely(!__pyx_v_vr)) { __Pyx_RaiseUnboundLocalError("vr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __Pyx_INCREF(__pyx_v_vr);
    __pyx_r = __pyx_v_vr;
    goto __pyx_L0;
  }
  __pyx_L21:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ctgevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_85ctgevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":2235
 * 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":2236
 *            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":2237
 *            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);
    values[5] = __pyx_k_155;
    values[6] = __pyx_k_156;
    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);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ctgevc", 0, 2, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2237; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2233
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_13;
  int __pyx_t_14;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_t_17;
  int __pyx_t_18;
  PyArrayObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ctgevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __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":2247
 *     cdef np.ndarray[np.float32_t] rwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2249
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2250
 * 
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex64)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 2250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":2251
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":2253
 *     rwork = np.empty(2*N, dtype = np.float32)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

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

  /* "kwant/linalg/lapack.pyx":2255
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2256
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2257
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2258
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2260
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2262
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2264
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_14 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2265
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":2266
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_MM = __pyx_t_15;

    /* "kwant/linalg/lapack.pyx":2267
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2269
 *         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_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2270
 *     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_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2271
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {
        __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
        if (__pyx_t_13) {
          __pyx_t_16 = (((PyObject *)__pyx_v_Z) != Py_None);
          __pyx_t_17 = __pyx_t_16;
        } else {
          __pyx_t_17 = __pyx_t_13;
        }
        __pyx_t_13 = __pyx_t_17;
      } else {
        __pyx_t_13 = __pyx_t_12;
      }
      __pyx_t_12 = __pyx_t_13;
    } else {
      __pyx_t_12 = __pyx_t_14;
    }
    if (!__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2272
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_14) {
        __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_17 = (!__pyx_t_13);
        if (__pyx_t_17) {
          __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
          __pyx_t_16 = __pyx_t_13;
        } else {
          __pyx_t_16 = __pyx_t_17;
        }
        __pyx_t_17 = __pyx_t_16;
      } else {
        __pyx_t_17 = __pyx_t_14;
      }
      if (!__pyx_t_17) {

        /* "kwant/linalg/lapack.pyx":2273
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_14) {
          __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_13 = (!__pyx_t_16);
          if (__pyx_t_13) {
            __pyx_t_16 = (((PyObject *)__pyx_v_Z) != Py_None);
            __pyx_t_18 = __pyx_t_16;
          } else {
            __pyx_t_18 = __pyx_t_13;
          }
          __pyx_t_13 = __pyx_t_18;
        } else {
          __pyx_t_13 = __pyx_t_14;
        }
        __pyx_t_14 = __pyx_t_13;
      } else {
        __pyx_t_14 = __pyx_t_17;
      }
      __pyx_t_17 = __pyx_t_14;
    } else {
      __pyx_t_17 = __pyx_t_12;
    }
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2274
 *             (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_v_howmny = __pyx_k__B;

      /* "kwant/linalg/lapack.pyx":2275
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_backtr = 1;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2277
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L5:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":2279
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2280
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2281
 *     if left:
 *         if backtr:
 *             vl = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl = ((PyArrayObject *)__pyx_v_Q);
      goto __pyx_L7;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2283
 *             vl = Q
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <float complex *>vl.data
 *     else:
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__complex64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L7:;

    /* "kwant/linalg/lapack.pyx":2284
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vl_ptr = <float complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_vl_ptr = ((__pyx_t_float_complex *)__pyx_v_vl->data);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2286
 *         vl_ptr = <float complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2288
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2289
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2290
 *     if right:
 *         if backtr:
 *             vr = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr = ((PyArrayObject *)__pyx_v_Z);
      goto __pyx_L9;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2292
 *             vr = Z
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <float complex *>vr.data
 *     else:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_2 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":2293
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex64, order='F')
 *         vr_ptr = <float complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_vr_ptr = ((__pyx_t_float_complex *)__pyx_v_vr->data);
    goto __pyx_L8;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2295
 *         vr_ptr = <float complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ctgevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":2301
 *                      <float complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 *                      <float complex *>work.data, <float *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgevc"
 */
  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":2303
 *                      <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"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_157));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2304
 * 
 *     assert info == 0, "Argument error in ctgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_158));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2306
 *     assert MM == M, "Unexpected number of eigenvectors returned in ctgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __pyx_t_17 = (!__pyx_v_backtr);
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2307
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2308
 *     if not backtr:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vl));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl));
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "kwant/linalg/lapack.pyx":2309
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2310
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__dot); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_Z));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_float_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr));
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "kwant/linalg/lapack.pyx":2312
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_12;
  } else {
    __pyx_t_14 = __pyx_t_17;
  }
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2313
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L13;
  }

  /* "kwant/linalg/lapack.pyx":2314
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2315
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2317
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }
  __pyx_L13:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("ztgevc"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_87ztgevc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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":2322
 * 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":2323
 *            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":2324
 *            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);
    values[5] = __pyx_k_159;
    values[6] = __pyx_k_160;
    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);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__S)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__T)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ztgevc", 0, 2, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Q);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Z);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__select);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_T), __pyx_ptype_5numpy_ndarray, 1, "T", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Q), __pyx_ptype_5numpy_ndarray, 1, "Q", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Z), __pyx_ptype_5numpy_ndarray, 1, "Z", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_select), __pyx_ptype_5numpy_ndarray, 1, "select", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __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);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2320
 * 
 * 
 * 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,
 */

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_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;
  int __pyx_t_13;
  int __pyx_t_14;
  __pyx_t_5kwant_6linalg_8f_lapack_l_int __pyx_t_15;
  int __pyx_t_16;
  int __pyx_t_17;
  int __pyx_t_18;
  PyArrayObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ztgevc", 0);
  __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __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":2334
 *     cdef np.ndarray[np.float64_t] rwork
 * 
 *     assert_fortran_mat(S, T, Q, Z)             # <<<<<<<<<<<<<<
 * 
 *     N = S.shape[0]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__assert_fortran_mat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_S));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_S));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_S));
  __Pyx_INCREF(((PyObject *)__pyx_v_T));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_T));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_T));
  __Pyx_INCREF(((PyObject *)__pyx_v_Q));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_Q));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
  __Pyx_INCREF(((PyObject *)__pyx_v_Z));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_Z));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2336
 *     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_v_N = (__pyx_v_S->dimensions[0]);

  /* "kwant/linalg/lapack.pyx":2337
 * 
 *     N = S.shape[0]
 *     work = np.empty(2*N, dtype = np.complex128)             # <<<<<<<<<<<<<<
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __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_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_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_work = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "kwant/linalg/lapack.pyx":2338
 *     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_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyInt_FromLong((2 * __pyx_v_N)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __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_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_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_rwork = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "kwant/linalg/lapack.pyx":2340
 *     rwork = np.empty(2*N, dtype = np.float64)
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         side = "B"
 *     elif left:
 */
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_13;
  } else {
    __pyx_t_14 = __pyx_t_12;
  }
  if (__pyx_t_14) {

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

  /* "kwant/linalg/lapack.pyx":2342
 *     if left and right:
 *         side = "B"
 *     elif left:             # <<<<<<<<<<<<<<
 *         side = "L"
 *     elif right:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2343
 *         side = "B"
 *     elif left:
 *         side = "L"             # <<<<<<<<<<<<<<
 *     elif right:
 *         side = "R"
 */
    __pyx_v_side = __pyx_k__L;
    goto __pyx_L3;
  }

  /* "kwant/linalg/lapack.pyx":2344
 *     elif left:
 *         side = "L"
 *     elif right:             # <<<<<<<<<<<<<<
 *         side = "R"
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2345
 *         side = "L"
 *     elif right:
 *         side = "R"             # <<<<<<<<<<<<<<
 *     else:
 *         return
 */
    __pyx_v_side = __pyx_k__R;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2347
 *         side = "R"
 *     else:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     backtr = False
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "kwant/linalg/lapack.pyx":2349
 *         return
 * 
 *     backtr = False             # <<<<<<<<<<<<<<
 * 
 *     if select is not None:
 */
  __pyx_v_backtr = 0;

  /* "kwant/linalg/lapack.pyx":2351
 *     backtr = False
 * 
 *     if select is not None:             # <<<<<<<<<<<<<<
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 */
  __pyx_t_14 = (((PyObject *)__pyx_v_select) != Py_None);
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2352
 * 
 *     if select is not None:
 *         howmny = "S"             # <<<<<<<<<<<<<<
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data
 */
    __pyx_v_howmny = __pyx_k__S;

    /* "kwant/linalg/lapack.pyx":2353
 *     if select is not None:
 *         howmny = "S"
 *         MM = select.nonzero()[0].size             # <<<<<<<<<<<<<<
 *         select_ptr = <l_logical *>select.data
 *     else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_select), __pyx_n_s__nonzero); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 0, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_15 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_MM = __pyx_t_15;

    /* "kwant/linalg/lapack.pyx":2354
 *         howmny = "S"
 *         MM = select.nonzero()[0].size
 *         select_ptr = <l_logical *>select.data             # <<<<<<<<<<<<<<
 *     else:
 *         MM = N
 */
    __pyx_v_select_ptr = ((__pyx_t_5kwant_6linalg_8f_lapack_l_logical *)__pyx_v_select->data);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2356
 *         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_v_MM = __pyx_v_N;

    /* "kwant/linalg/lapack.pyx":2357
 *     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_v_select_ptr = NULL;

    /* "kwant/linalg/lapack.pyx":2358
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {
        __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
        if (__pyx_t_13) {
          __pyx_t_16 = (((PyObject *)__pyx_v_Z) != Py_None);
          __pyx_t_17 = __pyx_t_16;
        } else {
          __pyx_t_17 = __pyx_t_13;
        }
        __pyx_t_13 = __pyx_t_17;
      } else {
        __pyx_t_13 = __pyx_t_12;
      }
      __pyx_t_12 = __pyx_t_13;
    } else {
      __pyx_t_12 = __pyx_t_14;
    }
    if (!__pyx_t_12) {

      /* "kwant/linalg/lapack.pyx":2359
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_14) {
        __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_17 = (!__pyx_t_13);
        if (__pyx_t_17) {
          __pyx_t_13 = (((PyObject *)__pyx_v_Q) != Py_None);
          __pyx_t_16 = __pyx_t_13;
        } else {
          __pyx_t_16 = __pyx_t_17;
        }
        __pyx_t_17 = __pyx_t_16;
      } else {
        __pyx_t_17 = __pyx_t_14;
      }
      if (!__pyx_t_17) {

        /* "kwant/linalg/lapack.pyx":2360
 *         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_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_14) {
          __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_13 = (!__pyx_t_16);
          if (__pyx_t_13) {
            __pyx_t_16 = (((PyObject *)__pyx_v_Z) != Py_None);
            __pyx_t_18 = __pyx_t_16;
          } else {
            __pyx_t_18 = __pyx_t_13;
          }
          __pyx_t_13 = __pyx_t_18;
        } else {
          __pyx_t_13 = __pyx_t_14;
        }
        __pyx_t_14 = __pyx_t_13;
      } else {
        __pyx_t_14 = __pyx_t_17;
      }
      __pyx_t_17 = __pyx_t_14;
    } else {
      __pyx_t_17 = __pyx_t_12;
    }
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2361
 *             (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_v_howmny = __pyx_k__B;

      /* "kwant/linalg/lapack.pyx":2362
 *             (right and not left and Z is not None)):
 *             howmny = "B"
 *             backtr = True             # <<<<<<<<<<<<<<
 *         else:
 *             howmny = "A"
 */
      __pyx_v_backtr = 1;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2364
 *             backtr = True
 *         else:
 *             howmny = "A"             # <<<<<<<<<<<<<<
 * 
 *     if left:
 */
      __pyx_v_howmny = __pyx_k__A;
    }
    __pyx_L5:;
  }
  __pyx_L4:;

  /* "kwant/linalg/lapack.pyx":2366
 *             howmny = "A"
 * 
 *     if left:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vl = Q
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2367
 * 
 *     if left:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vl = Q
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2368
 *     if left:
 *         if backtr:
 *             vl = Q             # <<<<<<<<<<<<<<
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      __pyx_v_vl = ((PyArrayObject *)__pyx_v_Q);
      goto __pyx_L7;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2370
 *             vl = Q
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vl_ptr = <double complex *>vl.data
 *     else:
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_5 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__complex128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_2);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L7:;

    /* "kwant/linalg/lapack.pyx":2371
 *         else:
 *             vl = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vl_ptr = <double complex *>vl.data             # <<<<<<<<<<<<<<
 *     else:
 *         vl_ptr = NULL
 */
    __pyx_v_vl_ptr = ((__pyx_t_double_complex *)__pyx_v_vl->data);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2373
 *         vl_ptr = <double complex *>vl.data
 *     else:
 *         vl_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     if right:
 */
    __pyx_v_vl_ptr = NULL;
  }
  __pyx_L6:;

  /* "kwant/linalg/lapack.pyx":2375
 *         vl_ptr = NULL
 * 
 *     if right:             # <<<<<<<<<<<<<<
 *         if backtr:
 *             vr = Z
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2376
 * 
 *     if right:
 *         if backtr:             # <<<<<<<<<<<<<<
 *             vr = Z
 *         else:
 */
    if (__pyx_v_backtr) {

      /* "kwant/linalg/lapack.pyx":2377
 *     if right:
 *         if backtr:
 *             vr = Z             # <<<<<<<<<<<<<<
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 */
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __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_7 < 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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      __pyx_v_vr = ((PyArrayObject *)__pyx_v_Z);
      goto __pyx_L9;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2379
 *             vr = Z
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')             # <<<<<<<<<<<<<<
 *         vr_ptr = <double complex *>vr.data
 *     else:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyInt_FromLong(__pyx_v_MM); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_2 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__complex128); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;
    }
    __pyx_L9:;

    /* "kwant/linalg/lapack.pyx":2380
 *         else:
 *             vr = np.empty((N, MM), dtype = np.complex128, order='F')
 *         vr_ptr = <double complex *>vr.data             # <<<<<<<<<<<<<<
 *     else:
 *         vr_ptr = NULL
 */
    __pyx_v_vr_ptr = ((__pyx_t_double_complex *)__pyx_v_vr->data);
    goto __pyx_L8;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2382
 *         vr_ptr = <double complex *>vr.data
 *     else:
 *         vr_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.ztgevc_(side, howmny, select_ptr,
 */
    __pyx_v_vr_ptr = NULL;
  }
  __pyx_L8:;

  /* "kwant/linalg/lapack.pyx":2388
 *                      <double complex *>T.data, &N,
 *                      vl_ptr, &N, vr_ptr, &N, &MM, &M,
 *                      <double complex *>work.data, <double *>rwork.data, &info)             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgevc"
 */
  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":2390
 *                      <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"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_info == 0))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_161));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2391
 * 
 *     assert info == 0, "Argument error in ztgevc"
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"             # <<<<<<<<<<<<<<
 * 
 *     if not backtr:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_MM == __pyx_v_M))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_162));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "kwant/linalg/lapack.pyx":2393
 *     assert MM == M, "Unexpected number of eigenvectors returned in ztgevc"
 * 
 *     if not backtr:             # <<<<<<<<<<<<<<
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 */
  __pyx_t_17 = (!__pyx_v_backtr);
  if (__pyx_t_17) {

    /* "kwant/linalg/lapack.pyx":2394
 * 
 *     if not backtr:
 *         if left:             # <<<<<<<<<<<<<<
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2395
 *     if not backtr:
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))             # <<<<<<<<<<<<<<
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_Q));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_Q));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Q));
      __Pyx_INCREF(((PyObject *)__pyx_v_vl));
      PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_vl));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vl.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vl.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vl));
      __pyx_v_vl = ((PyArrayObject *)__pyx_t_3);
      __pyx_t_3 = 0;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "kwant/linalg/lapack.pyx":2396
 *         if left:
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:             # <<<<<<<<<<<<<<
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 */
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_17) {

      /* "kwant/linalg/lapack.pyx":2397
 *             vl = np.asfortranarray(np.dot(Q, vl))
 *         if right:
 *             vr = np.asfortranarray(np.dot(Z, vr))             # <<<<<<<<<<<<<<
 * 
 *     if left and right:
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__dot); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_Z));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_Z));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_Z));
      __Pyx_INCREF(((PyObject *)__pyx_v_vr));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vr));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
      __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(((PyObject *)__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_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_19 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vr.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vr.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo___pyx_t_double_complex, PyBUF_FORMAT| PyBUF_STRIDES, 2, 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_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_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_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_19 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_v_vr));
      __pyx_v_vr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "kwant/linalg/lapack.pyx":2399
 *             vr = np.asfortranarray(np.dot(Z, vr))
 * 
 *     if left and right:             # <<<<<<<<<<<<<<
 *         return (vl, vr)
 *     elif left:
 */
  __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_17) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_right); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_t_12;
  } else {
    __pyx_t_14 = __pyx_t_17;
  }
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2400
 * 
 *     if left and right:
 *         return (vl, vr)             # <<<<<<<<<<<<<<
 *     elif left:
 *         return vl
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_vl));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vl));
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_vr));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L13;
  }

  /* "kwant/linalg/lapack.pyx":2401
 *     if left and right:
 *         return (vl, vr)
 *     elif left:             # <<<<<<<<<<<<<<
 *         return vl
 *     else:
 */
  __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_left); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "kwant/linalg/lapack.pyx":2402
 *         return (vl, vr)
 *     elif left:
 *         return vl             # <<<<<<<<<<<<<<
 *     else:
 *         return vr
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vl));
    __pyx_r = ((PyObject *)__pyx_v_vl);
    goto __pyx_L0;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2404
 *         return vl
 *     else:
 *         return vr             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_vr));
    __pyx_r = ((PyObject *)__pyx_v_vr);
    goto __pyx_L0;
  }
  __pyx_L13:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __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_RefNannyFinishContext();
  return __pyx_r;
}

/* 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 = {__Pyx_NAMESTR("prepare_for_lapack"), (PyCFunction)__pyx_pw_5kwant_6linalg_6lapack_89prepare_for_lapack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 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);
        case  0: break;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __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);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "kwant/linalg/lapack.pyx":2407
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */

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;
  PyObject *__pyx_v_i = NULL;
  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_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("prepare_for_lapack", 0);

  /* "kwant/linalg/lapack.pyx":2432
 * 
 *     # Make sure we have NumPy arrays
 *     mats = [None]*len(args)             # <<<<<<<<<<<<<<
 *     for i in xrange(len(args)):
 *         if args[i] is not None:
 */
  __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_args)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyList_New(1 * ((__pyx_t_1<0) ? 0:__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2432; __pyx_clineno = __LINE__; goto __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);
      PyList_SET_ITEM(__pyx_t_2, __pyx_temp, Py_None);
      __Pyx_GIVEREF(Py_None);
    }
  }
  __pyx_v_mats = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":2433
 *     # Make sure we have NumPy arrays
 *     mats = [None]*len(args)
 *     for i in xrange(len(args)):             # <<<<<<<<<<<<<<
 *         if args[i] is not None:
 *             arr = np.asanyarray(args[i])
 */
  __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_args)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_builtin_xrange, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) {
      if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) {
      if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_4(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "kwant/linalg/lapack.pyx":2434
 *     mats = [None]*len(args)
 *     for i in xrange(len(args)):
 *         if args[i] is not None:             # <<<<<<<<<<<<<<
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 */
    __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_v_i); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2434; __pyx_clineno = __LINE__; goto __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;
    if (__pyx_t_5) {

      /* "kwant/linalg/lapack.pyx":2435
 *     for i in xrange(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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__asanyarray); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_v_i); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_v_arr);
      __pyx_v_arr = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "kwant/linalg/lapack.pyx":2436
 *         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_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__issubdtype); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_arr, __pyx_n_s__dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s__number); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_2 = 0;
      __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = (!__pyx_t_5);
      if (__pyx_t_9) {

        /* "kwant/linalg/lapack.pyx":2437
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 *                 raise ValueError("Argument cannot be interpreted "             # <<<<<<<<<<<<<<
 *                                  "as a numeric array")
 * 
 */
        __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_164), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2437; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "kwant/linalg/lapack.pyx":2440
 *                                  "as a numeric array")
 * 
 *             mats[i] = (arr, arr is not args[i] or overwrite)             # <<<<<<<<<<<<<<
 *         else:
 *             mats[i] = (None, True)
 */
      __pyx_t_8 = PyObject_GetItem(((PyObject *)__pyx_v_args), __pyx_v_i); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = (__pyx_v_arr != __pyx_t_8);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyBool_FromLong(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (!__pyx_t_9) {
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_INCREF(__pyx_v_overwrite);
        __pyx_t_6 = __pyx_v_overwrite;
      } else {
        __pyx_t_6 = __pyx_t_8;
        __pyx_t_8 = 0;
      }
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_arr);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_arr);
      __Pyx_GIVEREF(__pyx_v_arr);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      if (PyObject_SetItem(((PyObject *)__pyx_v_mats), __pyx_v_i, ((PyObject *)__pyx_t_8)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "kwant/linalg/lapack.pyx":2442
 *             mats[i] = (arr, arr is not args[i] or overwrite)
 *         else:
 *             mats[i] = (None, True)             # <<<<<<<<<<<<<<
 * 
 *     # First figure out common dtype
 */
      __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_6, 0, Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      if (PyObject_SetItem(((PyObject *)__pyx_v_mats), __pyx_v_i, ((PyObject *)__pyx_t_6)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2447
 *     # 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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__common_type); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = ((PyObject *)__pyx_v_mats); __Pyx_INCREF(__pyx_t_8); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_8)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_1); __Pyx_INCREF(__pyx_t_7); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_10);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      #endif
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    {
      Py_ssize_t index = -1;
      __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L9_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_10);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L10_unpacking_done;
      __pyx_L9_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L10_unpacking_done:;
    }
    __Pyx_XDECREF(__pyx_v_arr);
    __pyx_v_arr = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_v_ovwrt);
    __pyx_v_ovwrt = __pyx_t_10;
    __pyx_t_10 = 0;
    __pyx_t_9 = (__pyx_v_arr != Py_None);
    if (__pyx_t_9) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_arr))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L11;
    }
    __pyx_L11:;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PySequence_Tuple(((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
  __pyx_v_dtype = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2449
 *     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__float32); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_9) {

    /* "kwant/linalg/lapack.pyx":2450
 * 
 *     if dtype == np.float32:
 *         lapacktype = 's'             # <<<<<<<<<<<<<<
 *     elif dtype == np.float64:
 *         lapacktype = 'd'
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__s));
    __pyx_v_lapacktype = ((PyObject *)__pyx_n_s__s);
    goto __pyx_L12;
  }

  /* "kwant/linalg/lapack.pyx":2451
 *     if dtype == np.float32:
 *         lapacktype = 's'
 *     elif dtype == np.float64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__float64); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_9) {

    /* "kwant/linalg/lapack.pyx":2452
 *         lapacktype = 's'
 *     elif dtype == np.float64:
 *         lapacktype = 'd'             # <<<<<<<<<<<<<<
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__d));
    __pyx_v_lapacktype = ((PyObject *)__pyx_n_s__d);
    goto __pyx_L12;
  }

  /* "kwant/linalg/lapack.pyx":2453
 *     elif dtype == np.float64:
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:             # <<<<<<<<<<<<<<
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__complex64); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_9) {

    /* "kwant/linalg/lapack.pyx":2454
 *         lapacktype = 'd'
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'             # <<<<<<<<<<<<<<
 *     elif dtype == np.complex128:
 *         lapacktype = 'z'
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__c));
    __pyx_v_lapacktype = ((PyObject *)__pyx_n_s__c);
    goto __pyx_L12;
  }

  /* "kwant/linalg/lapack.pyx":2455
 *     elif dtype == np.complex64:
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:             # <<<<<<<<<<<<<<
 *         lapacktype = 'z'
 *     else:
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s__complex128); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_dtype, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_9) {

    /* "kwant/linalg/lapack.pyx":2456
 *         lapacktype = 'c'
 *     elif dtype == np.complex128:
 *         lapacktype = 'z'             # <<<<<<<<<<<<<<
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__z));
    __pyx_v_lapacktype = ((PyObject *)__pyx_n_s__z);
    goto __pyx_L12;
  }
  /*else*/ {

    /* "kwant/linalg/lapack.pyx":2458
 *         lapacktype = 'z'
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")             # <<<<<<<<<<<<<<
 * 
 *     ret = [ lapacktype ]
 */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_166), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L12:;

  /* "kwant/linalg/lapack.pyx":2460
 *         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_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_lapacktype);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_lapacktype);
  __Pyx_GIVEREF(__pyx_v_lapacktype);
  __pyx_v_ret = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2461
 * 
 *     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_t_3 = ((PyObject *)__pyx_v_mats); __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_8 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_8); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
      PyObject* sequence = __pyx_t_8;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      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_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      #endif
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_6 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_6)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 1; __pyx_t_7 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_7)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L16_unpacking_done;
      __pyx_L15_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L16_unpacking_done:;
    }
    __Pyx_XDECREF(__pyx_v_npmat);
    __pyx_v_npmat = __pyx_t_6;
    __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_v_ovwrt);
    __pyx_v_ovwrt = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "kwant/linalg/lapack.pyx":2463
 *     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_t_9 = (__pyx_v_npmat != Py_None);
    if (__pyx_t_9) {

      /* "kwant/linalg/lapack.pyx":2464
 *         # 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_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__ndim); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, __pyx_int_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_9) {

        /* "kwant/linalg/lapack.pyx":2465
 *         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_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__flags); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyObject_GetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__F_CONTIGUOUS)); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_5 = (!__pyx_t_9);
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2466
 *             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_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_v_npmat);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_npmat);
          __Pyx_GIVEREF(__pyx_v_npmat);
          __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_6));
          if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__dtype), __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_10;
          __pyx_t_10 = 0;
          goto __pyx_L19;
        }

        /* "kwant/linalg/lapack.pyx":2467
 *                 if not npmat.flags["F_CONTIGUOUS"]:
 *                     npmat = np.asfortranarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__dtype); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_6 = PyObject_RichCompare(__pyx_t_10, __pyx_v_dtype, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2468
 *                     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_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__astype); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_INCREF(__pyx_v_dtype);
          PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_dtype);
          __Pyx_GIVEREF(__pyx_v_dtype);
          __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_8;
          __pyx_t_8 = 0;
          goto __pyx_L19;
        }

        /* "kwant/linalg/lapack.pyx":2469
 *                 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_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_ovwrt); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = (!__pyx_t_5);
        if (__pyx_t_9) {

          /* "kwant/linalg/lapack.pyx":2472
 *                     # 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_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __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_npmat, __pyx_n_s__copy); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_6 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L19;
        }
        __pyx_L19:;
        goto __pyx_L18;
      }

      /* "kwant/linalg/lapack.pyx":2473
 *                     # 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_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__ndim); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = PyObject_RichCompare(__pyx_t_6, __pyx_int_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_9) {

        /* "kwant/linalg/lapack.pyx":2474
 *                     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_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__flags); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = PyObject_GetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__C_CONTIGUOUS)); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_5 = (!__pyx_t_9);
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2475
 *             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_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_v_npmat);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_npmat);
          __Pyx_GIVEREF(__pyx_v_npmat);
          __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_10));
          if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__dtype), __pyx_v_dtype) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_7;
          __pyx_t_7 = 0;
          goto __pyx_L20;
        }

        /* "kwant/linalg/lapack.pyx":2476
 *                 if not npmat.flags["C_CONTIGUOUS"]:
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:             # <<<<<<<<<<<<<<
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__dtype); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_10 = PyObject_RichCompare(__pyx_t_7, __pyx_v_dtype, Py_NE); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (__pyx_t_5) {

          /* "kwant/linalg/lapack.pyx":2477
 *                     npmat = np.ascontiguousarray(npmat, dtype = dtype)
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)             # <<<<<<<<<<<<<<
 *                 elif not ovwrt:
 *                     npmat = np.asfortranarray(npmat.copy())
 */
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__astype); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_INCREF(__pyx_v_dtype);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_dtype);
          __Pyx_GIVEREF(__pyx_v_dtype);
          __pyx_t_6 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L20;
        }

        /* "kwant/linalg/lapack.pyx":2478
 *                 elif npmat.dtype != dtype:
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:             # <<<<<<<<<<<<<<
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 */
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_ovwrt); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = (!__pyx_t_5);
        if (__pyx_t_9) {

          /* "kwant/linalg/lapack.pyx":2479
 *                     npmat = npmat.astype(dtype)
 *                 elif not ovwrt:
 *                     npmat = np.asfortranarray(npmat.copy())             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")
 */
          __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s__asfortranarray); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_npmat, __pyx_n_s__copy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_10 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_10);
          __pyx_t_10 = 0;
          __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_v_npmat);
          __pyx_v_npmat = __pyx_t_10;
          __pyx_t_10 = 0;
          goto __pyx_L20;
        }
        __pyx_L20:;
        goto __pyx_L18;
      }
      /*else*/ {

        /* "kwant/linalg/lapack.pyx":2481
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")             # <<<<<<<<<<<<<<
 * 
 *         ret.append(npmat)
 */
        __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_168), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L18:;
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "kwant/linalg/lapack.pyx":2483
 *                 raise ValueError("Dimensionality of array is not 1 or 2")
 * 
 *         ret.append(npmat)             # <<<<<<<<<<<<<<
 * 
 *     return tuple(ret)
 */
    __pyx_t_13 = __Pyx_PyList_Append(__pyx_v_ret, __pyx_v_npmat); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "kwant/linalg/lapack.pyx":2485
 *         ret.append(npmat)
 * 
 *     return tuple(ret)             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_v_ret)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __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_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __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_i);
  __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_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* 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));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":194
 *         # 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 fullfill the PEP.
 */

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_copy_shape;
  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_v_hasfields;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  char *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }

  /* "numpy.pxd":200
 *             # of flags
 * 
 *             if info == NULL: return             # <<<<<<<<<<<<<<
 * 
 *             cdef int copy_shape, i, ndim
 */
  __pyx_t_1 = (__pyx_v_info == NULL);
  if (__pyx_t_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":203
 * 
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":204
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":206
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "numpy.pxd":208
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":209
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 copy_shape = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 copy_shape = 0
 */
    __pyx_v_copy_shape = 1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "numpy.pxd":211
 *                 copy_shape = 1
 *             else:
 *                 copy_shape = 0             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
    __pyx_v_copy_shape = 0;
  }
  __pyx_L4:;

  /* "numpy.pxd":213
 *                 copy_shape = 0
 * 
 *             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_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS);
  if (__pyx_t_1) {

    /* "numpy.pxd":214
 * 
 *             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_t_2 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS));
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "numpy.pxd":215
 *             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_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_170), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "numpy.pxd":217
 *                 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_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS);
  if (__pyx_t_3) {

    /* "numpy.pxd":218
 * 
 *             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_t_1 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS));
    __pyx_t_2 = __pyx_t_1;
  } else {
    __pyx_t_2 = __pyx_t_3;
  }
  if (__pyx_t_2) {

    /* "numpy.pxd":219
 *             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_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_172), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "numpy.pxd":221
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if copy_shape:
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "numpy.pxd":222
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if copy_shape:
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "numpy.pxd":223
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  if (__pyx_v_copy_shape) {

    /* "numpy.pxd":226
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2)));

    /* "numpy.pxd":227
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "numpy.pxd":228
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 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_t_5 = __pyx_v_ndim;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "numpy.pxd":229
 *                 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_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "numpy.pxd":230
 *                 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_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }
    goto __pyx_L7;
  }
  /*else*/ {

    /* "numpy.pxd":232
 *                     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_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "numpy.pxd":233
 *             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_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L7:;

  /* "numpy.pxd":234
 *                 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_v_info->suboffsets = NULL;

  /* "numpy.pxd":235
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "numpy.pxd":236
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(__pyx_v_self));

  /* "numpy.pxd":239
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef list stack
 */
  __pyx_v_f = NULL;

  /* "numpy.pxd":240
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef list stack
 *             cdef int offset
 */
  __pyx_t_4 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_4);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "numpy.pxd":244
 *             cdef int offset
 * 
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields and not copy_shape:
 */
  __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr);

  /* "numpy.pxd":246
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
  __pyx_t_2 = (!__pyx_v_hasfields);
  if (__pyx_t_2) {
    __pyx_t_3 = (!__pyx_v_copy_shape);
    __pyx_t_1 = __pyx_t_3;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "numpy.pxd":248
 *             if not hasfields and not copy_shape:
 *                 # do not call releasebuffer
 *                 info.obj = None             # <<<<<<<<<<<<<<
 *             else:
 *                 # need to call releasebuffer
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = Py_None;
    goto __pyx_L10;
  }
  /*else*/ {

    /* "numpy.pxd":251
 *             else:
 *                 # need to call releasebuffer
 *                 info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields:
 */
    __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);
  }
  __pyx_L10:;

  /* "numpy.pxd":253
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __pyx_t_1 = (!__pyx_v_hasfields);
  if (__pyx_t_1) {

    /* "numpy.pxd":254
 * 
 *             if not hasfields:
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __pyx_t_5 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_5;

    /* "numpy.pxd":255
 *             if not hasfields:
 *                 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_t_1 = (__pyx_v_descr->byteorder == '>');
    if (__pyx_t_1) {
      __pyx_t_2 = __pyx_v_little_endian;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (!__pyx_t_2) {

      /* "numpy.pxd":256
 *                 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_t_1 = (__pyx_v_descr->byteorder == '<');
      if (__pyx_t_1) {
        __pyx_t_3 = (!__pyx_v_little_endian);
        __pyx_t_7 = __pyx_t_3;
      } else {
        __pyx_t_7 = __pyx_t_1;
      }
      __pyx_t_1 = __pyx_t_7;
    } else {
      __pyx_t_1 = __pyx_t_2;
    }
    if (__pyx_t_1) {

      /* "numpy.pxd":257
 *                 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_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_174), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "numpy.pxd":274
 *                 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)
 */
    switch (__pyx_v_t) {

      /* "numpy.pxd":258
 *                     (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"
 */
      case NPY_BYTE:
      __pyx_v_f = __pyx_k__b;
      break;

      /* "numpy.pxd":259
 *                     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"
 */
      case NPY_UBYTE:
      __pyx_v_f = __pyx_k__B;
      break;

      /* "numpy.pxd":260
 *                 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"
 */
      case NPY_SHORT:
      __pyx_v_f = __pyx_k__h;
      break;

      /* "numpy.pxd":261
 *                 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"
 */
      case NPY_USHORT:
      __pyx_v_f = __pyx_k__H;
      break;

      /* "numpy.pxd":262
 *                 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"
 */
      case NPY_INT:
      __pyx_v_f = __pyx_k__i;
      break;

      /* "numpy.pxd":263
 *                 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"
 */
      case NPY_UINT:
      __pyx_v_f = __pyx_k__I;
      break;

      /* "numpy.pxd":264
 *                 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"
 */
      case NPY_LONG:
      __pyx_v_f = __pyx_k__l;
      break;

      /* "numpy.pxd":265
 *                 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"
 */
      case NPY_ULONG:
      __pyx_v_f = __pyx_k__L;
      break;

      /* "numpy.pxd":266
 *                 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"
 */
      case NPY_LONGLONG:
      __pyx_v_f = __pyx_k__q;
      break;

      /* "numpy.pxd":267
 *                 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"
 */
      case NPY_ULONGLONG:
      __pyx_v_f = __pyx_k__Q;
      break;

      /* "numpy.pxd":268
 *                 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"
 */
      case NPY_FLOAT:
      __pyx_v_f = __pyx_k__f;
      break;

      /* "numpy.pxd":269
 *                 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"
 */
      case NPY_DOUBLE:
      __pyx_v_f = __pyx_k__d;
      break;

      /* "numpy.pxd":270
 *                 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"
 */
      case NPY_LONGDOUBLE:
      __pyx_v_f = __pyx_k__g;
      break;

      /* "numpy.pxd":271
 *                 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"
 */
      case NPY_CFLOAT:
      __pyx_v_f = __pyx_k__Zf;
      break;

      /* "numpy.pxd":272
 *                 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"
 */
      case NPY_CDOUBLE:
      __pyx_v_f = __pyx_k__Zd;
      break;

      /* "numpy.pxd":273
 *                 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:
 */
      case NPY_CLONGDOUBLE:
      __pyx_v_f = __pyx_k__Zg;
      break;

      /* "numpy.pxd":274
 *                 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)
 */
      case NPY_OBJECT:
      __pyx_v_f = __pyx_k__O;
      break;
      default:

      /* "numpy.pxd":276
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_175), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
      __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }

    /* "numpy.pxd":277
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "numpy.pxd":278
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L11;
  }
  /*else*/ {

    /* "numpy.pxd":280
 *                 return
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
    __pyx_v_info->format = ((char *)malloc(255));

    /* "numpy.pxd":281
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "numpy.pxd":282
 *                 info.format = <char*>stdlib.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_v_offset = 0;

    /* "numpy.pxd":285
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)             # <<<<<<<<<<<<<<
 *                 f[0] = c'\0' # Terminate format string
 * 
 */
    __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_f = __pyx_t_9;

    /* "numpy.pxd":286
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = '\x00';
  }
  __pyx_L11:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* "numpy.pxd":288
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "numpy.pxd":289
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = PyArray_HASFIELDS(__pyx_v_self);
  if (__pyx_t_1) {

    /* "numpy.pxd":290
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)
 */
    free(__pyx_v_info->format);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":291
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":292
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    free(__pyx_v_info->strides);
    goto __pyx_L4;
  }
  __pyx_L4:;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":768
 * 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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "numpy.pxd":769
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":771
 *     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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "numpy.pxd":772
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":774
 *     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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "numpy.pxd":775
 * 
 * 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_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_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":777
 *     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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "numpy.pxd":778
 * 
 * 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_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_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":780
 *     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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "numpy.pxd":781
 * 
 * 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 char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __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_filename = __pyx_f[1]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":783
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * 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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  long __pyx_t_11;
  char *__pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "numpy.pxd":790
 *     cdef int delta_offset
 *     cdef tuple i
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":791
 *     cdef tuple i
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = ((PyObject *)__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_COMPILING_IN_CPYTHON
    __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_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF(__pyx_v_childname);
    __pyx_v_childname = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "numpy.pxd":795
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __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 tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_fields));
    __pyx_v_fields = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "numpy.pxd":796
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 */
    if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) {
      PyObject* sequence = ((PyObject *)__pyx_v_fields);
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      __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_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else if (1) {
      __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else
    {
      Py_ssize_t index = -1;
      __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_fields)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = NULL;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L6_unpacking_done:;
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((PyArray_Descr *)__pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_v_new_offset);
    __pyx_v_new_offset = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "numpy.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_7) {

      /* "numpy.pxd":799
 * 
 *         if (end - f) - (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_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_177), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "numpy.pxd":801
 *             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_t_7 = (__pyx_v_child->byteorder == '>');
    if (__pyx_t_7) {
      __pyx_t_8 = __pyx_v_little_endian;
    } else {
      __pyx_t_8 = __pyx_t_7;
    }
    if (!__pyx_t_8) {

      /* "numpy.pxd":802
 * 
 *         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_t_7 = (__pyx_v_child->byteorder == '<');
      if (__pyx_t_7) {
        __pyx_t_9 = (!__pyx_v_little_endian);
        __pyx_t_10 = __pyx_t_9;
      } else {
        __pyx_t_10 = __pyx_t_7;
      }
      __pyx_t_7 = __pyx_t_10;
    } else {
      __pyx_t_7 = __pyx_t_8;
    }
    if (__pyx_t_7) {

      /* "numpy.pxd":803
 *         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_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_178), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "numpy.pxd":813
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_7) break;

      /* "numpy.pxd":814
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 120;

      /* "numpy.pxd":815
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "numpy.pxd":816
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_11 = 0;
      (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + 1);
    }

    /* "numpy.pxd":818
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_11 = 0;
    (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + __pyx_v_child->elsize);

    /* "numpy.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_7 = (!PyDataType_HASFIELDS(__pyx_v_child));
    if (__pyx_t_7) {

      /* "numpy.pxd":821
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_v_t);
      __pyx_v_t = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "numpy.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_7 = ((__pyx_v_end - __pyx_v_f) < 5);
      if (__pyx_t_7) {

        /* "numpy.pxd":823
 *             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_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_180), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "numpy.pxd":826
 * 
 *             # 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_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L13;
      }

      /* "numpy.pxd":827
 *             # 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_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L13;
      }

      /* "numpy.pxd":828
 *             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_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 104;
        goto __pyx_L13;
      }

      /* "numpy.pxd":829
 *             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_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L13;
      }

      /* "numpy.pxd":830
 *             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_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 105;
        goto __pyx_L13;
      }

      /* "numpy.pxd":831
 *             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_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L13;
      }

      /* "numpy.pxd":832
 *             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_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 108;
        goto __pyx_L13;
      }

      /* "numpy.pxd":833
 *             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_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L13;
      }

      /* "numpy.pxd":834
 *             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_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 113;
        goto __pyx_L13;
      }

      /* "numpy.pxd":835
 *             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_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L13;
      }

      /* "numpy.pxd":836
 *             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_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 102;
        goto __pyx_L13;
      }

      /* "numpy.pxd":837
 *             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_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 100;
        goto __pyx_L13;
      }

      /* "numpy.pxd":838
 *             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_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 103;
        goto __pyx_L13;
      }

      /* "numpy.pxd":839
 *             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_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 102;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":840
 *             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_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 100;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":841
 *             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_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 103;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":842
 *             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_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L13;
      }
      /*else*/ {

        /* "numpy.pxd":844
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_175), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_5));
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
        __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
        __Pyx_Raise(__pyx_t_5, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L13:;

      /* "numpy.pxd":845
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);
      goto __pyx_L11;
    }
    /*else*/ {

      /* "numpy.pxd":849
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
      __pyx_t_12 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_f = __pyx_t_12;
    }
    __pyx_L11:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "numpy.pxd":850
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __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_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":965
 * 
 * 
 * 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_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "numpy.pxd":967
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  if (__pyx_t_1) {

    /* "numpy.pxd":968
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":970
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
    Py_INCREF(__pyx_v_base);

    /* "numpy.pxd":971
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "numpy.pxd":972
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "numpy.pxd":973
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":975
 *      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_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "numpy.pxd":976
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = (__pyx_v_arr->base == NULL);
  if (__pyx_t_1) {

    /* "numpy.pxd":977
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":979
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    __Pyx_NAMESTR("lapack"),
    __Pyx_DOCSTR(__pyx_k_181), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 0},
  {&__pyx_kp_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 0},
  {&__pyx_kp_s_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 0, 1, 0},
  {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0},
  {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0},
  {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0},
  {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0},
  {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0},
  {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0},
  {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_133, __pyx_k_133, sizeof(__pyx_k_133), 0, 0, 1, 0},
  {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0},
  {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0},
  {&__pyx_kp_s_142, __pyx_k_142, sizeof(__pyx_k_142), 0, 0, 1, 0},
  {&__pyx_kp_s_145, __pyx_k_145, sizeof(__pyx_k_145), 0, 0, 1, 0},
  {&__pyx_kp_s_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 0, 1, 0},
  {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_s_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 0, 1, 0},
  {&__pyx_kp_s_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 0, 1, 0},
  {&__pyx_kp_s_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 0, 1, 0},
  {&__pyx_kp_s_157, __pyx_k_157, sizeof(__pyx_k_157), 0, 0, 1, 0},
  {&__pyx_kp_s_158, __pyx_k_158, sizeof(__pyx_k_158), 0, 0, 1, 0},
  {&__pyx_kp_s_161, __pyx_k_161, sizeof(__pyx_k_161), 0, 0, 1, 0},
  {&__pyx_kp_s_162, __pyx_k_162, sizeof(__pyx_k_162), 0, 0, 1, 0},
  {&__pyx_kp_s_163, __pyx_k_163, sizeof(__pyx_k_163), 0, 0, 1, 0},
  {&__pyx_kp_s_165, __pyx_k_165, sizeof(__pyx_k_165), 0, 0, 1, 0},
  {&__pyx_kp_s_167, __pyx_k_167, sizeof(__pyx_k_167), 0, 0, 1, 0},
  {&__pyx_kp_u_169, __pyx_k_169, sizeof(__pyx_k_169), 0, 1, 0, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
  {&__pyx_kp_u_171, __pyx_k_171, sizeof(__pyx_k_171), 0, 1, 0, 0},
  {&__pyx_kp_u_173, __pyx_k_173, sizeof(__pyx_k_173), 0, 1, 0, 0},
  {&__pyx_kp_u_175, __pyx_k_175, sizeof(__pyx_k_175), 0, 1, 0, 0},
  {&__pyx_kp_u_176, __pyx_k_176, sizeof(__pyx_k_176), 0, 1, 0, 0},
  {&__pyx_kp_u_179, __pyx_k_179, sizeof(__pyx_k_179), 0, 1, 0, 0},
  {&__pyx_n_s_182, __pyx_k_182, sizeof(__pyx_k_182), 0, 0, 1, 1},
  {&__pyx_kp_s_185, __pyx_k_185, sizeof(__pyx_k_185), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
  {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
  {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
  {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
  {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
  {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0},
  {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0},
  {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0},
  {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0},
  {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0},
  {&__pyx_kp_s_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 1, 0},
  {&__pyx_kp_s_75, __pyx_k_75, sizeof(__pyx_k_75), 0, 0, 1, 0},
  {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0},
  {&__pyx_kp_s_79, __pyx_k_79, sizeof(__pyx_k_79), 0, 0, 1, 0},
  {&__pyx_kp_s_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 0, 1, 0},
  {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0},
  {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0},
  {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__A, __pyx_k__A, sizeof(__pyx_k__A), 0, 0, 1, 1},
  {&__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_s__C_CONTIGUOUS, __pyx_k__C_CONTIGUOUS, sizeof(__pyx_k__C_CONTIGUOUS), 0, 0, 1, 1},
  {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1},
  {&__pyx_n_s__F_CONTIGUOUS, __pyx_k__F_CONTIGUOUS, sizeof(__pyx_k__F_CONTIGUOUS), 0, 0, 1, 1},
  {&__pyx_n_s__IPIV, __pyx_k__IPIV, sizeof(__pyx_k__IPIV), 0, 0, 1, 1},
  {&__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_n_s__Q, __pyx_k__Q, sizeof(__pyx_k__Q), 0, 0, 1, 1},
  {&__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_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____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
  {&__pyx_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1},
  {&__pyx_n_s____import__, __pyx_k____import__, sizeof(__pyx_k____import__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 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_n_s____pyx_getbuffer, __pyx_k____pyx_getbuffer, sizeof(__pyx_k____pyx_getbuffer), 0, 0, 1, 1},
  {&__pyx_n_s____pyx_releasebuffer, __pyx_k____pyx_releasebuffer, sizeof(__pyx_k____pyx_releasebuffer), 0, 0, 1, 1},
  {&__pyx_n_s____qualname__, __pyx_k____qualname__, sizeof(__pyx_k____qualname__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 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_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 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_s__cgees, __pyx_k__cgees, sizeof(__pyx_k__cgees), 0, 0, 1, 1},
  {&__pyx_n_s__cgetrf, __pyx_k__cgetrf, sizeof(__pyx_k__cgetrf), 0, 0, 1, 1},
  {&__pyx_n_s__cgetrs, __pyx_k__cgetrs, sizeof(__pyx_k__cgetrs), 0, 0, 1, 1},
  {&__pyx_n_s__cgges, __pyx_k__cgges, sizeof(__pyx_k__cgges), 0, 0, 1, 1},
  {&__pyx_n_s__cggev, __pyx_k__cggev, sizeof(__pyx_k__cggev), 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_s__ctgsen, __pyx_k__ctgsen, sizeof(__pyx_k__ctgsen), 0, 0, 1, 1},
  {&__pyx_n_s__ctrevc, __pyx_k__ctrevc, sizeof(__pyx_k__ctrevc), 0, 0, 1, 1},
  {&__pyx_n_s__ctrsen, __pyx_k__ctrsen, sizeof(__pyx_k__ctrsen), 0, 0, 1, 1},
  {&__pyx_n_s__d, __pyx_k__d, sizeof(__pyx_k__d), 0, 0, 1, 1},
  {&__pyx_n_s__dgecon, __pyx_k__dgecon, sizeof(__pyx_k__dgecon), 0, 0, 1, 1},
  {&__pyx_n_s__dgees, __pyx_k__dgees, sizeof(__pyx_k__dgees), 0, 0, 1, 1},
  {&__pyx_n_s__dgetrf, __pyx_k__dgetrf, sizeof(__pyx_k__dgetrf), 0, 0, 1, 1},
  {&__pyx_n_s__dgetrs, __pyx_k__dgetrs, sizeof(__pyx_k__dgetrs), 0, 0, 1, 1},
  {&__pyx_n_s__dgges, __pyx_k__dgges, sizeof(__pyx_k__dgges), 0, 0, 1, 1},
  {&__pyx_n_s__dggev, __pyx_k__dggev, sizeof(__pyx_k__dggev), 0, 0, 1, 1},
  {&__pyx_n_s__diagonal, __pyx_k__diagonal, sizeof(__pyx_k__diagonal), 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_s__dtgsen, __pyx_k__dtgsen, sizeof(__pyx_k__dtgsen), 0, 0, 1, 1},
  {&__pyx_n_s__dtrevc, __pyx_k__dtrevc, sizeof(__pyx_k__dtrevc), 0, 0, 1, 1},
  {&__pyx_n_s__dtrsen, __pyx_k__dtrsen, sizeof(__pyx_k__dtrsen), 0, 0, 1, 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__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__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__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__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_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_for_lapack, __pyx_k__prepare_for_lapack, sizeof(__pyx_k__prepare_for_lapack), 0, 0, 1, 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__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_s__s, __pyx_k__s, sizeof(__pyx_k__s), 0, 0, 1, 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_s__sgees, __pyx_k__sgees, sizeof(__pyx_k__sgees), 0, 0, 1, 1},
  {&__pyx_n_s__sgetrf, __pyx_k__sgetrf, sizeof(__pyx_k__sgetrf), 0, 0, 1, 1},
  {&__pyx_n_s__sgetrs, __pyx_k__sgetrs, sizeof(__pyx_k__sgetrs), 0, 0, 1, 1},
  {&__pyx_n_s__sgges, __pyx_k__sgges, sizeof(__pyx_k__sgges), 0, 0, 1, 1},
  {&__pyx_n_s__sggev, __pyx_k__sggev, sizeof(__pyx_k__sggev), 0, 0, 1, 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_s__stgsen, __pyx_k__stgsen, sizeof(__pyx_k__stgsen), 0, 0, 1, 1},
  {&__pyx_n_s__strevc, __pyx_k__strevc, sizeof(__pyx_k__strevc), 0, 0, 1, 1},
  {&__pyx_n_s__strsen, __pyx_k__strsen, sizeof(__pyx_k__strsen), 0, 0, 1, 1},
  {&__pyx_n_s__txevc_postprocess, __pyx_k__txevc_postprocess, sizeof(__pyx_k__txevc_postprocess), 0, 0, 1, 1},
  {&__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_s__xrange, __pyx_k__xrange, sizeof(__pyx_k__xrange), 0, 0, 1, 1},
  {&__pyx_n_s__z, __pyx_k__z, sizeof(__pyx_k__z), 0, 0, 1, 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_s__zgees, __pyx_k__zgees, sizeof(__pyx_k__zgees), 0, 0, 1, 1},
  {&__pyx_n_s__zgetrf, __pyx_k__zgetrf, sizeof(__pyx_k__zgetrf), 0, 0, 1, 1},
  {&__pyx_n_s__zgetrs, __pyx_k__zgetrs, sizeof(__pyx_k__zgetrs), 0, 0, 1, 1},
  {&__pyx_n_s__zgges, __pyx_k__zgges, sizeof(__pyx_k__zgges), 0, 0, 1, 1},
  {&__pyx_n_s__zggev, __pyx_k__zggev, sizeof(__pyx_k__zggev), 0, 0, 1, 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_s__ztgsen, __pyx_k__ztgsen, sizeof(__pyx_k__ztgsen), 0, 0, 1, 1},
  {&__pyx_n_s__ztrevc, __pyx_k__ztrevc, sizeof(__pyx_k__ztrevc), 0, 0, 1, 1},
  {&__pyx_n_s__ztrsen, __pyx_k__ztrsen, sizeof(__pyx_k__ztrsen), 0, 0, 1, 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_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION >= 3
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #else
  __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s__AssertionError); if (!__pyx_builtin_AssertionError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __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_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_1)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_2);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));

  /* "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_k_tuple_8 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_8);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));

  /* "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_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_9)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_10);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_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_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_12);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_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_k_tuple_14 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_13)); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_14);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));

  /* "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_k_tuple_16 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_16);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16));

  /* "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_k_tuple_18 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_17)); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_18);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18));

  /* "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_k_tuple_20 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_7)); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_20);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20));

  /* "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_k_tuple_22 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_21)); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_22);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));

  /* "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_k_slice_28 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_28);
  __Pyx_GIVEREF(__pyx_k_slice_28);
  __pyx_k_slice_29 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_29);
  __Pyx_GIVEREF(__pyx_k_slice_29);

  /* "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_k_slice_30 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_30);
  __Pyx_GIVEREF(__pyx_k_slice_30);
  __pyx_k_slice_31 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_31);
  __Pyx_GIVEREF(__pyx_k_slice_31);

  /* "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_k_slice_32 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_32);
  __Pyx_GIVEREF(__pyx_k_slice_32);
  __pyx_k_slice_33 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_33);
  __Pyx_GIVEREF(__pyx_k_slice_33);

  /* "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_k_slice_34 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_34);
  __Pyx_GIVEREF(__pyx_k_slice_34);
  __pyx_k_slice_35 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_35);
  __Pyx_GIVEREF(__pyx_k_slice_35);

  /* "kwant/linalg/lapack.pyx":424
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sggev"
 */
  __pyx_k_tuple_40 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_39)); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_40);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));

  /* "kwant/linalg/lapack.pyx":491
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dggev"
 */
  __pyx_k_tuple_45 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_44)); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_45);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));

  /* "kwant/linalg/lapack.pyx":536
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex64)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.cggev_(jobvl, jobvr, &N, <float complex *>A.data, &N,
 */
  __pyx_k_tuple_48 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_48);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48));

  /* "kwant/linalg/lapack.pyx":560
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cggev"
 */
  __pyx_k_tuple_51 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_50)); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_51);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51));

  /* "kwant/linalg/lapack.pyx":603
 *     # workspace query
 *     lwork = -1
 *     work = np.empty(1, dtype = np.complex128)             # <<<<<<<<<<<<<<
 * 
 *     f_lapack.zggev_(jobvl, jobvr, &N, <double complex *>A.data, &N,
 */
  __pyx_k_tuple_54 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_54);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54));

  /* "kwant/linalg/lapack.pyx":626
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zggev")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zggev"
 */
  __pyx_k_tuple_57 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_57);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57));

  /* "kwant/linalg/lapack.pyx":673
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in sgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in sgees"
 */
  __pyx_k_tuple_62 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_61)); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_62);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62));

  /* "kwant/linalg/lapack.pyx":724
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in dgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dgees"
 */
  __pyx_k_tuple_67 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_66)); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_67);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));

  /* "kwant/linalg/lapack.pyx":777
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in cgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in cgees"
 */
  __pyx_k_tuple_72 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_71)); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_72);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_72));

  /* "kwant/linalg/lapack.pyx":825
 * 
 *     if info > 0:
 *         raise LinAlgError("QR iteration failed to converge in zgees")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_k_tuple_77 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_76)); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_77);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77));

  /* "kwant/linalg/lapack.pyx":877
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in strsen"
 */
  __pyx_k_tuple_81 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_81);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_81));

  /* "kwant/linalg/lapack.pyx":934
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtrsen"
 */
  __pyx_k_tuple_84 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_84);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_84));

  /* "kwant/linalg/lapack.pyx":986
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctrsen"
 */
  __pyx_k_tuple_87 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_87);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_87));

  /* "kwant/linalg/lapack.pyx":1033
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztrsen"
 */
  __pyx_k_tuple_90 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_90);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_90));

  /* "kwant/linalg/lapack.pyx":1059
 *             # 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_k_slice_91 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_91);
  __Pyx_GIVEREF(__pyx_k_slice_91);
  __pyx_k_slice_92 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_92);
  __Pyx_GIVEREF(__pyx_k_slice_92);
  __pyx_k_slice_93 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_93)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_93);
  __Pyx_GIVEREF(__pyx_k_slice_93);

  /* "kwant/linalg/lapack.pyx":1068
 *             # 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_k_slice_94 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_94);
  __Pyx_GIVEREF(__pyx_k_slice_94);
  __pyx_k_slice_95 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_95);
  __Pyx_GIVEREF(__pyx_k_slice_95);
  __pyx_k_slice_96 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_96);
  __Pyx_GIVEREF(__pyx_k_slice_96);

  /* "kwant/linalg/lapack.pyx":1073
 *         else:
 *             # real eigenvalue
 *             v[:, m] = vreal[:, indx]             # <<<<<<<<<<<<<<
 * 
 *             indx += 1
 */
  __pyx_k_slice_97 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_97);
  __Pyx_GIVEREF(__pyx_k_slice_97);
  __pyx_k_slice_98 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_k_slice_98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_slice_98);
  __Pyx_GIVEREF(__pyx_k_slice_98);

  /* "kwant/linalg/lapack.pyx":1501
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in sgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_k_tuple_119 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_118)); if (unlikely(!__pyx_k_tuple_119)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_119);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_119));

  /* "kwant/linalg/lapack.pyx":1573
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in dgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_k_tuple_124 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_123)); if (unlikely(!__pyx_k_tuple_124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_124);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_124));

  /* "kwant/linalg/lapack.pyx":1645
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in cgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_k_tuple_129 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_128)); if (unlikely(!__pyx_k_tuple_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_129);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_129));

  /* "kwant/linalg/lapack.pyx":1712
 * 
 *     if info > 0:
 *         raise LinAlgError("QZ iteration failed to converge in zgges")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in zgees"
 */
  __pyx_k_tuple_134 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_133)); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_134);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));

  /* "kwant/linalg/lapack.pyx":1784
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in stgsen"
 */
  __pyx_k_tuple_137 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_137);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137));

  /* "kwant/linalg/lapack.pyx":1861
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in dtgsen"
 */
  __pyx_k_tuple_140 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_140)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_140);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_140));

  /* "kwant/linalg/lapack.pyx":1935
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ctgsen"
 */
  __pyx_k_tuple_143 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_143);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_143));

  /* "kwant/linalg/lapack.pyx":2004
 * 
 *     if info > 0:
 *         raise LinAlgError("Reordering failed; problem is very ill-conditioned")             # <<<<<<<<<<<<<<
 * 
 *     assert info == 0, "Argument error in ztgsen"
 */
  __pyx_k_tuple_146 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_80)); if (unlikely(!__pyx_k_tuple_146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_146);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_146));

  /* "kwant/linalg/lapack.pyx":2437
 *             arr = np.asanyarray(args[i])
 *             if not np.issubdtype(arr.dtype, np.number):
 *                 raise ValueError("Argument cannot be interpreted "             # <<<<<<<<<<<<<<
 *                                  "as a numeric array")
 * 
 */
  __pyx_k_tuple_164 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_163)); if (unlikely(!__pyx_k_tuple_164)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_164);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_164));

  /* "kwant/linalg/lapack.pyx":2458
 *         lapacktype = 'z'
 *     else:
 *         raise AssertionError("Unexpected data type from common_type")             # <<<<<<<<<<<<<<
 * 
 *     ret = [ lapacktype ]
 */
  __pyx_k_tuple_166 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_165)); if (unlikely(!__pyx_k_tuple_166)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_166);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_166));

  /* "kwant/linalg/lapack.pyx":2481
 *                     npmat = np.asfortranarray(npmat.copy())
 *             else:
 *                 raise ValueError("Dimensionality of array is not 1 or 2")             # <<<<<<<<<<<<<<
 * 
 *         ret.append(npmat)
 */
  __pyx_k_tuple_168 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_s_167)); if (unlikely(!__pyx_k_tuple_168)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_168);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_168));

  /* "numpy.pxd":215
 *             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_k_tuple_170 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_169)); if (unlikely(!__pyx_k_tuple_170)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_170);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_170));

  /* "numpy.pxd":219
 *             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_k_tuple_172 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_171)); if (unlikely(!__pyx_k_tuple_172)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_172);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_172));

  /* "numpy.pxd":257
 *                 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_k_tuple_174 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_173)); if (unlikely(!__pyx_k_tuple_174)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_174);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_174));

  /* "numpy.pxd":799
 * 
 *         if (end - f) - (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_k_tuple_177 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_176)); if (unlikely(!__pyx_k_tuple_177)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_177);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_177));

  /* "numpy.pxd":803
 *         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_k_tuple_178 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_173)); if (unlikely(!__pyx_k_tuple_178)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_178);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_178));

  /* "numpy.pxd":823
 *             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_k_tuple_180 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_179)); if (unlikely(!__pyx_k_tuple_180)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_180);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_180));

  /* "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_k_tuple_183 = PyTuple_Pack(4, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__sel), ((PyObject *)__pyx_n_s__arg)); if (unlikely(!__pyx_k_tuple_183)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_183);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_183));
  __pyx_k_codeobj_184 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_183, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__filter_args, 42, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_184)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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_k_tuple_186 = PyTuple_Pack(3, ((PyObject *)__pyx_n_s__mats), ((PyObject *)__pyx_n_s__mats), ((PyObject *)__pyx_n_s__mat)); if (unlikely(!__pyx_k_tuple_186)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_186);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_186));
  __pyx_k_codeobj_187 = (PyObject*)__Pyx_PyCode_New(0, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_186, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__assert_fortran_mat, 45, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_187)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __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_k_tuple_188 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ipiv)); if (unlikely(!__pyx_k_tuple_188)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_188);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_188));
  __pyx_k_codeobj_189 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_188, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sgetrf, 55, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_189)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __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_k_tuple_190 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ipiv)); if (unlikely(!__pyx_k_tuple_190)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_190);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_190));
  __pyx_k_codeobj_191 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_190, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dgetrf, 72, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_191)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __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_k_tuple_192 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ipiv)); if (unlikely(!__pyx_k_tuple_192)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_192);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_192));
  __pyx_k_codeobj_193 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_192, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cgetrf, 89, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_193)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __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_k_tuple_194 = PyTuple_Pack(5, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ipiv)); if (unlikely(!__pyx_k_tuple_194)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_194);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_194));
  __pyx_k_codeobj_195 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_194, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zgetrf, 106, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_195)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __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_k_tuple_196 = PyTuple_Pack(7, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__IPIV), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__NRHS), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__b)); if (unlikely(!__pyx_k_tuple_196)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_196);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_196));
  __pyx_k_codeobj_197 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_196, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sgetrs, 125, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_197)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __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_k_tuple_198 = PyTuple_Pack(7, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__IPIV), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__NRHS), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__b)); if (unlikely(!__pyx_k_tuple_198)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_198);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_198));
  __pyx_k_codeobj_199 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_198, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dgetrs, 155, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_199)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __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_k_tuple_200 = PyTuple_Pack(7, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__IPIV), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__NRHS), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__b)); if (unlikely(!__pyx_k_tuple_200)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_200);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_200));
  __pyx_k_codeobj_201 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_200, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cgetrs, 185, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_201)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __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_k_tuple_202 = PyTuple_Pack(7, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__IPIV), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__NRHS), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__b)); if (unlikely(!__pyx_k_tuple_202)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_202);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_202));
  __pyx_k_codeobj_203 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_202, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zgetrs, 215, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_203)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __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 = "1"):
 *     cdef l_int N, info
 */
  __pyx_k_tuple_204 = PyTuple_Pack(8, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__normA), ((PyObject *)__pyx_n_s__norm), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__rcond), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork)); if (unlikely(!__pyx_k_tuple_204)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_204);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_204));
  __pyx_k_codeobj_205 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_204, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sgecon, 247, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_205)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_k_tuple_206 = PyTuple_Pack(8, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__normA), ((PyObject *)__pyx_n_s__norm), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__rcond), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork)); if (unlikely(!__pyx_k_tuple_206)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_206);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_206));
  __pyx_k_codeobj_207 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_206, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dgecon, 268, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_207)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_k_tuple_208 = PyTuple_Pack(8, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__normA), ((PyObject *)__pyx_n_s__norm), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__rcond), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_208)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_208);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_208));
  __pyx_k_codeobj_209 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_208, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cgecon, 289, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_209)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_k_tuple_210 = PyTuple_Pack(8, ((PyObject *)__pyx_n_s__LU), ((PyObject *)__pyx_n_s__normA), ((PyObject *)__pyx_n_s__norm), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__rcond), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_210)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_210);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_210));
  __pyx_k_codeobj_211 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_210, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zgecon, 310, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_211)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __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_k_tuple_212 = PyTuple_Pack(10, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__indx), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_212)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_212);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_212));
  __pyx_k_codeobj_213 = (PyObject*)__Pyx_PyCode_New(5, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_212, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ggev_postprocess, 334, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_213)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __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_k_tuple_214 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__jobvl), ((PyObject *)__pyx_n_s__jobvr), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_214)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_214);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_214));
  __pyx_k_codeobj_215 = (PyObject*)__Pyx_PyCode_New(4, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_214, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sggev, 366, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_215)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":433
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_k_tuple_216 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__jobvl), ((PyObject *)__pyx_n_s__jobvr), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_216)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_216);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_216));
  __pyx_k_codeobj_217 = (PyObject*)__Pyx_PyCode_New(4, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_216, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dggev, 433, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_217)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":500
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_k_tuple_218 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__jobvl), ((PyObject *)__pyx_n_s__jobvr), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_218)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_218);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_218));
  __pyx_k_codeobj_219 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_218, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cggev, 500, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_219)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":567
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_k_tuple_220 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__jobvl), ((PyObject *)__pyx_n_s__jobvr), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_220)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_220);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_220));
  __pyx_k_codeobj_221 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_220, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zggev, 567, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_221)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":634
 * 
 * # 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_k_tuple_222 = PyTuple_Pack(15, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvs), ((PyObject *)__pyx_n_s__vs_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vs), ((PyObject *)__pyx_n_s__wr), ((PyObject *)__pyx_n_s__wi), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__w)); if (unlikely(!__pyx_k_tuple_222)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_222);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_222));
  __pyx_k_codeobj_223 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_222, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sgees, 634, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_223)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":685
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_k_tuple_224 = PyTuple_Pack(15, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvs), ((PyObject *)__pyx_n_s__vs_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vs), ((PyObject *)__pyx_n_s__wr), ((PyObject *)__pyx_n_s__wi), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__w)); if (unlikely(!__pyx_k_tuple_224)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_224);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_224));
  __pyx_k_codeobj_225 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_224, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dgees, 685, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_225)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":736
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_k_tuple_226 = PyTuple_Pack(14, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvs), ((PyObject *)__pyx_n_s__vs_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vs), ((PyObject *)__pyx_n_s__w), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_226)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_226);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_226));
  __pyx_k_codeobj_227 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_226, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cgees, 736, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_227)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":784
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_k_tuple_228 = PyTuple_Pack(14, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvs), ((PyObject *)__pyx_n_s__vs_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vs), ((PyObject *)__pyx_n_s__w), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_228)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_228);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_228));
  __pyx_k_codeobj_229 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_228, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zgees, 784, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_229)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":832
 * 
 * # 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_k_tuple_230 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__compq), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__wr), ((PyObject *)__pyx_n_s__wi), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork), ((PyObject *)__pyx_n_s__w)); if (unlikely(!__pyx_k_tuple_230)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_230);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_230));
  __pyx_k_codeobj_231 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_230, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__strsen, 832, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_231)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":889
 * 
 * 
 * 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_k_tuple_232 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__compq), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__wr), ((PyObject *)__pyx_n_s__wi), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork), ((PyObject *)__pyx_n_s__w)); if (unlikely(!__pyx_k_tuple_232)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_232);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_232));
  __pyx_k_codeobj_233 = (PyObject*)__Pyx_PyCode_New(4, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_232, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dtrsen, 889, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_233)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":946
 * 
 * 
 * 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_k_tuple_234 = PyTuple_Pack(13, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__compq), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__w), ((PyObject *)__pyx_n_s__work)); if (unlikely(!__pyx_k_tuple_234)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_234);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_234));
  __pyx_k_codeobj_235 = (PyObject*)__Pyx_PyCode_New(4, 0, 13, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_234, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ctrsen, 946, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_235)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":993
 * 
 * 
 * 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_k_tuple_236 = PyTuple_Pack(14, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__compq), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__w), ((PyObject *)__pyx_n_s__work)); if (unlikely(!__pyx_k_tuple_236)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_236);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_236));
  __pyx_k_codeobj_237 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_236, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ztrsen, 993, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_237)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1041
 * 
 * # 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_k_tuple_238 = PyTuple_Pack(12, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__vreal), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__m), ((PyObject *)__pyx_n_s__indx), ((PyObject *)__pyx_n_s__selindx), ((PyObject *)__pyx_n_s__v), ((PyObject *)__pyx_n_s__k)); if (unlikely(!__pyx_k_tuple_238)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_238);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_238));
  __pyx_k_codeobj_239 = (PyObject*)__Pyx_PyCode_New(4, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_238, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__txevc_postprocess, 1041, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_239)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1080
 * 
 * # 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_k_tuple_240 = PyTuple_Pack(22, ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_r_ptr), ((PyObject *)__pyx_n_s__vr_r_ptr), ((PyObject *)__pyx_n_s__select_cpy), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__cmplxindx), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_240)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_240);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_240));
  __pyx_k_codeobj_241 = (PyObject*)__Pyx_PyCode_New(5, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_240, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__strevc, 1080, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_241)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1182
 * 
 * 
 * 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_k_tuple_242 = PyTuple_Pack(22, ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_r_ptr), ((PyObject *)__pyx_n_s__vr_r_ptr), ((PyObject *)__pyx_n_s__select_cpy), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__cmplxindx), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_242)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_242);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_242));
  __pyx_k_codeobj_243 = (PyObject*)__Pyx_PyCode_New(5, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_242, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dtrevc, 1182, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_243)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1283
 * 
 * 
 * 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_k_tuple_244 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_244)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_244);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_244));
  __pyx_k_codeobj_245 = (PyObject*)__Pyx_PyCode_New(5, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_244, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ctrevc, 1283, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_245)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1362
 * 
 * 
 * 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_k_tuple_246 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_246)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_246);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_246));
  __pyx_k_codeobj_247 = (PyObject*)__Pyx_PyCode_New(5, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_246, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ztrevc, 1362, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_247)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1442
 * 
 * # 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_k_tuple_248 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvsl), ((PyObject *)__pyx_n_s__jobvsr), ((PyObject *)__pyx_n_s__vsl_ptr), ((PyObject *)__pyx_n_s__vsr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vsl), ((PyObject *)__pyx_n_s__vsr), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alpha)); if (unlikely(!__pyx_k_tuple_248)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_248);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_248));
  __pyx_k_codeobj_249 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_248, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__sgges, 1442, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_249)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1514
 * 
 * 
 * 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_k_tuple_250 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvsl), ((PyObject *)__pyx_n_s__jobvsr), ((PyObject *)__pyx_n_s__vsl_ptr), ((PyObject *)__pyx_n_s__vsr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vsl), ((PyObject *)__pyx_n_s__vsr), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__alpha)); if (unlikely(!__pyx_k_tuple_250)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_250);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_250));
  __pyx_k_codeobj_251 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_250, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dgges, 1514, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_251)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1586
 * 
 * 
 * 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_k_tuple_252 = PyTuple_Pack(20, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvsl), ((PyObject *)__pyx_n_s__jobvsr), ((PyObject *)__pyx_n_s__vsl_ptr), ((PyObject *)__pyx_n_s__vsr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vsl), ((PyObject *)__pyx_n_s__vsr), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_252)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_252);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_252));
  __pyx_k_codeobj_253 = (PyObject*)__Pyx_PyCode_New(5, 0, 20, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_252, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__cgges, 1586, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_253)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1653
 * 
 * 
 * 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_k_tuple_254 = PyTuple_Pack(20, ((PyObject *)__pyx_n_s__A), ((PyObject *)__pyx_n_s__B), ((PyObject *)__pyx_n_s__calc_q), ((PyObject *)__pyx_n_s__calc_z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__sdim), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__jobvsl), ((PyObject *)__pyx_n_s__jobvsr), ((PyObject *)__pyx_n_s__vsl_ptr), ((PyObject *)__pyx_n_s__vsr_ptr), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__vsl), ((PyObject *)__pyx_n_s__vsr), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork)); if (unlikely(!__pyx_k_tuple_254)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_254);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_254));
  __pyx_k_codeobj_255 = (PyObject*)__Pyx_PyCode_New(5, 0, 20, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_254, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__zgges, 1653, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_255)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1721
 * 
 * # 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_k_tuple_256 = PyTuple_Pack(24, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ijob), ((PyObject *)__pyx_n_s__wantq), ((PyObject *)__pyx_n_s__wantz), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__z_ptr), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork), ((PyObject *)__pyx_n_s__alpha)); if (unlikely(!__pyx_k_tuple_256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_256);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_256));
  __pyx_k_codeobj_257 = (PyObject*)__Pyx_PyCode_New(6, 0, 24, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_256, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__stgsen, 1721, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_257)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1798
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */
  __pyx_k_tuple_258 = PyTuple_Pack(24, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ijob), ((PyObject *)__pyx_n_s__wantq), ((PyObject *)__pyx_n_s__wantz), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__z_ptr), ((PyObject *)__pyx_n_s__alphar), ((PyObject *)__pyx_n_s__alphai), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork), ((PyObject *)__pyx_n_s__alpha)); if (unlikely(!__pyx_k_tuple_258)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_258);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_258));
  __pyx_k_codeobj_259 = (PyObject*)__Pyx_PyCode_New(6, 0, 24, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_258, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dtgsen, 1798, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_259)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1875
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */
  __pyx_k_tuple_260 = PyTuple_Pack(22, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ijob), ((PyObject *)__pyx_n_s__wantq), ((PyObject *)__pyx_n_s__wantz), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__z_ptr), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork)); if (unlikely(!__pyx_k_tuple_260)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_260);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_260));
  __pyx_k_codeobj_261 = (PyObject*)__Pyx_PyCode_New(6, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_260, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ctgsen, 1875, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_261)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":1944
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */
  __pyx_k_tuple_262 = PyTuple_Pack(22, ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__calc_ev), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__lwork), ((PyObject *)__pyx_n_s__liwork), ((PyObject *)__pyx_n_s__qiwork), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__ijob), ((PyObject *)__pyx_n_s__wantq), ((PyObject *)__pyx_n_s__wantz), ((PyObject *)__pyx_n_s__qwork), ((PyObject *)__pyx_n_s__q_ptr), ((PyObject *)__pyx_n_s__z_ptr), ((PyObject *)__pyx_n_s__alpha), ((PyObject *)__pyx_n_s__beta), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__iwork)); if (unlikely(!__pyx_k_tuple_262)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_262);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_262));
  __pyx_k_codeobj_263 = (PyObject*)__Pyx_PyCode_New(6, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_262, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ztgsen, 1944, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_263)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":2014
 * 
 * # 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_k_tuple_264 = PyTuple_Pack(25, ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_r_ptr), ((PyObject *)__pyx_n_s__vr_r_ptr), ((PyObject *)__pyx_n_s__select_cpy), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__backtr), ((PyObject *)__pyx_n_s__cmplxindx), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_264)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_264);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_264));
  __pyx_k_codeobj_265 = (PyObject*)__Pyx_PyCode_New(7, 0, 25, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_264, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__stgevc, 2014, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_265)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":2123
 * 
 * 
 * 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_k_tuple_266 = PyTuple_Pack(25, ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl_r), ((PyObject *)__pyx_n_s__vr_r), ((PyObject *)__pyx_n_s__vl_r_ptr), ((PyObject *)__pyx_n_s__vr_r_ptr), ((PyObject *)__pyx_n_s__select_cpy), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__backtr), ((PyObject *)__pyx_n_s__cmplxindx), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr)); if (unlikely(!__pyx_k_tuple_266)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_266);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_266));
  __pyx_k_codeobj_267 = (PyObject*)__Pyx_PyCode_New(7, 0, 25, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_266, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__dtgevc, 2123, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_267)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":2233
 * 
 * 
 * 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_k_tuple_268 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork), ((PyObject *)__pyx_n_s__backtr)); if (unlikely(!__pyx_k_tuple_268)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_268);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_268));
  __pyx_k_codeobj_269 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_268, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ctgevc, 2233, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_269)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":2320
 * 
 * 
 * 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_k_tuple_270 = PyTuple_Pack(21, ((PyObject *)__pyx_n_s__S), ((PyObject *)__pyx_n_s__T), ((PyObject *)__pyx_n_s__Q), ((PyObject *)__pyx_n_s__Z), ((PyObject *)__pyx_n_s__select), ((PyObject *)__pyx_n_s__left), ((PyObject *)__pyx_n_s__right), ((PyObject *)__pyx_n_s__N), ((PyObject *)__pyx_n_s__info), ((PyObject *)__pyx_n_s__M), ((PyObject *)__pyx_n_s__MM), ((PyObject *)__pyx_n_s__side), ((PyObject *)__pyx_n_s__howmny), ((PyObject *)__pyx_n_s__vl), ((PyObject *)__pyx_n_s__vr), ((PyObject *)__pyx_n_s__vl_ptr), ((PyObject *)__pyx_n_s__vr_ptr), ((PyObject *)__pyx_n_s__select_ptr), ((PyObject *)__pyx_n_s__work), ((PyObject *)__pyx_n_s__rwork), ((PyObject *)__pyx_n_s__backtr)); if (unlikely(!__pyx_k_tuple_270)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_270);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_270));
  __pyx_k_codeobj_271 = (PyObject*)__Pyx_PyCode_New(7, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_270, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__ztgevc, 2320, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_271)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "kwant/linalg/lapack.pyx":2407
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */
  __pyx_k_tuple_272 = PyTuple_Pack(11, ((PyObject *)__pyx_n_s__overwrite), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__args), ((PyObject *)__pyx_n_s__mats), ((PyObject *)__pyx_n_s__i), ((PyObject *)__pyx_n_s__arr), ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__lapacktype), ((PyObject *)__pyx_n_s__ret), ((PyObject *)__pyx_n_s__npmat), ((PyObject *)__pyx_n_s__ovwrt)); if (unlikely(!__pyx_k_tuple_272)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_272);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_272));
  __pyx_k_codeobj_273 = (PyObject*)__Pyx_PyCode_New(1, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_272, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_185, __pyx_n_s__prepare_for_lapack, 2407, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_273)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initlapack(void); /*proto*/
PyMODINIT_FUNC initlapack(void)
#else
PyMODINIT_FUNC PyInit_lapack(void); /*proto*/
PyMODINIT_FUNC PyInit_lapack(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #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("PyMODINIT_FUNC PyInit_lapack(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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 PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("lapack"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_181), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "kwant.linalg.lapack")) {
      if (unlikely(PyDict_SetItemString(modules, "kwant.linalg.lapack", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_kwant__linalg__lapack) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "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_t_1 = PyList_New(41); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sgetrf));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__sgetrf));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sgetrf));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dgetrf));
  PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__dgetrf));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dgetrf));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgetrf));
  PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__cgetrf));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgetrf));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zgetrf));
  PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__zgetrf));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zgetrf));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sgetrs));
  PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__sgetrs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sgetrs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dgetrs));
  PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__dgetrs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dgetrs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgetrs));
  PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__cgetrs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgetrs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zgetrs));
  PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__zgetrs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zgetrs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sgecon));
  PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__sgecon));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sgecon));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dgecon));
  PyList_SET_ITEM(__pyx_t_1, 9, ((PyObject *)__pyx_n_s__dgecon));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dgecon));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgecon));
  PyList_SET_ITEM(__pyx_t_1, 10, ((PyObject *)__pyx_n_s__cgecon));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgecon));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zgecon));
  PyList_SET_ITEM(__pyx_t_1, 11, ((PyObject *)__pyx_n_s__zgecon));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zgecon));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sggev));
  PyList_SET_ITEM(__pyx_t_1, 12, ((PyObject *)__pyx_n_s__sggev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sggev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dggev));
  PyList_SET_ITEM(__pyx_t_1, 13, ((PyObject *)__pyx_n_s__dggev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dggev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cggev));
  PyList_SET_ITEM(__pyx_t_1, 14, ((PyObject *)__pyx_n_s__cggev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cggev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zggev));
  PyList_SET_ITEM(__pyx_t_1, 15, ((PyObject *)__pyx_n_s__zggev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zggev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sgees));
  PyList_SET_ITEM(__pyx_t_1, 16, ((PyObject *)__pyx_n_s__sgees));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sgees));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dgees));
  PyList_SET_ITEM(__pyx_t_1, 17, ((PyObject *)__pyx_n_s__dgees));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dgees));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgees));
  PyList_SET_ITEM(__pyx_t_1, 18, ((PyObject *)__pyx_n_s__cgees));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgees));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zgees));
  PyList_SET_ITEM(__pyx_t_1, 19, ((PyObject *)__pyx_n_s__zgees));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zgees));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__strsen));
  PyList_SET_ITEM(__pyx_t_1, 20, ((PyObject *)__pyx_n_s__strsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__strsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dtrsen));
  PyList_SET_ITEM(__pyx_t_1, 21, ((PyObject *)__pyx_n_s__dtrsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dtrsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ctrsen));
  PyList_SET_ITEM(__pyx_t_1, 22, ((PyObject *)__pyx_n_s__ctrsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ctrsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ztrsen));
  PyList_SET_ITEM(__pyx_t_1, 23, ((PyObject *)__pyx_n_s__ztrsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ztrsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__strevc));
  PyList_SET_ITEM(__pyx_t_1, 24, ((PyObject *)__pyx_n_s__strevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__strevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dtrevc));
  PyList_SET_ITEM(__pyx_t_1, 25, ((PyObject *)__pyx_n_s__dtrevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dtrevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ctrevc));
  PyList_SET_ITEM(__pyx_t_1, 26, ((PyObject *)__pyx_n_s__ctrevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ctrevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ztrevc));
  PyList_SET_ITEM(__pyx_t_1, 27, ((PyObject *)__pyx_n_s__ztrevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ztrevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sgges));
  PyList_SET_ITEM(__pyx_t_1, 28, ((PyObject *)__pyx_n_s__sgges));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sgges));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dgges));
  PyList_SET_ITEM(__pyx_t_1, 29, ((PyObject *)__pyx_n_s__dgges));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dgges));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgges));
  PyList_SET_ITEM(__pyx_t_1, 30, ((PyObject *)__pyx_n_s__cgges));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgges));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zgges));
  PyList_SET_ITEM(__pyx_t_1, 31, ((PyObject *)__pyx_n_s__zgges));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zgges));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__stgsen));
  PyList_SET_ITEM(__pyx_t_1, 32, ((PyObject *)__pyx_n_s__stgsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stgsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dtgsen));
  PyList_SET_ITEM(__pyx_t_1, 33, ((PyObject *)__pyx_n_s__dtgsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dtgsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ctgsen));
  PyList_SET_ITEM(__pyx_t_1, 34, ((PyObject *)__pyx_n_s__ctgsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ctgsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ztgsen));
  PyList_SET_ITEM(__pyx_t_1, 35, ((PyObject *)__pyx_n_s__ztgsen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ztgsen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__stgevc));
  PyList_SET_ITEM(__pyx_t_1, 36, ((PyObject *)__pyx_n_s__stgevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stgevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dtgevc));
  PyList_SET_ITEM(__pyx_t_1, 37, ((PyObject *)__pyx_n_s__dtgevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dtgevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ctgevc));
  PyList_SET_ITEM(__pyx_t_1, 38, ((PyObject *)__pyx_n_s__ctgevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ctgevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ztgevc));
  PyList_SET_ITEM(__pyx_t_1, 39, ((PyObject *)__pyx_n_s__ztgevc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ztgevc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__prepare_for_lapack));
  PyList_SET_ITEM(__pyx_t_1, 40, ((PyObject *)__pyx_n_s__prepare_for_lapack));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prepare_for_lapack));
  if (PyDict_SetItem(__pyx_d, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":23
 *            'prepare_for_lapack']
 * 
 * import numpy as np             # <<<<<<<<<<<<<<
 * cimport numpy as np
 * 
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __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.
 * import f_lapack             # <<<<<<<<<<<<<<
 * cimport f_lapack
 * from f_lapack cimport l_int, l_logical
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__f_lapack), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__f_lapack, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__l_int_dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __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__int_dtype, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "kwant/linalg/lapack.pyx":33
 * 
 * int_dtype = f_lapack.l_int_dtype
 * logical_dtype = f_lapack.l_logical_dtype             # <<<<<<<<<<<<<<
 * 
 * # exceptions
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__f_lapack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__l_logical_dtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __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__logical_dtype, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":37
 * # exceptions
 * 
 * class LinAlgError(RuntimeError):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_builtin_RuntimeError);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_RuntimeError);
  __Pyx_GIVEREF(__pyx_builtin_RuntimeError);
  __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__LinAlgError, __pyx_n_s__LinAlgError, __pyx_n_s_182); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__LinAlgError, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_1filter_args, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__filter_args, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_3assert_fortran_mat, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__assert_fortran_mat, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_5sgetrf, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sgetrf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_7dgetrf, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dgetrf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_9cgetrf, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cgetrf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_11zgetrf, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zgetrf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_13sgetrs, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sgetrs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_15dgetrs, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dgetrs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_17cgetrs, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cgetrs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_19zgetrs, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zgetrs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":247
 * # Wrappers for xGECON
 * 
 * def sgecon(np.ndarray[np.float32_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_21sgecon, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sgecon, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":268
 *     return rcond
 * 
 * def dgecon(np.ndarray[np.float64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             double normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_23dgecon, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dgecon, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":289
 *     return rcond
 * 
 * def cgecon(np.ndarray[np.complex64_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *             float normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_25cgecon, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cgecon, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":310
 *     return rcond
 * 
 * def zgecon(np.ndarray[np.complex128_t, ndim=2] LU,             # <<<<<<<<<<<<<<
 *            double normA, char *norm = "1"):
 *     cdef l_int N, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_27zgecon, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zgecon, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_29ggev_postprocess, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ggev_postprocess, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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, *jobvr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_36 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_37 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_31sggev, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sggev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":435
 * 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, *jobvr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_41 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_42 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":433
 * 
 * 
 * def dggev(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.float64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_33dggev, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dggev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":502
 * 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, *jobvr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_46 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_47 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":500
 * 
 * 
 * def cggev(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex64_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_35cggev, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cggev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":569
 * 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, *jobvr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_52 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_53 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":567
 * 
 * 
 * def zggev(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           np.ndarray[np.complex128_t, ndim=2] B,
 *           left=False, right=True):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_37zggev, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zggev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":635
 * # 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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_58 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_59 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":634
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_39sgees, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sgees, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":686
 * 
 * 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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_63 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_64 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":685
 * 
 * 
 * def dgees(np.ndarray[np.float64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_41dgees, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dgees, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":737
 * 
 * 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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_68 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_69 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":736
 * 
 * 
 * def cgees(np.ndarray[np.complex64_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_43cgees, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cgees, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":785
 * 
 * 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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_73 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_74 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":784
 * 
 * 
 * def zgees(np.ndarray[np.complex128_t, ndim=2] A,             # <<<<<<<<<<<<<<
 *           calc_q=True, calc_ev=True):
 *     cdef l_int N, lwork, sdim, info
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_45zgees, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zgees, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":835
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_78 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":832
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_47strsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__strsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":892
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_82 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":889
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_49dtrsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dtrsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":949
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_85 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":946
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_51ctrsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ctrsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":996
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_88 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":993
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_53ztrsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ztrsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1041
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_55txevc_postprocess, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__txevc_postprocess, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1083
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_99 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_100 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1080
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_57strevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__strevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1185
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_103 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_104 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1182
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_59dtrevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dtrevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1286
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_107 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_108 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1283
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_61ctrevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ctrevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1365
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_111 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_112 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1362
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_63ztrevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ztrevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1444
 * 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, *jobvsr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_115 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_116 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_117 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1442
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_65sgges, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__sgges, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1516
 * 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, *jobvsr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_120 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_121 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_122 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1514
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_67dgges, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dgges, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1588
 * 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, *jobvsr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_125 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_126 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_127 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1586
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_69cgges, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__cgges, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1655
 * 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, *jobvsr
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_130 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_131 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_132 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1653
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_71zgges, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__zgges, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1726
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_135 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1721
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_73stgsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__stgsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1803
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_138 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1798
 * 
 * 
 * def dtgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.float64_t, ndim=2] S,
 *            np.ndarray[np.float64_t, ndim=2] T,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_75dtgsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dtgsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1880
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_141 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1875
 * 
 * 
 * def ctgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex64_t, ndim=2] S,
 *            np.ndarray[np.complex64_t, ndim=2] T,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_77ctgsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ctgsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1949
 *            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
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_144 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":1944
 * 
 * 
 * def ztgsen(np.ndarray[l_logical] select,             # <<<<<<<<<<<<<<
 *            np.ndarray[np.complex128_t, ndim=2] S,
 *            np.ndarray[np.complex128_t, ndim=2] T,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_79ztgsen, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ztgsen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2019
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_147 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_148 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2014
 * 
 * # 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_81stgevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__stgevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2128
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_151 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_152 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2123
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_83dtgevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__dtgevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2238
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_155 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_156 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2233
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_85ctgevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ctgevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2325
 *            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, *howmny
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_159 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_160 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2320
 * 
 * 
 * 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_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_87ztgevc, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__ztgevc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "kwant/linalg/lapack.pyx":2407
 * 
 * 
 * def prepare_for_lapack(overwrite, *args):             # <<<<<<<<<<<<<<
 *     """Convert arrays to Fortran format.
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5kwant_6linalg_6lapack_89prepare_for_lapack, NULL, __pyx_n_s_182); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s__prepare_for_lapack, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_d, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "numpy.pxd":975
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init kwant.linalg.lapack", __pyx_clineno, __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 PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */
#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 /* CYTHON_REFNANNY */

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 '%s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

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,
                 "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

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
}

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,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

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);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || 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
}

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;
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CPYTHON_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_CheckExact(key)) && 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,
        "%s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static CYTHON_INLINE 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,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, 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,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, 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, int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    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))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            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));
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    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);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    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 PY_VERSION_HEX < 0x02050000
    if (PyClass_Check(type)) {
    #else
    if (PyType_Check(type)) {
    #endif
#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;
        #if PY_VERSION_HEX < 0x02050000
        if (PyInstance_Check(type)) {
            type = (PyObject*) ((PyInstanceObject*)type)->in_class;
            Py_INCREF(type);
        } else {
            type = 0;
            PyErr_SetString(PyExc_TypeError,
                "raise: exception must be an old-style class or instance");
            goto raise_error;
        }
        #else
        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;
        }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else /* Python 3+ */
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 *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 = PyEval_CallObject(type, args);
        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 PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        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) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
  unsigned int n = 1;
  return *(unsigned char*)(&n) != 0;
}
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) /* First char was not a digit */
        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; /* Consume from buffer string */
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break; /* breaks both loops as ctx->enc_count == 0 */
      }
      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; /* empty struct */
        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 CYTHON_INLINE 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 != ')') {
        if (isspace(*ts))
            continue;
        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 10:
      case 13:
        ++ts;
        break;
      case '<':
        if (!__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_IsLittleEndian()) {
          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': /* substruct */
        {
          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; /* Erase processed last struct element */
          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 '}': /* end of substruct; either repeat or move on */
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0; /* Erase processed last struct element */
          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;
        }        /* fall through */
      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 's': case 'p':
        if (ctx->enc_type == *ts && got_Z == ctx->is_complex &&
            ctx->enc_packmode == ctx->new_packmode) {
          ctx->enc_count += ctx->new_count;
        } else {
          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;
        }
    }
  }
}
static CYTHON_INLINE 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 CYTHON_INLINE int __Pyx_GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  if (obj == Py_None || obj == NULL) {
    __Pyx_ZeroBuffer(buf);
    return 0;
  }
  buf->buf = NULL;
  if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
  if (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 ((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_ZeroBuffer(buf);
  return -1;
}
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (info->buf == NULL) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (result) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_Format(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

#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

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__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_sumf(__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_difff(__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_prodf(__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;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        float denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__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_zerof(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__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_absf(__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_powf(__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_prodf(a, a);
                        return __Pyx_c_prodf(a, a);
                    case 3:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, a);
                    case 4:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_absf(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

#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

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__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(__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(__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(__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;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__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(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__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(__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(__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(a, a);
                        return __Pyx_c_prod(a, a);
                    case 3:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, a);
                    case 4:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs(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 PY_VERSION_HEX >= 0x02060000
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
  #endif
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags);
  #if PY_VERSION_HEX < 0x02060000
    if (obj->ob_type->tp_dict) {
        PyObject *getbuffer_cobj = PyObject_GetItem(
            obj->ob_type->tp_dict, __pyx_n_s____pyx_getbuffer);
        if (getbuffer_cobj) {
            getbufferproc func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj);
            Py_DECREF(getbuffer_cobj);
            if (!func)
                goto fail;
            return func(obj, view, flags);
        } else {
            PyErr_Clear();
        }
    }
  #endif
    PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
#if PY_VERSION_HEX < 0x02060000
fail:
#endif
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
  #if PY_VERSION_HEX >= 0x02060000
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
  #endif
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) { __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view); return; }
  #if PY_VERSION_HEX < 0x02060000
    if (obj->ob_type->tp_dict) {
        PyObject *releasebuffer_cobj = PyObject_GetItem(
            obj->ob_type->tp_dict, __pyx_n_s____pyx_releasebuffer);
        if (releasebuffer_cobj) {
            releasebufferproc func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj);
            Py_DECREF(releasebuffer_cobj);
            if (!func)
                goto fail;
            func(obj, view);
            return;
        } else {
            PyErr_Clear();
        }
    }
  #endif
    goto nofail;
#if PY_VERSION_HEX < 0x02060000
fail:
#endif
    PyErr_WriteUnraisable(obj);
nofail:
    Py_DECREF(obj);
    view->obj = NULL;
}
#endif /*  PY_MAJOR_VERSION < 3 */


        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_VERSION_HEX < 0x03030000
    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_VERSION_HEX >= 0x02050000
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                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, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0; /* try absolute import on failure */
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            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
        }
    }
    #else
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) {
    PyObject *metaclass;
#if PY_MAJOR_VERSION < 3
    if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
        PyObject *base = PyTuple_GET_ITEM(bases, 0);
        metaclass = __Pyx_PyObject_GetAttrStr(base, __pyx_n_s____class__);
        if (!metaclass) {
            PyErr_Clear();
            metaclass = (PyObject*) Py_TYPE(base);
        }
    } else {
        metaclass = (PyObject *) &PyClass_Type;
    }
#else
    if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
        PyObject *base = PyTuple_GET_ITEM(bases, 0);
        metaclass = (PyObject*) Py_TYPE(base);
    } else {
        metaclass = (PyObject *) &PyType_Type;
    }
#endif
    Py_INCREF(metaclass);
    return metaclass;
}

static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
                                   PyObject *qualname, PyObject *modname) {
    PyObject *result;
    PyObject *metaclass;
    if (PyDict_SetItem(dict, __pyx_n_s____module__, modname) < 0)
        return NULL;
    if (PyDict_SetItem(dict, __pyx_n_s____qualname__, qualname) < 0)
        return NULL;
    metaclass = PyDict_GetItem(dict, __pyx_n_s____metaclass__);
    if (metaclass) {
        Py_INCREF(metaclass);
    } else {
        metaclass = __Pyx_FindPy2Metaclass(bases);
    }
    result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
    Py_DECREF(metaclass);
    return result;
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (unsigned long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return (unsigned long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(unsigned long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(unsigned long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (unsigned long)PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return (long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (long)PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (signed long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return (signed long)PyLong_AsUnsignedLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(signed long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(signed long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (signed long)PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
#endif
#endif
            return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

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);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

#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

#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,
            "%s.%s 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",
            module_name, class_name);
        #if PY_VERSION_HEX < 0x02050000
        if (PyErr_Warn(NULL, warning) < 0) goto bad;
        #else
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
        #endif
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%s.%s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

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) / 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, 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);
}

#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,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __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,      /*int firstlineno,*/
        __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;
    PyObject *py_globals = 0;
    PyFrameObject *py_frame = 0;
    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_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

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  /* Python 3+ has unicode identifiers */
        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;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE 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)) {
#if PY_VERSION_HEX < 0x03030000
        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 /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else /* PY_VERSION_HEX < 0x03030000 */
        if (PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_DATA_SIZE(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
        return PyUnicode_AsUTF8AndSize(o, length);
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
#endif /* PY_VERSION_HEX < 0x03030000 */
    } else
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII  || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (r < 0) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  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 = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       if ((val != (unsigned PY_LONG_LONG)-1) || !PyErr_Occurred())
           PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
