/* Generated by Pyrex 0.9.8.5 on Mon Jun 15 13:04:28 2009 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#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 PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#include "array_interface.h"
#include "math.h"
#include "matrix_invert.c"
#include "eigen.c"


typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
static char **__pyx_f;

static void __Pyx_WriteUnraisable(char *name); /*proto*/

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

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

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

static void __Pyx_AddTraceback(char *funcname); /*proto*/

/* Declarations from cogent.maths._matrix_exponentiation */


/* Declarations from implementation of cogent.maths._matrix_exponentiation */

typedef PyObject *__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType;

struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator {
  PyObject_HEAD
  int n;
  PyObject *shape;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType Q;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType roots;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType ev;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType evT;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType evI;
  double *_ev;
  double *_evI;
  double *_roots;
};


static PyTypeObject *__pyx_ptype_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator = 0;
static PyObject *__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty;
static PyObject *__pyx_v_6cogent_5maths_22_matrix_exponentiation_zeros;
static PyObject *__pyx_v_6cogent_5maths_22_matrix_exponentiation_contiguous;
static PyObject *__pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT;
static PyObject *__pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX;
static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_uncheckedArrayDouble(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType); /*proto*/
static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,char,int,int,int **); /*proto*/
static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,char,int,int *); /*proto*/
static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,char,int,int *,int *); /*proto*/
static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,char,int,int *,int *,int *); /*proto*/
static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,char,int,int *,int *,int *,int *); /*proto*/
static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *); /*proto*/
static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *); /*proto*/
static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *,int *); /*proto*/
static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *,int *,int *); /*proto*/
static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *); /*proto*/
static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *); /*proto*/
static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *,int *); /*proto*/
static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType,int *,int *,int *,int *); /*proto*/

static char __pyx_k1[] = "__array_struct__";
static char __pyx_k2[] = "Array required, got None";
static char __pyx_k3[] = "Unexpected array interface version %s";
static char __pyx_k4[] = "'%s' type array required, got '%s'";
static char __pyx_k5[] = "chr";
static char __pyx_k6[] = "'%s%s' type array required, got '%s%s'";
static char __pyx_k7[] = "%s dimensional array required, got %s";
static char __pyx_k8[] = "Noncontiguous array";
static char __pyx_k9[] = "Dimension %s is %s, expected %s";
static char __pyx_k10[] = "d";
static char __pyx_k11[] = "D";
static char __pyx_k12[] = "array";
static char __pyx_k13[] = "zeros";
static char __pyx_k14[] = "empty";
static char __pyx_k15[] = "inner";
static char __pyx_k16[] = "copy";
static char __pyx_k17[] = "%s > 64";
static char __pyx_k18[] = "Determinant too small";
static char __pyx_k19[] = "eigenvalues didn't converge";
static char __pyx_k20[] = "Negative distance %s";
static char __pyx_k21[] = "('1', '3')";
static char __pyx_k22[] = "__version__";
static char __pyx_k23[] = "version_info";

static PyObject *__pyx_n_D;
static PyObject *__pyx_n___array_struct__;
static PyObject *__pyx_n___version__;
static PyObject *__pyx_n_array;
static PyObject *__pyx_n_chr;
static PyObject *__pyx_n_copy;
static PyObject *__pyx_n_d;
static PyObject *__pyx_n_empty;
static PyObject *__pyx_n_inner;
static PyObject *__pyx_n_version_info;
static PyObject *__pyx_n_zeros;

static PyObject *__pyx_k2p;
static PyObject *__pyx_k3p;
static PyObject *__pyx_k4p;
static PyObject *__pyx_k6p;
static PyObject *__pyx_k7p;
static PyObject *__pyx_k8p;
static PyObject *__pyx_k9p;
static PyObject *__pyx_k17p;
static PyObject *__pyx_k18p;
static PyObject *__pyx_k19p;
static PyObject *__pyx_k20p;
static PyObject *__pyx_k21p;

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_D, 1, __pyx_k11, sizeof(__pyx_k11)},
  {&__pyx_n___array_struct__, 1, __pyx_k1, sizeof(__pyx_k1)},
  {&__pyx_n___version__, 1, __pyx_k22, sizeof(__pyx_k22)},
  {&__pyx_n_array, 1, __pyx_k12, sizeof(__pyx_k12)},
  {&__pyx_n_chr, 1, __pyx_k5, sizeof(__pyx_k5)},
  {&__pyx_n_copy, 1, __pyx_k16, sizeof(__pyx_k16)},
  {&__pyx_n_d, 1, __pyx_k10, sizeof(__pyx_k10)},
  {&__pyx_n_empty, 1, __pyx_k14, sizeof(__pyx_k14)},
  {&__pyx_n_inner, 1, __pyx_k15, sizeof(__pyx_k15)},
  {&__pyx_n_version_info, 1, __pyx_k23, sizeof(__pyx_k23)},
  {&__pyx_n_zeros, 1, __pyx_k13, sizeof(__pyx_k13)},
  {&__pyx_k2p, 0, __pyx_k2, sizeof(__pyx_k2)},
  {&__pyx_k3p, 0, __pyx_k3, sizeof(__pyx_k3)},
  {&__pyx_k4p, 0, __pyx_k4, sizeof(__pyx_k4)},
  {&__pyx_k6p, 0, __pyx_k6, sizeof(__pyx_k6)},
  {&__pyx_k7p, 0, __pyx_k7, sizeof(__pyx_k7)},
  {&__pyx_k8p, 0, __pyx_k8, sizeof(__pyx_k8)},
  {&__pyx_k9p, 0, __pyx_k9, sizeof(__pyx_k9)},
  {&__pyx_k17p, 0, __pyx_k17, sizeof(__pyx_k17)},
  {&__pyx_k18p, 0, __pyx_k18, sizeof(__pyx_k18)},
  {&__pyx_k19p, 0, __pyx_k19, sizeof(__pyx_k19)},
  {&__pyx_k20p, 0, __pyx_k20, sizeof(__pyx_k20)},
  {&__pyx_k21p, 0, __pyx_k21, sizeof(__pyx_k21)},
  {0, 0, 0, 0}
};



/* Implementation of cogent.maths._matrix_exponentiation */

static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_uncheckedArrayDouble(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_A) {
  struct PyArrayInterface *__pyx_v_a;
  PyObject *__pyx_v_cobj;
  double *__pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_A);
  __pyx_v_cobj = Py_None; Py_INCREF(Py_None);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":34 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_A, __pyx_n___array_struct__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
  Py_DECREF(__pyx_v_cobj);
  __pyx_v_cobj = __pyx_1;
  __pyx_1 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":35 */
  __pyx_v_a = ((struct PyArrayInterface *)PyCObject_AsVoidPtr(__pyx_v_cobj));

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":36 */
  __pyx_r = ((double *)__pyx_v_a->data);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_WriteUnraisable("cogent.maths._matrix_exponentiation.uncheckedArrayDouble");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_cobj);
  Py_DECREF(__pyx_v_A);
  return __pyx_r;
}

static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_A,char __pyx_v_typecode,int __pyx_v_itemsize,int __pyx_v_nd,int **__pyx_v_dims) {
  struct PyArrayInterface *__pyx_v_a;
  PyObject *__pyx_v_cobj;
  char __pyx_v_typecode2;
  int __pyx_v_dimension;
  int __pyx_v_val;
  int *__pyx_v_var;
  void *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  PyObject *__pyx_6 = 0;
  Py_INCREF(__pyx_v_A);
  __pyx_v_cobj = Py_None; Py_INCREF(Py_None);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":43 */
  __pyx_1 = __pyx_v_A == Py_None;
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
    Py_INCREF(__pyx_k2p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k2p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":45 */
  __pyx_2 = PyObject_GetAttr(__pyx_v_A, __pyx_n___array_struct__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;}
  Py_DECREF(__pyx_v_cobj);
  __pyx_v_cobj = __pyx_2;
  __pyx_2 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":46 */
  __pyx_v_a = ((struct PyArrayInterface *)PyCObject_AsVoidPtr(__pyx_v_cobj));

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":47 */
  __pyx_1 = (__pyx_v_a->version != 2);
  if (__pyx_1) {
    __pyx_3 = PyInt_FromLong(__pyx_v_a->version); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
    __pyx_3 = 0;
    __pyx_3 = PyObject_CallObject(((PyObject *)(&PyString_Type)), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k3p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":51 */
  __pyx_v_typecode2 = __pyx_v_a->typekind;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":52 */
  __pyx_1 = (__pyx_v_typecode2 != __pyx_v_typecode);
  if (__pyx_1) {
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_chr); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    __pyx_2 = PyInt_FromLong(__pyx_v_typecode); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_chr); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    __pyx_4 = PyInt_FromLong(__pyx_v_typecode2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_3, 1, __pyx_4);
    __pyx_2 = 0;
    __pyx_4 = 0;
    __pyx_5 = PyNumber_Remainder(__pyx_k4p, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_5);
    __pyx_5 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":55 */
  __pyx_1 = (__pyx_v_a->itemsize != __pyx_v_itemsize);
  if (__pyx_1) {
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_chr); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_5 = PyInt_FromLong(__pyx_v_typecode); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_5);
    __pyx_5 = 0;
    __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_5 = PyInt_FromLong(__pyx_v_itemsize); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_chr); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_2 = PyInt_FromLong(__pyx_v_typecode2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_6, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    __pyx_3 = PyInt_FromLong(__pyx_v_a->itemsize); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    __pyx_6 = PyTuple_New(4); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4);
    PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
    PyTuple_SET_ITEM(__pyx_6, 2, __pyx_2);
    PyTuple_SET_ITEM(__pyx_6, 3, __pyx_3);
    __pyx_4 = 0;
    __pyx_5 = 0;
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_4 = PyNumber_Remainder(__pyx_k6p, __pyx_6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; goto __pyx_L1;}
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_TypeError, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; goto __pyx_L1;}
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; goto __pyx_L1;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":58 */
  __pyx_1 = (__pyx_v_a->nd != __pyx_v_nd);
  if (__pyx_1) {
    __pyx_3 = PyInt_FromLong(__pyx_v_nd); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
    __pyx_6 = PyInt_FromLong(__pyx_v_a->nd); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_6);
    __pyx_3 = 0;
    __pyx_6 = 0;
    __pyx_5 = PyNumber_Remainder(__pyx_k7p, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_5);
    __pyx_5 = 0;
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":61 */
  __pyx_1 = (!(__pyx_v_a->flags & CONTIGUOUS));
  if (__pyx_1) {
    __pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
    Py_INCREF(__pyx_k8p);
    PyTuple_SET_ITEM(__pyx_6, 0, __pyx_k8p);
    __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":66 */
  for (__pyx_v_dimension = 0; __pyx_v_dimension < __pyx_v_nd; ++__pyx_v_dimension) {

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":67 */
    __pyx_v_val = (__pyx_v_a->shape[__pyx_v_dimension]);

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":68 */
    __pyx_v_var = (__pyx_v_dims[__pyx_v_dimension]);

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":69 */
    __pyx_1 = ((__pyx_v_var[0]) == 0);
    if (__pyx_1) {
      (__pyx_v_var[0]) = __pyx_v_val;
      goto __pyx_L10;
    }
    __pyx_1 = ((__pyx_v_var[0]) != __pyx_v_val);
    if (__pyx_1) {
      __pyx_5 = PyInt_FromLong(__pyx_v_dimension); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
      __pyx_2 = PyInt_FromLong(__pyx_v_val); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
      __pyx_3 = PyInt_FromLong((__pyx_v_var[0])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
      __pyx_6 = PyTuple_New(3); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_6, 0, __pyx_5);
      PyTuple_SET_ITEM(__pyx_6, 1, __pyx_2);
      PyTuple_SET_ITEM(__pyx_6, 2, __pyx_3);
      __pyx_5 = 0;
      __pyx_2 = 0;
      __pyx_3 = 0;
      __pyx_4 = PyNumber_Remainder(__pyx_k9p, __pyx_6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;}
      Py_DECREF(__pyx_6); __pyx_6 = 0;
      __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_5, 0, __pyx_4);
      __pyx_4 = 0;
      __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;}
      Py_DECREF(__pyx_5); __pyx_5 = 0;
      __Pyx_Raise(__pyx_2, 0, 0);
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;}
      goto __pyx_L10;
    }
    /*else*/ {
    }
    __pyx_L10:;
  }

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":79 */
  __pyx_r = __pyx_v_a->data;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArray");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_cobj);
  Py_DECREF(__pyx_v_A);
  return __pyx_r;
}

static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,char __pyx_v_typecode,int __pyx_v_size,int *__pyx_v_x) {
  int *__pyx_v_dims[1];
  void *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":85 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":86 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_v_a,__pyx_v_typecode,__pyx_v_size,1,__pyx_v_dims); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArray1D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,char __pyx_v_typecode,int __pyx_v_size,int *__pyx_v_x,int *__pyx_v_y) {
  int *__pyx_v_dims[2];
  void *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":91 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":92 */
  (__pyx_v_dims[1]) = __pyx_v_y;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":93 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_v_a,__pyx_v_typecode,__pyx_v_size,2,__pyx_v_dims); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArray2D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,char __pyx_v_typecode,int __pyx_v_size,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  int *__pyx_v_dims[3];
  void *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":98 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":99 */
  (__pyx_v_dims[1]) = __pyx_v_y;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":100 */
  (__pyx_v_dims[2]) = __pyx_v_z;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":101 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_v_a,__pyx_v_typecode,__pyx_v_size,3,__pyx_v_dims); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArray3D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static void *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,char __pyx_v_typecode,int __pyx_v_size,int *__pyx_v_w,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  int *__pyx_v_dims[4];
  void *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":106 */
  (__pyx_v_dims[0]) = __pyx_v_w;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":107 */
  (__pyx_v_dims[1]) = __pyx_v_x;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":108 */
  (__pyx_v_dims[2]) = __pyx_v_y;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":109 */
  (__pyx_v_dims[3]) = __pyx_v_z;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":110 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray(__pyx_v_a,__pyx_v_typecode,__pyx_v_size,4,__pyx_v_dims); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArray4D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x) {
  double *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray1D(__pyx_v_a,'f',(sizeof(double)),__pyx_v_x); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
  __pyx_r = ((double *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayDouble1D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x,int *__pyx_v_y) {
  double *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_v_a,'f',(sizeof(double)),__pyx_v_x,__pyx_v_y); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
  __pyx_r = ((double *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayDouble2D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  double *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray3D(__pyx_v_a,'f',(sizeof(double)),__pyx_v_x,__pyx_v_y,__pyx_v_z); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
  __pyx_r = ((double *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayDouble3D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static double *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_w,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  double *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray4D(__pyx_v_a,'f',(sizeof(double)),__pyx_v_w,__pyx_v_x,__pyx_v_y,__pyx_v_z); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
  __pyx_r = ((double *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayDouble4D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong1D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x) {
  long *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray1D(__pyx_v_a,'i',(sizeof(long)),__pyx_v_x); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
  __pyx_r = ((long *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayLong1D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong2D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x,int *__pyx_v_y) {
  long *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_v_a,'i',(sizeof(long)),__pyx_v_x,__pyx_v_y); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; goto __pyx_L1;}
  __pyx_r = ((long *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayLong2D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong3D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  long *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray3D(__pyx_v_a,'i',(sizeof(long)),__pyx_v_x,__pyx_v_y,__pyx_v_z); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; goto __pyx_L1;}
  __pyx_r = ((long *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayLong3D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static long *__pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayLong4D(__pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_a,int *__pyx_v_w,int *__pyx_v_x,int *__pyx_v_y,int *__pyx_v_z) {
  long *__pyx_r;
  void *__pyx_1;
  Py_INCREF(__pyx_v_a);
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray4D(__pyx_v_a,'i',(sizeof(long)),__pyx_v_w,__pyx_v_x,__pyx_v_y,__pyx_v_z); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
  __pyx_r = ((long *)__pyx_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.checkArrayLong4D");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  return __pyx_r;
}

static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_setNumPy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_setNumPy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_Numeric = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"Numeric",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_Numeric)) return 0;
  Py_INCREF(__pyx_v_Numeric);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":27 */
  Py_INCREF(__pyx_n_d);
  Py_DECREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT = __pyx_n_d;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":28 */
  Py_INCREF(__pyx_n_D);
  Py_DECREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX = __pyx_n_D;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":29 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_Numeric, __pyx_n_array); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; goto __pyx_L1;}
  Py_DECREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_contiguous);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_contiguous = __pyx_1;
  __pyx_1 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":30 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_Numeric, __pyx_n_zeros); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; goto __pyx_L1;}
  Py_DECREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_zeros);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_zeros = __pyx_1;
  __pyx_1 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":31 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_Numeric, __pyx_n_empty); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; goto __pyx_L1;}
  Py_DECREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_empty = __pyx_1;
  __pyx_1 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":32 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_Numeric, __pyx_n_inner); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_inner, __pyx_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.setNumPy");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_Numeric);
  return __pyx_r;
}

static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_inverse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_inverse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_U = 0;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_V;
  int __pyx_v_n;
  int __pyx_v_ret;
  int __pyx_v_is_complex;
  int __pyx_v_i;
  double __pyx_v_work[128];
  double *__pyx_v_data;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  double *__pyx_3;
  int __pyx_4;
  PyObject *__pyx_5 = 0;
  void *__pyx_6;
  long __pyx_7;
  static char *__pyx_argnames[] = {"U",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_U)) return 0;
  Py_INCREF(__pyx_v_U);
  __pyx_v_V = Py_None; Py_INCREF(Py_None);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":38 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_U, __pyx_n_copy); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_V);
  __pyx_v_V = __pyx_2;
  __pyx_2 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":39 */
  __pyx_v_n = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":40 */
  /*try:*/ {

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":41 */
    __pyx_3 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_v_V,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_3 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; goto __pyx_L2;}
    __pyx_v_data = __pyx_3;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":42 */
    __pyx_v_is_complex = 0;
  }
  goto __pyx_L3;
  __pyx_L2:;
  Py_XDECREF(__pyx_1); __pyx_1 = 0;
  Py_XDECREF(__pyx_2); __pyx_2 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":43 */
  __pyx_4 = PyErr_ExceptionMatches(PyExc_TypeError);
  if (__pyx_4) {
    __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.inverse");
    if (__Pyx_GetException(&__pyx_1, &__pyx_2, &__pyx_5) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; goto __pyx_L1;}

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":44 */
    __pyx_6 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_v_V,'c',((sizeof(double)) * 2),(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_6 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; goto __pyx_L1;}
    __pyx_v_data = ((double *)__pyx_6);

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":45 */
    __pyx_v_is_complex = 1;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    goto __pyx_L3;
  }
  goto __pyx_L1;
  __pyx_L3:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":47 */
  __pyx_4 = (__pyx_v_n > 64);
  if (__pyx_4) {
    __pyx_1 = PyInt_FromLong(__pyx_v_n); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; goto __pyx_L1;}
    __pyx_2 = PyNumber_Remainder(__pyx_k17p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_1 = PyObject_CallObject(PyExc_ValueError, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; goto __pyx_L1;}
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    __Pyx_Raise(__pyx_1, 0, 0);
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":51 */
  __pyx_7 = (2 * __pyx_v_n);
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_7; ++__pyx_v_i) {
    (__pyx_v_work[__pyx_v_i]) = 0;
  }

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":54 */
  __pyx_4 = __pyx_v_is_complex;
  if (__pyx_4) {
    __pyx_v_ret = cmatinv(((struct complex *)__pyx_v_data),__pyx_v_n,__pyx_v_n,__pyx_v_work);
    goto __pyx_L7;
  }
  /*else*/ {
    __pyx_v_ret = matinv(__pyx_v_data,__pyx_v_n,__pyx_v_n,__pyx_v_work);
  }
  __pyx_L7:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":59 */
  __pyx_4 = __pyx_v_ret;
  if (__pyx_4) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; goto __pyx_L1;}
    Py_INCREF(__pyx_k18p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k18p);
    __pyx_5 = PyObject_CallObject(PyExc_ArithmeticError, __pyx_2); if (!__pyx_5) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_5, 0, 0);
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; goto __pyx_L1;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":61 */
  Py_INCREF(__pyx_v_V);
  __pyx_r = __pyx_v_V;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.inverse");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_V);
  Py_DECREF(__pyx_v_U);
  return __pyx_r;
}

static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_eigenvectors(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_eigenvectors(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_Q = 0;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_U;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_R;
  int __pyx_v_n;
  int __pyx_v_ret;
  double *__pyx_v_U_data;
  double *__pyx_v_R_data;
  double *__pyx_v_Q_data;
  double __pyx_v_Q2_data[4096];
  double __pyx_v_U2_data[4096];
  double __pyx_v_Ui2_data[4096];
  double __pyx_v_R2_data[64];
  double __pyx_v_Ri2_data[64];
  double __pyx_v_work[128];
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_j;
  PyObject *__pyx_r;
  double *__pyx_1;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  long __pyx_5;
  Py_ssize_t __pyx_6;
  Py_ssize_t __pyx_7;
  PyObject *__pyx_8 = 0;
  void *__pyx_9;
  void *__pyx_10;
  long __pyx_11;
  double *__pyx_12;
  static char *__pyx_argnames[] = {"Q",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_Q)) return 0;
  Py_INCREF(__pyx_v_Q);
  __pyx_v_U = Py_None; Py_INCREF(Py_None);
  __pyx_v_R = Py_None; Py_INCREF(Py_None);
  __pyx_v_i = Py_None; Py_INCREF(Py_None);
  __pyx_v_j = Py_None; Py_INCREF(Py_None);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":69 */
  __pyx_v_n = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":70 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_v_Q,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; goto __pyx_L1;}
  __pyx_v_Q_data = __pyx_1;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":71 */
  __pyx_2 = (__pyx_v_n > 64);
  if (__pyx_2) {
    __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; goto __pyx_L1;}
    __pyx_4 = PyNumber_Remainder(__pyx_k17p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":73 */
  __pyx_2 = (__pyx_v_n * __pyx_v_n);
  for (__pyx_5 = 0; __pyx_5 < __pyx_2; ++__pyx_5) {
    __pyx_3 = PyInt_FromLong(__pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; goto __pyx_L1;}
    Py_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_3;
    __pyx_3 = 0;
    __pyx_6 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; goto __pyx_L1;}
    __pyx_7 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; goto __pyx_L1;}
    (__pyx_v_Q2_data[__pyx_7]) = (__pyx_v_Q_data[__pyx_6]);
  }

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":75 */
  __pyx_v_ret = eigen(1,__pyx_v_Q2_data,__pyx_v_n,__pyx_v_R2_data,__pyx_v_Ri2_data,__pyx_v_U2_data,__pyx_v_Ui2_data,__pyx_v_work);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":76 */
  __pyx_2 = (__pyx_v_ret == (-1));
  if (__pyx_2) {
    __Pyx_Raise(PyExc_RuntimeError, __pyx_k19p, 0);
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; goto __pyx_L1;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":78 */
  __pyx_2 = (__pyx_v_ret == 1);
  if (__pyx_2) {

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":79 */
    __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
    __pyx_3 = PyList_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
    PyList_SET_ITEM(__pyx_3, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3);
    Py_INCREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX);
    __pyx_3 = 0;
    __pyx_3 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_v_R);
    __pyx_v_R = __pyx_3;
    __pyx_3 = 0;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":80 */
    __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; goto __pyx_L1;}
    __pyx_8 = PyList_New(2); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; goto __pyx_L1;}
    PyList_SET_ITEM(__pyx_8, 0, __pyx_4);
    PyList_SET_ITEM(__pyx_8, 1, __pyx_3);
    __pyx_4 = 0;
    __pyx_3 = 0;
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_8);
    Py_INCREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX);
    __pyx_8 = 0;
    __pyx_3 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_v_U);
    __pyx_v_U = __pyx_3;
    __pyx_3 = 0;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":81 */
    __pyx_9 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray2D(__pyx_v_U,'c',((sizeof(double)) * 2),(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_9 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; goto __pyx_L1;}
    __pyx_v_U_data = ((double *)__pyx_9);

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":82 */
    __pyx_10 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArray1D(__pyx_v_R,'c',((sizeof(double)) * 2),(&__pyx_v_n)); if (__pyx_10 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; goto __pyx_L1;}
    __pyx_v_R_data = ((double *)__pyx_10);

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":84 */
    for (__pyx_5 = 0; __pyx_5 < __pyx_v_n; ++__pyx_5) {
      __pyx_8 = PyInt_FromLong(__pyx_5); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; goto __pyx_L1;}
      Py_DECREF(__pyx_v_i);
      __pyx_v_i = __pyx_8;
      __pyx_8 = 0;

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":85 */
      __pyx_6 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      __pyx_4 = PyInt_FromLong(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      __pyx_3 = PyNumber_Multiply(__pyx_v_i, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      __pyx_8 = PyInt_FromLong(0); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      __pyx_4 = PyNumber_Add(__pyx_3, __pyx_8); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_8); __pyx_8 = 0;
      __pyx_7 = PyInt_AsSsize_t(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; goto __pyx_L1;}
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      (__pyx_v_R_data[__pyx_7]) = (__pyx_v_R2_data[__pyx_6]);

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":86 */
      __pyx_6 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      __pyx_8 = PyNumber_Multiply(__pyx_v_i, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      __pyx_4 = PyInt_FromLong(1); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      __pyx_3 = PyNumber_Add(__pyx_8, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      Py_DECREF(__pyx_8); __pyx_8 = 0;
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      __pyx_7 = PyInt_AsSsize_t(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      (__pyx_v_R_data[__pyx_7]) = (__pyx_v_Ri2_data[__pyx_6]);

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":87 */
      for (__pyx_11 = 0; __pyx_11 < __pyx_v_n; ++__pyx_11) {
        __pyx_8 = PyInt_FromLong(__pyx_11); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 87; goto __pyx_L1;}
        Py_DECREF(__pyx_v_j);
        __pyx_v_j = __pyx_8;
        __pyx_8 = 0;

        /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":88 */
        __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        __pyx_3 = PyNumber_Multiply(__pyx_v_j, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_8 = PyNumber_Add(__pyx_3, __pyx_v_i); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_6 = PyInt_AsSsize_t(__pyx_8); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        __pyx_3 = PyNumber_Multiply(__pyx_v_i, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_8 = PyNumber_Add(__pyx_3, __pyx_v_j); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyInt_FromLong(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        __pyx_3 = PyNumber_Multiply(__pyx_8, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_8 = PyInt_FromLong(0); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        __pyx_4 = PyNumber_Add(__pyx_3, __pyx_8); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_7 = PyInt_AsSsize_t(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        (__pyx_v_U_data[__pyx_7]) = (__pyx_v_U2_data[__pyx_6]);

        /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":89 */
        __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        __pyx_8 = PyNumber_Multiply(__pyx_v_j, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyNumber_Add(__pyx_8, __pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_6 = PyInt_AsSsize_t(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        __pyx_8 = PyNumber_Multiply(__pyx_v_i, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyNumber_Add(__pyx_8, __pyx_v_j); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        __pyx_8 = PyNumber_Multiply(__pyx_4, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyInt_FromLong(1); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        __pyx_3 = PyNumber_Add(__pyx_8, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_7 = PyInt_AsSsize_t(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        (__pyx_v_U_data[__pyx_7]) = (__pyx_v_Ui2_data[__pyx_6]);
      }
    }
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":91 */
    __pyx_8 = PyInt_FromLong(__pyx_v_n); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; goto __pyx_L1;}
    __pyx_4 = PyList_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; goto __pyx_L1;}
    PyList_SET_ITEM(__pyx_4, 0, __pyx_8);
    __pyx_8 = 0;
    __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
    Py_INCREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
    PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
    __pyx_4 = 0;
    __pyx_8 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_v_R);
    __pyx_v_R = __pyx_8;
    __pyx_8 = 0;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":92 */
    __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
    __pyx_8 = PyList_New(2); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
    PyList_SET_ITEM(__pyx_8, 0, __pyx_4);
    PyList_SET_ITEM(__pyx_8, 1, __pyx_3);
    __pyx_4 = 0;
    __pyx_3 = 0;
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_8);
    Py_INCREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
    __pyx_8 = 0;
    __pyx_3 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_empty, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_v_U);
    __pyx_v_U = __pyx_3;
    __pyx_3 = 0;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":93 */
    __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_v_U,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; goto __pyx_L1;}
    __pyx_v_U_data = __pyx_1;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":94 */
    __pyx_12 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble1D(__pyx_v_R,(&__pyx_v_n)); if (__pyx_12 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; goto __pyx_L1;}
    __pyx_v_R_data = __pyx_12;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":95 */
    for (__pyx_11 = 0; __pyx_11 < __pyx_v_n; ++__pyx_11) {
      __pyx_8 = PyInt_FromLong(__pyx_11); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; goto __pyx_L1;}
      Py_DECREF(__pyx_v_i);
      __pyx_v_i = __pyx_8;
      __pyx_8 = 0;

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":96 */
      __pyx_6 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; goto __pyx_L1;}
      __pyx_7 = PyInt_AsSsize_t(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; goto __pyx_L1;}
      (__pyx_v_R_data[__pyx_7]) = (__pyx_v_R2_data[__pyx_6]);

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":97 */
      for (__pyx_5 = 0; __pyx_5 < __pyx_v_n; ++__pyx_5) {
        __pyx_4 = PyInt_FromLong(__pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 97; goto __pyx_L1;}
        Py_DECREF(__pyx_v_j);
        __pyx_v_j = __pyx_4;
        __pyx_4 = 0;
        __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        __pyx_8 = PyNumber_Multiply(__pyx_v_j, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyNumber_Add(__pyx_8, __pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_6 = PyInt_AsSsize_t(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __pyx_3 = PyInt_FromLong(__pyx_v_n); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        __pyx_8 = PyNumber_Multiply(__pyx_v_i, __pyx_3); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __pyx_4 = PyNumber_Add(__pyx_8, __pyx_v_j); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_8); __pyx_8 = 0;
        __pyx_7 = PyInt_AsSsize_t(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        (__pyx_v_U_data[__pyx_7]) = (__pyx_v_U2_data[__pyx_6]);
      }
    }
  }
  __pyx_L6:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":99 */
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; goto __pyx_L1;}
  Py_INCREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_R);
  Py_INCREF(__pyx_v_U);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_U);
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_8);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.eigenvectors");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_U);
  Py_DECREF(__pyx_v_R);
  Py_DECREF(__pyx_v_i);
  Py_DECREF(__pyx_v_j);
  Py_DECREF(__pyx_v_Q);
  return __pyx_r;
}

static int __pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_Q = 0;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_roots = 0;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_ev = 0;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_evI = 0;
  int __pyx_v_n;
  int __pyx_r;
  double *__pyx_1;
  double *__pyx_2;
  int __pyx_3;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  PyObject *__pyx_8 = 0;
  static char *__pyx_argnames[] = {"Q","roots","ev","evI",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO", __pyx_argnames, &__pyx_v_Q, &__pyx_v_roots, &__pyx_v_ev, &__pyx_v_evI)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_Q);
  Py_INCREF(__pyx_v_roots);
  Py_INCREF(__pyx_v_ev);
  Py_INCREF(__pyx_v_evI);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":112 */
  __pyx_v_n = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":113 */
  Py_INCREF(__pyx_v_roots);
  Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->roots);
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->roots = __pyx_v_roots;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":114 */
  Py_INCREF(__pyx_v_ev);
  Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->ev);
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->ev = __pyx_v_ev;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":115 */
  Py_INCREF(__pyx_v_evI);
  Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI);
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI = __pyx_v_evI;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":116 */
  Py_INCREF(__pyx_v_Q);
  Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->Q);
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->Q = __pyx_v_Q;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":117 */
  __pyx_1 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble1D(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->roots,(&__pyx_v_n)); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; goto __pyx_L1;}
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_roots = __pyx_1;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":118 */
  __pyx_2 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->ev,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 118; goto __pyx_L1;}
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_ev = __pyx_2;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":119 */
  /*try:*/ {
    __pyx_2 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; goto __pyx_L2;}
    ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_evI = __pyx_2;
  }
  goto __pyx_L3;
  __pyx_L2:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":121 */
  __pyx_3 = PyErr_ExceptionMatches(PyExc_ValueError);
  if (__pyx_3) {
    __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.__init__");
    if (__Pyx_GetException(&__pyx_4, &__pyx_5, &__pyx_6) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; goto __pyx_L1;}

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":122 */
    __pyx_7 = PyTuple_New(1); if (!__pyx_7) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; goto __pyx_L1;}
    Py_INCREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI);
    PyTuple_SET_ITEM(__pyx_7, 0, ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI);
    __pyx_8 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_contiguous, __pyx_7); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; goto __pyx_L1;}
    Py_DECREF(__pyx_7); __pyx_7 = 0;
    Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI);
    ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI = __pyx_8;
    __pyx_8 = 0;

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":123 */
    __pyx_2 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->evI,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; goto __pyx_L1;}
    ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_evI = __pyx_2;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    goto __pyx_L3;
  }
  goto __pyx_L1;
  __pyx_L3:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":124 */
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->n = __pyx_v_n;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":125 */
  __pyx_7 = PyInt_FromLong(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->n); if (!__pyx_7) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; goto __pyx_L1;}
  __pyx_8 = PyInt_FromLong(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->n); if (!__pyx_8) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; goto __pyx_L1;}
  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_7);
  PyTuple_SET_ITEM(__pyx_4, 1, __pyx_8);
  __pyx_7 = 0;
  __pyx_8 = 0;
  Py_DECREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->shape);
  ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->shape = __pyx_4;
  __pyx_4 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  Py_XDECREF(__pyx_8);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.EigenExponentiator.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_Q);
  Py_DECREF(__pyx_v_roots);
  Py_DECREF(__pyx_v_ev);
  Py_DECREF(__pyx_v_evI);
  return __pyx_r;
}

static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  double __pyx_v_t;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_v_k;
  int __pyx_v_n;
  double __pyx_v_expt;
  double __pyx_v_uexpt;
  double *__pyx_v_data;
  double *__pyx_v_roots;
  double *__pyx_v_ev;
  double *__pyx_v_evI;
  __pyx_t_6cogent_5maths_22_matrix_exponentiation_ArrayType __pyx_v_P;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  double *__pyx_4;
  int __pyx_5;
  static char *__pyx_argnames[] = {"t",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "d", __pyx_argnames, &__pyx_v_t)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_P = Py_None; Py_INCREF(Py_None);

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":131 */
  __pyx_1 = (__pyx_v_t < 0.0);
  if (__pyx_1) {
    __pyx_2 = PyFloat_FromDouble(__pyx_v_t); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; goto __pyx_L1;}
    __pyx_3 = PyNumber_Remainder(__pyx_k20p, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
    __pyx_3 = 0;
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":133 */
  __pyx_v_n = ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->n;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":134 */
  __pyx_v_roots = ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_roots;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":135 */
  __pyx_v_ev = ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_ev;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":136 */
  __pyx_v_evI = ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->_evI;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":137 */
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 137; goto __pyx_L1;}
  Py_INCREF(((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->shape);
  PyTuple_SET_ITEM(__pyx_2, 0, ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)__pyx_v_self)->shape);
  Py_INCREF(__pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT);
  __pyx_3 = PyObject_CallObject(__pyx_v_6cogent_5maths_22_matrix_exponentiation_zeros, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 137; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_P);
  __pyx_v_P = __pyx_3;
  __pyx_3 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":138 */
  __pyx_4 = __pyx_f_6cogent_5maths_22_matrix_exponentiation_checkArrayDouble2D(__pyx_v_P,(&__pyx_v_n),(&__pyx_v_n)); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 138; goto __pyx_L1;}
  __pyx_v_data = __pyx_4;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":139 */
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_v_n; ++__pyx_v_k) {

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":140 */
    __pyx_v_expt = exp((__pyx_v_t * (__pyx_v_roots[__pyx_v_k])));

    /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":141 */
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_n; ++__pyx_v_i) {

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":142 */
      __pyx_v_uexpt = ((__pyx_v_evI[((__pyx_v_i * __pyx_v_n) + __pyx_v_k)]) * __pyx_v_expt);

      /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":143 */
      for (__pyx_v_j = 0; __pyx_v_j < __pyx_v_n; ++__pyx_v_j) {
        (__pyx_v_data[((__pyx_v_j * __pyx_v_n) + __pyx_v_i)]) += (__pyx_v_uexpt * (__pyx_v_ev[((__pyx_v_k * __pyx_v_n) + __pyx_v_j)]));
      }
    }
  }

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":145 */
  __pyx_1 = (__pyx_v_n * __pyx_v_n);
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_1; ++__pyx_v_i) {
    __pyx_5 = ((__pyx_v_data[__pyx_v_i]) < 0.0);
    if (__pyx_5) {
      (__pyx_v_data[__pyx_v_i]) = 0.0;
      goto __pyx_L11;
    }
    __pyx_L11:;
  }

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":148 */
  Py_INCREF(__pyx_v_P);
  __pyx_r = __pyx_v_P;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation.EigenExponentiator.__call__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_P);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_tp_new_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)o);
  p->shape = Py_None; Py_INCREF(Py_None);
  p->Q = Py_None; Py_INCREF(Py_None);
  p->roots = Py_None; Py_INCREF(Py_None);
  p->ev = Py_None; Py_INCREF(Py_None);
  p->evT = Py_None; Py_INCREF(Py_None);
  p->evI = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator(PyObject *o) {
  struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *p = (struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)o;
  Py_XDECREF(p->shape);
  Py_XDECREF(p->Q);
  Py_XDECREF(p->roots);
  Py_XDECREF(p->ev);
  Py_XDECREF(p->evT);
  Py_XDECREF(p->evI);
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *p = (struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)o;
  if (p->shape) {
    e = (*v)(p->shape, a); if (e) return e;
  }
  if (p->Q) {
    e = (*v)(p->Q, a); if (e) return e;
  }
  if (p->roots) {
    e = (*v)(p->roots, a); if (e) return e;
  }
  if (p->ev) {
    e = (*v)(p->ev, a); if (e) return e;
  }
  if (p->evT) {
    e = (*v)(p->evT, a); if (e) return e;
  }
  if (p->evI) {
    e = (*v)(p->evI, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator(PyObject *o) {
  struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *p = (struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator *)o;
  PyObject *t;
  t = p->shape; 
  p->shape = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->Q; 
  p->Q = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->roots; 
  p->roots = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->ev; 
  p->ev = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->evT; 
  p->evT = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->evI; 
  p->evI = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static struct PyMethodDef __pyx_methods_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator[] = {
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator[] = {
  {"n", T_INT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, n), READONLY, 0},
  {"shape", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, shape), READONLY, 0},
  {"Q", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, Q), READONLY, 0},
  {"roots", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, roots), READONLY, 0},
  {"ev", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, ev), READONLY, 0},
  {"evT", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, evT), READONLY, 0},
  {"evI", T_OBJECT, offsetof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, evI), READONLY, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_EigenExponentiator = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_EigenExponentiator = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_EigenExponentiator = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_EigenExponentiator = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "cogent.maths._matrix_exponentiation.EigenExponentiator", /*tp_name*/
  sizeof(struct __pyx_obj_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_EigenExponentiator, /*tp_as_number*/
  &__pyx_tp_as_sequence_EigenExponentiator, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_EigenExponentiator, /*tp_as_mapping*/
  0, /*tp_hash*/
  __pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___call__, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_EigenExponentiator, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_traverse*/
  __pyx_tp_clear_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_methods*/
  __pyx_members_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_6cogent_5maths_22_matrix_exponentiation_18EigenExponentiator___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {"setNumPy", (PyCFunction)__pyx_f_6cogent_5maths_22_matrix_exponentiation_setNumPy, METH_VARARGS|METH_KEYWORDS, 0},
  {"inverse", (PyCFunction)__pyx_f_6cogent_5maths_22_matrix_exponentiation_inverse, METH_VARARGS|METH_KEYWORDS, 0},
  {"eigenvectors", (PyCFunction)__pyx_f_6cogent_5maths_22_matrix_exponentiation_eigenvectors, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC init_matrix_exponentiation(void); /*proto*/
PyMODINIT_FUNC init_matrix_exponentiation(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_matrix_exponentiation", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; goto __pyx_L1;};
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_empty = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_zeros = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_contiguous = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_FLOAT = Py_None; Py_INCREF(Py_None);
  __pyx_v_6cogent_5maths_22_matrix_exponentiation_COMPLEX = Py_None; Py_INCREF(Py_None);
  __pyx_type_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "EigenExponentiator", (PyObject *)&__pyx_type_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; goto __pyx_L1;}
  __pyx_ptype_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator = &__pyx_type_6cogent_5maths_22_matrix_exponentiation_EigenExponentiator;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/../../include/numerical_pyrex.pyx":13 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___version__, __pyx_k21p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;}

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":3 */
  __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong(2); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_1 = 0;
  __pyx_2 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_version_info, __pyx_3) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":4 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___version__, __pyx_k21p) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 4; goto __pyx_L1;}

  /* "/Users/mcdonald/ResearchWork/PyCogent-v1.1/cogent/maths/_matrix_exponentiation.pyx":127 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("cogent.maths._matrix_exponentiation");
}

static char *__pyx_filenames[] = {
  "numerical_pyrex.pyx",
  "_matrix_exponentiation.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_WriteUnraisable(char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    PyErr_Fetch(&old_exc, &old_val, &old_tb);
    ctx = PyString_FromString(name);
    PyErr_Restore(old_exc, old_val, old_tb);
    if (!ctx)
        ctx = Py_None;
    PyErr_WriteUnraisable(ctx);
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) type->ob_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
    }
    PyErr_Restore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_Get();
    PyErr_Fetch(type, value, tb);
    PyErr_NormalizeException(type, value, tb);
    if (PyErr_Occurred())
        goto bad;
    Py_INCREF(*type);
    Py_INCREF(*value);
    Py_INCREF(*tb);
    Py_XDECREF(tstate->exc_type);
    Py_XDECREF(tstate->exc_value);
    Py_XDECREF(tstate->exc_traceback);
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
    return 0;
bad:
    Py_XDECREF(*type);
    Py_XDECREF(*value);
    Py_XDECREF(*tb);
    return -1;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        if (!*t->p)
            return -1;
        if (t->i)
            PyString_InternInPlace(t->p);
        ++t;
    }
    return 0;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_tuple = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    
    py_srcfile = PyString_FromString(__pyx_filename);
    if (!py_srcfile) goto bad;
    py_funcname = PyString_FromString(funcname);
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    empty_tuple = PyTuple_New(0);
    if (!empty_tuple) goto bad;
    empty_string = PyString_FromString("");
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        empty_tuple,  /*PyObject *consts,*/
        empty_tuple,  /*PyObject *names,*/
        empty_tuple,  /*PyObject *varnames,*/
        empty_tuple,  /*PyObject *freevars,*/
        empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) 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 = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_tuple);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
