/* Generated by Cython 0.16 on Fri Sep 14 12:12:06 2012 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 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 CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyCFunction_Call PyObject_Call
#else
  #define __Pyx_PyCFunction_Call PyCFunction_Call
#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 PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #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"
#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 > 0x03030000 && defined(PyUnicode_GET_LENGTH)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
#else
  #define CYTHON_PEP393_ENABLED 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]))
#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_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

#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__cogent__evolve___likelihood_tree
#define __PYX_HAVE_API__cogent__evolve___likelihood_tree
#include "array_interface.h"
#include "math.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


/* inline attribute */
#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

/* unused attribute */
#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 long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

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

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))

#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_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;


static const char *__pyx_f[] = {
  "numerical_pyrex.pyx",
  "_likelihood_tree.pyx",
};

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

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":30
 *     int CONTIGUOUS
 * 
 * ctypedef object ArrayType             # <<<<<<<<<<<<<<
 * 
 * cdef double *uncheckedArrayDouble(ArrayType A):
 */
typedef PyObject *__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType;
#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)

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

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 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 PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    if (PyList_CheckExact(o)) {
        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if (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 = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (likely(i >= 0)) {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            return m->sq_item(o, i);
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

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 void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename); /*proto*/

static int __Pyx_check_binary_version(void);

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 'cogent.evolve._likelihood_tree' */
static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, char, int, int, int **); /*proto*/
static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, char, int, int *); /*proto*/
static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray2D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, char, int, int *, int *); /*proto*/
static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray3D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, char, int, int *, int *, int *); /*proto*/
static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray4D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, char, int, int *, int *, int *, int *); /*proto*/
static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, int *); /*proto*/
static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, int *, int *); /*proto*/
static long *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType, int *); /*proto*/
#define __Pyx_MODULE_NAME "cogent.evolve._likelihood_tree"
int __pyx_module_is_main_cogent__evolve___likelihood_tree = 0;

/* Implementation of 'cogent.evolve._likelihood_tree' */
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_sumInputLikelihoods(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_child_indexes, PyObject *__pyx_v_result, PyObject *__pyx_v_likelihoods); /* proto */
static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_2getTotalLogLikelihood(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_counts, PyObject *__pyx_v_input_likelihoods, PyObject *__pyx_v_mprobs); /* proto */
static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_4getLogSumAcrossSites(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_counts, PyObject *__pyx_v_input_likelihoods); /* proto */
static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_6logDotReduce(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_index, PyObject *__pyx_v_patch_probs, PyObject *__pyx_v_switch_probs, PyObject *__pyx_v_plhs); /* proto */
static char __pyx_k_1[] = "Array required, got None";
static char __pyx_k_3[] = "Unexpected array interface version %s";
static char __pyx_k_4[] = "'%s' type array required, got '%s'";
static char __pyx_k_5[] = "'%s%s' type array required, got '%s%s'";
static char __pyx_k_6[] = "%s dimensional array required, got %s";
static char __pyx_k_7[] = "Noncontiguous array";
static char __pyx_k_9[] = "Dimension %s is %s, expected %s";
static char __pyx_k_10[] = "('1', '5', '3')";
static char __pyx_k_14[] = "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/_likelihood_tree.pyx";
static char __pyx_k_15[] = "cogent.evolve._likelihood_tree";
static char __pyx_k_18[] = "getTotalLogLikelihood";
static char __pyx_k_21[] = "getLogSumAcrossSites";
static char __pyx_k__M[] = "M";
static char __pyx_k__S[] = "S";
static char __pyx_k__U[] = "U";
static char __pyx_k__c[] = "c";
static char __pyx_k__i[] = "i";
static char __pyx_k__j[] = "j";
static char __pyx_k__k[] = "k";
static char __pyx_k__m[] = "m";
static char __pyx_k__n[] = "n";
static char __pyx_k__u[] = "u";
static char __pyx_k__pl[] = "pl";
static char __pyx_k__sp[] = "sp";
static char __pyx_k__chr[] = "chr";
static char __pyx_k__tmp[] = "tmp";
static char __pyx_k__BASE[] = "BASE";
static char __pyx_k__copy[] = "copy";
static char __pyx_k__plhs[] = "plhs";
static char __pyx_k__posn[] = "posn";
static char __pyx_k__prev[] = "prev";
static char __pyx_k__site[] = "site";
static char __pyx_k__uniq[] = "uniq";
static char __pyx_k__first[] = "first";
static char __pyx_k__index[] = "index";
static char __pyx_k__state[] = "state";
static char __pyx_k__total[] = "total";
static char __pyx_k__counts[] = "counts";
static char __pyx_k__length[] = "length";
static char __pyx_k__mprobs[] = "mprobs";
static char __pyx_k__result[] = "result";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__exponent[] = "exponent";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__index_data[] = "index_data";
static char __pyx_k____version__[] = "__version__";
static char __pyx_k__likelihoods[] = "likelihoods";
static char __pyx_k__mprobs_data[] = "mprobs_data";
static char __pyx_k__patch_probs[] = "patch_probs";
static char __pyx_k__target_data[] = "target_data";
static char __pyx_k__values_data[] = "values_data";
static char __pyx_k__logDotReduce[] = "logDotReduce";
static char __pyx_k__patch_probs1[] = "patch_probs1";
static char __pyx_k__patch_probs2[] = "patch_probs2";
static char __pyx_k__switch_probs[] = "switch_probs";
static char __pyx_k__version_info[] = "version_info";
static char __pyx_k__weights_data[] = "weights_data";
static char __pyx_k__child_indexes[] = "child_indexes";
static char __pyx_k____array_struct__[] = "__array_struct__";
static char __pyx_k__likelihoods_data[] = "likelihoods_data";
static char __pyx_k__input_likelihoods[] = "input_likelihoods";
static char __pyx_k__most_probable_state[] = "most_probable_state";
static char __pyx_k__sumInputLikelihoods[] = "sumInputLikelihoods";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_n_s_15;
static PyObject *__pyx_n_s_18;
static PyObject *__pyx_n_s_21;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__BASE;
static PyObject *__pyx_n_s__M;
static PyObject *__pyx_n_s__S;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__U;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____array_struct__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s____version__;
static PyObject *__pyx_n_s__c;
static PyObject *__pyx_n_s__child_indexes;
static PyObject *__pyx_n_s__chr;
static PyObject *__pyx_n_s__copy;
static PyObject *__pyx_n_s__counts;
static PyObject *__pyx_n_s__exponent;
static PyObject *__pyx_n_s__first;
static PyObject *__pyx_n_s__i;
static PyObject *__pyx_n_s__index;
static PyObject *__pyx_n_s__index_data;
static PyObject *__pyx_n_s__input_likelihoods;
static PyObject *__pyx_n_s__j;
static PyObject *__pyx_n_s__k;
static PyObject *__pyx_n_s__length;
static PyObject *__pyx_n_s__likelihoods;
static PyObject *__pyx_n_s__likelihoods_data;
static PyObject *__pyx_n_s__logDotReduce;
static PyObject *__pyx_n_s__m;
static PyObject *__pyx_n_s__most_probable_state;
static PyObject *__pyx_n_s__mprobs;
static PyObject *__pyx_n_s__mprobs_data;
static PyObject *__pyx_n_s__n;
static PyObject *__pyx_n_s__patch_probs;
static PyObject *__pyx_n_s__patch_probs1;
static PyObject *__pyx_n_s__patch_probs2;
static PyObject *__pyx_n_s__pl;
static PyObject *__pyx_n_s__plhs;
static PyObject *__pyx_n_s__posn;
static PyObject *__pyx_n_s__prev;
static PyObject *__pyx_n_s__result;
static PyObject *__pyx_n_s__site;
static PyObject *__pyx_n_s__sp;
static PyObject *__pyx_n_s__state;
static PyObject *__pyx_n_s__sumInputLikelihoods;
static PyObject *__pyx_n_s__switch_probs;
static PyObject *__pyx_n_s__target_data;
static PyObject *__pyx_n_s__tmp;
static PyObject *__pyx_n_s__total;
static PyObject *__pyx_n_s__u;
static PyObject *__pyx_n_s__uniq;
static PyObject *__pyx_n_s__values_data;
static PyObject *__pyx_n_s__version_info;
static PyObject *__pyx_n_s__weights_data;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_k_tuple_2;
static PyObject *__pyx_k_tuple_8;
static PyObject *__pyx_k_tuple_11;
static PyObject *__pyx_k_tuple_12;
static PyObject *__pyx_k_tuple_16;
static PyObject *__pyx_k_tuple_19;
static PyObject *__pyx_k_tuple_22;
static PyObject *__pyx_k_codeobj_13;
static PyObject *__pyx_k_codeobj_17;
static PyObject *__pyx_k_codeobj_20;
static PyObject *__pyx_k_codeobj_23;

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":32
 * ctypedef object ArrayType
 * 
 * cdef double *uncheckedArrayDouble(ArrayType A):             # <<<<<<<<<<<<<<
 *     cdef PyArrayInterface *a
 *     cobj = A.__array_struct__
 */

static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_uncheckedArrayDouble(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_A) {
  struct PyArrayInterface *__pyx_v_a;
  PyObject *__pyx_v_cobj = NULL;
  double *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("uncheckedArrayDouble", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":34
 * cdef double *uncheckedArrayDouble(ArrayType A):
 *     cdef PyArrayInterface *a
 *     cobj = A.__array_struct__             # <<<<<<<<<<<<<<
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 *     return <double *> a.data
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_A), __pyx_n_s____array_struct__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_cobj = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":35
 *     cdef PyArrayInterface *a
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)             # <<<<<<<<<<<<<<
 *     return <double *> a.data
 * 
 */
  __pyx_v_a = ((struct PyArrayInterface *)PyCObject_AsVoidPtr(__pyx_v_cobj));

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":36
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 *     return <double *> a.data             # <<<<<<<<<<<<<<
 * 
 * cdef void *checkArray(ArrayType A, char typecode, int itemsize,
 */
  __pyx_r = ((double *)__pyx_v_a->data);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("cogent.evolve._likelihood_tree.uncheckedArrayDouble", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cobj);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":38
 *     return <double *> a.data
 * 
 * cdef void *checkArray(ArrayType A, char typecode, int itemsize,             # <<<<<<<<<<<<<<
 *         int nd, int **dims) except NULL:
 *     cdef PyArrayInterface *a
 */

static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_t_6cogent_6evolve_16_likelihood_tree_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 = NULL;
  char __pyx_v_typecode2;
  int __pyx_v_dimension;
  int __pyx_v_val;
  int *__pyx_v_var;
  void *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArray", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":43
 *     cdef int length, size
 *     cdef char kind
 *     if A is None:             # <<<<<<<<<<<<<<
 *         raise TypeError("Array required, got None")
 *     cobj = A.__array_struct__
 */
  __pyx_t_1 = (__pyx_v_A == ((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)Py_None));
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":44
 *     cdef char kind
 *     if A is None:
 *         raise TypeError("Array required, got None")             # <<<<<<<<<<<<<<
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __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 = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":45
 *     if A is None:
 *         raise TypeError("Array required, got None")
 *     cobj = A.__array_struct__             # <<<<<<<<<<<<<<
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 *     if a.version != 2:
 */
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_A), __pyx_n_s____array_struct__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_cobj = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":46
 *         raise TypeError("Array required, got None")
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)             # <<<<<<<<<<<<<<
 *     if a.version != 2:
 *         raise ValueError(
 */
  __pyx_v_a = ((struct PyArrayInterface *)PyCObject_AsVoidPtr(__pyx_v_cobj));

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":47
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 *     if a.version != 2:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "Unexpected array interface version %s" % str(a.version))
 */
  __pyx_t_1 = (__pyx_v_a->version != 2);
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":49
 *     if a.version != 2:
 *         raise ValueError(
 *             "Unexpected array interface version %s" % str(a.version))             # <<<<<<<<<<<<<<
 *     cdef char typecode2
 *     typecode2 = a.typekind
 */
    __pyx_t_2 = PyInt_FromLong(__pyx_v_a->version); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __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 = 49; __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(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __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 = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 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 = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":51
 *             "Unexpected array interface version %s" % str(a.version))
 *     cdef char typecode2
 *     typecode2 = a.typekind             # <<<<<<<<<<<<<<
 *     if typecode2 != typecode:
 *         raise TypeError("'%s' type array required, got '%s'" %
 */
  __pyx_v_typecode2 = __pyx_v_a->typekind;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":52
 *     cdef char typecode2
 *     typecode2 = a.typekind
 *     if typecode2 != typecode:             # <<<<<<<<<<<<<<
 *         raise TypeError("'%s' type array required, got '%s'" %
 *                 (chr(typecode), chr(typecode2)))
 */
  __pyx_t_1 = (__pyx_v_typecode2 != __pyx_v_typecode);
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":54
 *     if typecode2 != typecode:
 *         raise TypeError("'%s' type array required, got '%s'" %
 *                 (chr(typecode), chr(typecode2)))             # <<<<<<<<<<<<<<
 *     if a.itemsize != itemsize:
 *         raise TypeError("'%s%s' type array required, got '%s%s'" %
 */
    __pyx_t_3 = PyInt_FromLong(__pyx_v_typecode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __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_builtin_chr, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromLong(__pyx_v_typecode2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __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);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_chr, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__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 = 54; __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_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_4), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":55
 *         raise TypeError("'%s' type array required, got '%s'" %
 *                 (chr(typecode), chr(typecode2)))
 *     if a.itemsize != itemsize:             # <<<<<<<<<<<<<<
 *         raise TypeError("'%s%s' type array required, got '%s%s'" %
 *                 (chr(typecode), itemsize, chr(typecode2), a.itemsize))
 */
  __pyx_t_1 = (__pyx_v_a->itemsize != __pyx_v_itemsize);
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":57
 *     if a.itemsize != itemsize:
 *         raise TypeError("'%s%s' type array required, got '%s%s'" %
 *                 (chr(typecode), itemsize, chr(typecode2), a.itemsize))             # <<<<<<<<<<<<<<
 *     if a.nd != nd:
 *         raise ValueError("%s dimensional array required, got %s" %
 */
    __pyx_t_2 = PyInt_FromLong(__pyx_v_typecode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __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);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_chr, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromLong(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_typecode2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __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_builtin_chr, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyInt_FromLong(__pyx_v_a->itemsize); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __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_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_4 = 0;
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_DECREF(((PyObject *)__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 = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":58
 *         raise TypeError("'%s%s' type array required, got '%s%s'" %
 *                 (chr(typecode), itemsize, chr(typecode2), a.itemsize))
 *     if a.nd != nd:             # <<<<<<<<<<<<<<
 *         raise ValueError("%s dimensional array required, got %s" %
 *                 (nd, a.nd))
 */
  __pyx_t_1 = (__pyx_v_a->nd != __pyx_v_nd);
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":60
 *     if a.nd != nd:
 *         raise ValueError("%s dimensional array required, got %s" %
 *                 (nd, a.nd))             # <<<<<<<<<<<<<<
 *     if not a.flags & CONTIGUOUS:
 *         raise ValueError ('Noncontiguous array')
 */
    __pyx_t_5 = PyInt_FromLong(__pyx_v_nd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyInt_FromLong(__pyx_v_a->nd); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __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_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_6), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __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 = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_6));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
    __pyx_t_6 = 0;
    __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":61
 *         raise ValueError("%s dimensional array required, got %s" %
 *                 (nd, a.nd))
 *     if not a.flags & CONTIGUOUS:             # <<<<<<<<<<<<<<
 *         raise ValueError ('Noncontiguous array')
 * 
 */
  __pyx_t_1 = (!(__pyx_v_a->flags & CONTIGUOUS));
  if (__pyx_t_1) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":62
 *                 (nd, a.nd))
 *     if not a.flags & CONTIGUOUS:
 *         raise ValueError ('Noncontiguous array')             # <<<<<<<<<<<<<<
 * 
 *     cdef int dimension, val
 */
    __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":66
 *     cdef int dimension, val
 *     cdef int *var
 *     for dimension from 0 <= dimension < nd:             # <<<<<<<<<<<<<<
 *         val = a.shape[dimension]
 *         var = dims[dimension]
 */
  __pyx_t_7 = __pyx_v_nd;
  for (__pyx_v_dimension = 0; __pyx_v_dimension < __pyx_t_7; __pyx_v_dimension++) {

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":67
 *     cdef int *var
 *     for dimension from 0 <= dimension < nd:
 *         val = a.shape[dimension]             # <<<<<<<<<<<<<<
 *         var = dims[dimension]
 *         if var[0] == 0:
 */
    __pyx_v_val = (__pyx_v_a->shape[__pyx_v_dimension]);

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":68
 *     for dimension from 0 <= dimension < nd:
 *         val = a.shape[dimension]
 *         var = dims[dimension]             # <<<<<<<<<<<<<<
 *         if var[0] == 0:
 *             # Length unspecified, take it from the provided array
 */
    __pyx_v_var = (__pyx_v_dims[__pyx_v_dimension]);

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":69
 *         val = a.shape[dimension]
 *         var = dims[dimension]
 *         if var[0] == 0:             # <<<<<<<<<<<<<<
 *             # Length unspecified, take it from the provided array
 *             var[0] = val
 */
    __pyx_t_1 = ((__pyx_v_var[0]) == 0);
    if (__pyx_t_1) {

      /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":71
 *         if var[0] == 0:
 *             # Length unspecified, take it from the provided array
 *             var[0] = val             # <<<<<<<<<<<<<<
 *         elif var[0] != val:
 *             # Length already specified, but not the same
 */
      (__pyx_v_var[0]) = __pyx_v_val;
      goto __pyx_L11;
    }

    /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":72
 *             # Length unspecified, take it from the provided array
 *             var[0] = val
 *         elif var[0] != val:             # <<<<<<<<<<<<<<
 *             # Length already specified, but not the same
 *             raise ValueError("Dimension %s is %s, expected %s" %
 */
    __pyx_t_1 = ((__pyx_v_var[0]) != __pyx_v_val);
    if (__pyx_t_1) {

      /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":75
 *             # Length already specified, but not the same
 *             raise ValueError("Dimension %s is %s, expected %s" %
 *                     (dimension, val, var[0]))             # <<<<<<<<<<<<<<
 *         else:
 *             # Length matches what was expected
 */
      __pyx_t_6 = PyInt_FromLong(__pyx_v_dimension); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyInt_FromLong((__pyx_v_var[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_6 = 0;
      __pyx_t_3 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 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_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L11;
    }
    /*else*/ {
    }
    __pyx_L11:;
  }

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":79
 *             # Length matches what was expected
 *             pass
 *     return a.data             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_a->data;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArray", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cobj);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":82
 * 
 * 
 * cdef void *checkArray1D(ArrayType a, char typecode, int size,             # <<<<<<<<<<<<<<
 *         int *x) except NULL:
 *     cdef int *dims[1]
 */

static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, char __pyx_v_typecode, int __pyx_v_size, int *__pyx_v_x) {
  int *__pyx_v_dims[1];
  void *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArray1D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":85
 *         int *x) except NULL:
 *     cdef int *dims[1]
 *     dims[0] = x             # <<<<<<<<<<<<<<
 *     return checkArray(a, typecode, size, 1, dims)
 * 
 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":86
 *     cdef int *dims[1]
 *     dims[0] = x
 *     return checkArray(a, typecode, size, 1, dims)             # <<<<<<<<<<<<<<
 * 
 * cdef void *checkArray2D(ArrayType a, char typecode, int size,
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_v_a, __pyx_v_typecode, __pyx_v_size, 1, __pyx_v_dims); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArray1D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":88
 *     return checkArray(a, typecode, size, 1, dims)
 * 
 * cdef void *checkArray2D(ArrayType a, char typecode, int size,             # <<<<<<<<<<<<<<
 *         int *x, int *y) except NULL:
 *     cdef int *dims[2]
 */

static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray2D(__pyx_t_6cogent_6evolve_16_likelihood_tree_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;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArray2D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":91
 *         int *x, int *y) except NULL:
 *     cdef int *dims[2]
 *     dims[0] = x             # <<<<<<<<<<<<<<
 *     dims[1] = y
 *     return checkArray(a, typecode, size, 2, dims)
 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":92
 *     cdef int *dims[2]
 *     dims[0] = x
 *     dims[1] = y             # <<<<<<<<<<<<<<
 *     return checkArray(a, typecode, size, 2, dims)
 * 
 */
  (__pyx_v_dims[1]) = __pyx_v_y;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":93
 *     dims[0] = x
 *     dims[1] = y
 *     return checkArray(a, typecode, size, 2, dims)             # <<<<<<<<<<<<<<
 * 
 * cdef void *checkArray3D(ArrayType a, char typecode, int size,
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_v_a, __pyx_v_typecode, __pyx_v_size, 2, __pyx_v_dims); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArray2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":95
 *     return checkArray(a, typecode, size, 2, dims)
 * 
 * cdef void *checkArray3D(ArrayType a, char typecode, int size,             # <<<<<<<<<<<<<<
 *         int *x, int *y, int *z) except NULL:
 *     cdef int *dims[3]
 */

static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray3D(__pyx_t_6cogent_6evolve_16_likelihood_tree_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;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArray3D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":98
 *         int *x, int *y, int *z) except NULL:
 *     cdef int *dims[3]
 *     dims[0] = x             # <<<<<<<<<<<<<<
 *     dims[1] = y
 *     dims[2] = z
 */
  (__pyx_v_dims[0]) = __pyx_v_x;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":99
 *     cdef int *dims[3]
 *     dims[0] = x
 *     dims[1] = y             # <<<<<<<<<<<<<<
 *     dims[2] = z
 *     return checkArray(a, typecode, size, 3, dims)
 */
  (__pyx_v_dims[1]) = __pyx_v_y;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":100
 *     dims[0] = x
 *     dims[1] = y
 *     dims[2] = z             # <<<<<<<<<<<<<<
 *     return checkArray(a, typecode, size, 3, dims)
 * 
 */
  (__pyx_v_dims[2]) = __pyx_v_z;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":101
 *     dims[1] = y
 *     dims[2] = z
 *     return checkArray(a, typecode, size, 3, dims)             # <<<<<<<<<<<<<<
 * 
 * cdef void *checkArray4D(ArrayType a, char typecode, int size,
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_v_a, __pyx_v_typecode, __pyx_v_size, 3, __pyx_v_dims); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArray3D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":103
 *     return checkArray(a, typecode, size, 3, dims)
 * 
 * cdef void *checkArray4D(ArrayType a, char typecode, int size,             # <<<<<<<<<<<<<<
 *         int *w, int *x, int *y, int *z) except NULL:
 *     cdef int *dims[4]
 */

static void *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray4D(__pyx_t_6cogent_6evolve_16_likelihood_tree_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;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArray4D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":106
 *         int *w, int *x, int *y, int *z) except NULL:
 *     cdef int *dims[4]
 *     dims[0] = w             # <<<<<<<<<<<<<<
 *     dims[1] = x
 *     dims[2] = y
 */
  (__pyx_v_dims[0]) = __pyx_v_w;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":107
 *     cdef int *dims[4]
 *     dims[0] = w
 *     dims[1] = x             # <<<<<<<<<<<<<<
 *     dims[2] = y
 *     dims[3] = z
 */
  (__pyx_v_dims[1]) = __pyx_v_x;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":108
 *     dims[0] = w
 *     dims[1] = x
 *     dims[2] = y             # <<<<<<<<<<<<<<
 *     dims[3] = z
 *     return checkArray(a, typecode, size, 4, dims)
 */
  (__pyx_v_dims[2]) = __pyx_v_y;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":109
 *     dims[1] = x
 *     dims[2] = y
 *     dims[3] = z             # <<<<<<<<<<<<<<
 *     return checkArray(a, typecode, size, 4, dims)
 * 
 */
  (__pyx_v_dims[3]) = __pyx_v_z;

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":110
 *     dims[2] = y
 *     dims[3] = z
 *     return checkArray(a, typecode, size, 4, dims)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray(__pyx_v_a, __pyx_v_typecode, __pyx_v_size, 4, __pyx_v_dims); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArray4D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":113
 * 
 * 
 * cdef double * checkArrayDouble1D(ArrayType a, int *x) except NULL:             # <<<<<<<<<<<<<<
 *     return <double *> checkArray1D(a, c'f', sizeof(double), x)
 * 
 */

static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x) {
  double *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayDouble1D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":114
 * 
 * cdef double * checkArrayDouble1D(ArrayType a, int *x) except NULL:
 *     return <double *> checkArray1D(a, c'f', sizeof(double), x)             # <<<<<<<<<<<<<<
 * 
 * cdef double * checkArrayDouble2D(ArrayType a, int *x, int *y) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray1D(__pyx_v_a, 'f', (sizeof(double)), __pyx_v_x); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((double *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayDouble1D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":116
 *     return <double *> checkArray1D(a, c'f', sizeof(double), x)
 * 
 * cdef double * checkArrayDouble2D(ArrayType a, int *x, int *y) except NULL:             # <<<<<<<<<<<<<<
 *     return <double *> checkArray2D(a, c'f', sizeof(double), x, y)
 * 
 */

static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) {
  double *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayDouble2D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":117
 * 
 * cdef double * checkArrayDouble2D(ArrayType a, int *x, int *y) except NULL:
 *     return <double *> checkArray2D(a, c'f', sizeof(double), x, y)             # <<<<<<<<<<<<<<
 * 
 * cdef double * checkArrayDouble3D(ArrayType a, int *x, int *y, int *z) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray2D(__pyx_v_a, 'f', (sizeof(double)), __pyx_v_x, __pyx_v_y); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((double *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayDouble2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":119
 *     return <double *> checkArray2D(a, c'f', sizeof(double), x, y)
 * 
 * cdef double * checkArrayDouble3D(ArrayType a, int *x, int *y, int *z) except NULL:             # <<<<<<<<<<<<<<
 *     return <double *> checkArray3D(a, c'f', sizeof(double), x, y, z)
 * 
 */

static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble3D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) {
  double *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayDouble3D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":120
 * 
 * cdef double * checkArrayDouble3D(ArrayType a, int *x, int *y, int *z) except NULL:
 *     return <double *> checkArray3D(a, c'f', sizeof(double), x, y, z)             # <<<<<<<<<<<<<<
 * 
 * cdef double * checkArrayDouble4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray3D(__pyx_v_a, 'f', (sizeof(double)), __pyx_v_x, __pyx_v_y, __pyx_v_z); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((double *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayDouble3D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":122
 *     return <double *> checkArray3D(a, c'f', sizeof(double), x, y, z)
 * 
 * cdef double * checkArrayDouble4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:             # <<<<<<<<<<<<<<
 *     return <double *> checkArray4D(a, c'f', sizeof(double), w, x, y, z)
 * 
 */

static double *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble4D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_w, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) {
  double *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayDouble4D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":123
 * 
 * cdef double * checkArrayDouble4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:
 *     return <double *> checkArray4D(a, c'f', sizeof(double), w, x, y, z)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray4D(__pyx_v_a, 'f', (sizeof(double)), __pyx_v_w, __pyx_v_x, __pyx_v_y, __pyx_v_z); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((double *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayDouble4D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":126
 * 
 * 
 * cdef long * checkArrayLong1D(ArrayType a, int *x) except NULL:             # <<<<<<<<<<<<<<
 *     return <long *> checkArray1D(a, c'i', sizeof(long), x)
 * 
 */

static long *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong1D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x) {
  long *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayLong1D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":127
 * 
 * cdef long * checkArrayLong1D(ArrayType a, int *x) except NULL:
 *     return <long *> checkArray1D(a, c'i', sizeof(long), x)             # <<<<<<<<<<<<<<
 * 
 * cdef long * checkArrayLong2D(ArrayType a, int *x, int *y) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray1D(__pyx_v_a, 'i', (sizeof(long)), __pyx_v_x); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((long *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayLong1D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":129
 *     return <long *> checkArray1D(a, c'i', sizeof(long), x)
 * 
 * cdef long * checkArrayLong2D(ArrayType a, int *x, int *y) except NULL:             # <<<<<<<<<<<<<<
 *     return <long *> checkArray2D(a, c'i', sizeof(long), x, y)
 * 
 */

static long *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong2D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y) {
  long *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayLong2D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":130
 * 
 * cdef long * checkArrayLong2D(ArrayType a, int *x, int *y) except NULL:
 *     return <long *> checkArray2D(a, c'i', sizeof(long), x, y)             # <<<<<<<<<<<<<<
 * 
 * cdef long * checkArrayLong3D(ArrayType a, int *x, int *y, int *z) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray2D(__pyx_v_a, 'i', (sizeof(long)), __pyx_v_x, __pyx_v_y); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((long *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayLong2D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":132
 *     return <long *> checkArray2D(a, c'i', sizeof(long), x, y)
 * 
 * cdef long * checkArrayLong3D(ArrayType a, int *x, int *y, int *z) except NULL:             # <<<<<<<<<<<<<<
 *     return <long *> checkArray3D(a, c'i', sizeof(long), x, y, z)
 * 
 */

static long *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong3D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) {
  long *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayLong3D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":133
 * 
 * cdef long * checkArrayLong3D(ArrayType a, int *x, int *y, int *z) except NULL:
 *     return <long *> checkArray3D(a, c'i', sizeof(long), x, y, z)             # <<<<<<<<<<<<<<
 * 
 * cdef long * checkArrayLong4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray3D(__pyx_v_a, 'i', (sizeof(long)), __pyx_v_x, __pyx_v_y, __pyx_v_z); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((long *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayLong3D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":135
 *     return <long *> checkArray3D(a, c'i', sizeof(long), x, y, z)
 * 
 * cdef long * checkArrayLong4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:             # <<<<<<<<<<<<<<
 *     return <long *> checkArray4D(a, c'i', sizeof(long), w, x, y, z)
 */

static long *__pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong4D(__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType __pyx_v_a, int *__pyx_v_w, int *__pyx_v_x, int *__pyx_v_y, int *__pyx_v_z) {
  long *__pyx_r;
  __Pyx_RefNannyDeclarations
  void *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("checkArrayLong4D", 0);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":136
 * 
 * cdef long * checkArrayLong4D(ArrayType a, int *w, int *x, int *y, int *z) except NULL:
 *     return <long *> checkArray4D(a, c'i', sizeof(long), w, x, y, z)             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArray4D(__pyx_v_a, 'i', (sizeof(long)), __pyx_v_w, __pyx_v_x, __pyx_v_y, __pyx_v_z); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((long *)__pyx_t_1);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.checkArrayLong4D", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_1sumInputLikelihoods(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6cogent_6evolve_16_likelihood_tree_1sumInputLikelihoods = {__Pyx_NAMESTR("sumInputLikelihoods"), (PyCFunction)__pyx_pw_6cogent_6evolve_16_likelihood_tree_1sumInputLikelihoods, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_1sumInputLikelihoods(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_child_indexes = 0;
  PyObject *__pyx_v_result = 0;
  PyObject *__pyx_v_likelihoods = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_indexes,&__pyx_n_s__result,&__pyx_n_s__likelihoods,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sumInputLikelihoods (wrapper)", 0);
  __pyx_self = __pyx_self;
  {
    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:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_indexes);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__result);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sumInputLikelihoods", 1, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__likelihoods);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sumInputLikelihoods", 1, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sumInputLikelihoods") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __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_child_indexes = values[0];
    __pyx_v_result = values[1];
    __pyx_v_likelihoods = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sumInputLikelihoods", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.sumInputLikelihoods", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cogent_6evolve_16_likelihood_tree_sumInputLikelihoods(__pyx_self, __pyx_v_child_indexes, __pyx_v_result, __pyx_v_likelihoods);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cogent/evolve/_likelihood_tree.pyx":8
 *     double log (double x)
 * 
 * def sumInputLikelihoods(child_indexes, result, likelihoods):             # <<<<<<<<<<<<<<
 *     # M is dim of alphabet, S is non-redundandt parent seq length,
 *     # U is length
 */

static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_sumInputLikelihoods(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_child_indexes, PyObject *__pyx_v_result, PyObject *__pyx_v_likelihoods) {
  int __pyx_v_M;
  int __pyx_v_S;
  int __pyx_v_U;
  int __pyx_v_m;
  int __pyx_v_i;
  int __pyx_v_u;
  int __pyx_v_c;
  double *__pyx_v_values_data;
  long *__pyx_v_index_data;
  double *__pyx_v_target_data;
  CYTHON_UNUSED long __pyx_v_first;
  PyObject *__pyx_v_index = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  double *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  long *__pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sumInputLikelihoods", 0);

  /* "cogent/evolve/_likelihood_tree.pyx":18
 *     cdef double *target_data
 * 
 *     M = S = 0             # <<<<<<<<<<<<<<
 *     target_data = checkArrayDouble2D(result, &S, &M)
 *     first = 1
 */
  __pyx_v_M = 0;
  __pyx_v_S = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":19
 * 
 *     M = S = 0
 *     target_data = checkArrayDouble2D(result, &S, &M)             # <<<<<<<<<<<<<<
 *     first = 1
 *     c = 0
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_result), (&__pyx_v_S), (&__pyx_v_M)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_target_data = __pyx_t_1;

  /* "cogent/evolve/_likelihood_tree.pyx":20
 *     M = S = 0
 *     target_data = checkArrayDouble2D(result, &S, &M)
 *     first = 1             # <<<<<<<<<<<<<<
 *     c = 0
 *     for index in child_indexes:
 */
  __pyx_v_first = 1;

  /* "cogent/evolve/_likelihood_tree.pyx":21
 *     target_data = checkArrayDouble2D(result, &S, &M)
 *     first = 1
 *     c = 0             # <<<<<<<<<<<<<<
 *     for index in child_indexes:
 *         U = 0
 */
  __pyx_v_c = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":22
 *     first = 1
 *     c = 0
 *     for index in child_indexes:             # <<<<<<<<<<<<<<
 *         U = 0
 *         index_data = checkArrayLong1D(index, &S)
 */
  if (PyList_CheckExact(__pyx_v_child_indexes) || PyTuple_CheckExact(__pyx_v_child_indexes)) {
    __pyx_t_2 = __pyx_v_child_indexes; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_child_indexes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  for (;;) {
    if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++;
    } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++;
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_5)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF(__pyx_v_index);
    __pyx_v_index = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "cogent/evolve/_likelihood_tree.pyx":23
 *     c = 0
 *     for index in child_indexes:
 *         U = 0             # <<<<<<<<<<<<<<
 *         index_data = checkArrayLong1D(index, &S)
 *         values_data = checkArrayDouble2D(likelihoods[c], &U, &M)
 */
    __pyx_v_U = 0;

    /* "cogent/evolve/_likelihood_tree.pyx":24
 *     for index in child_indexes:
 *         U = 0
 *         index_data = checkArrayLong1D(index, &S)             # <<<<<<<<<<<<<<
 *         values_data = checkArrayDouble2D(likelihoods[c], &U, &M)
 *         #if index_data[S-1] >= U:
 */
    __pyx_t_6 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_index), (&__pyx_v_S)); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_index_data = __pyx_t_6;

    /* "cogent/evolve/_likelihood_tree.pyx":25
 *         U = 0
 *         index_data = checkArrayLong1D(index, &S)
 *         values_data = checkArrayDouble2D(likelihoods[c], &U, &M)             # <<<<<<<<<<<<<<
 *         #if index_data[S-1] >= U:
 *         #    raise RangeError
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_likelihoods, __pyx_v_c, sizeof(int), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_t_5), (&__pyx_v_U), (&__pyx_v_M)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_values_data = __pyx_t_1;

    /* "cogent/evolve/_likelihood_tree.pyx":28
 *         #if index_data[S-1] >= U:
 *         #    raise RangeError
 *         if c == 0:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < S:
 *                 u = index_data[i]
 */
    __pyx_t_7 = (__pyx_v_c == 0);
    if (__pyx_t_7) {

      /* "cogent/evolve/_likelihood_tree.pyx":29
 *         #    raise RangeError
 *         if c == 0:
 *             for i from 0 <= i < S:             # <<<<<<<<<<<<<<
 *                 u = index_data[i]
 *                 for m from 0 <= m < M:
 */
      __pyx_t_8 = __pyx_v_S;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "cogent/evolve/_likelihood_tree.pyx":30
 *         if c == 0:
 *             for i from 0 <= i < S:
 *                 u = index_data[i]             # <<<<<<<<<<<<<<
 *                 for m from 0 <= m < M:
 *                     target_data[M*i+m] = values_data[M*u+m]
 */
        __pyx_v_u = (__pyx_v_index_data[__pyx_v_i]);

        /* "cogent/evolve/_likelihood_tree.pyx":31
 *             for i from 0 <= i < S:
 *                 u = index_data[i]
 *                 for m from 0 <= m < M:             # <<<<<<<<<<<<<<
 *                     target_data[M*i+m] = values_data[M*u+m]
 *         else:
 */
        __pyx_t_9 = __pyx_v_M;
        for (__pyx_v_m = 0; __pyx_v_m < __pyx_t_9; __pyx_v_m++) {

          /* "cogent/evolve/_likelihood_tree.pyx":32
 *                 u = index_data[i]
 *                 for m from 0 <= m < M:
 *                     target_data[M*i+m] = values_data[M*u+m]             # <<<<<<<<<<<<<<
 *         else:
 *             for i from 0 <= i < S: # col of parent data
 */
          (__pyx_v_target_data[((__pyx_v_M * __pyx_v_i) + __pyx_v_m)]) = (__pyx_v_values_data[((__pyx_v_M * __pyx_v_u) + __pyx_v_m)]);
        }
      }
      goto __pyx_L5;
    }
    /*else*/ {

      /* "cogent/evolve/_likelihood_tree.pyx":34
 *                     target_data[M*i+m] = values_data[M*u+m]
 *         else:
 *             for i from 0 <= i < S: # col of parent data             # <<<<<<<<<<<<<<
 *                 u = index_data[i] # col of childs data
 *                 for m from 0 <= m < M:
 */
      __pyx_t_8 = __pyx_v_S;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "cogent/evolve/_likelihood_tree.pyx":35
 *         else:
 *             for i from 0 <= i < S: # col of parent data
 *                 u = index_data[i] # col of childs data             # <<<<<<<<<<<<<<
 *                 for m from 0 <= m < M:
 *                     target_data[M*i+m] *= values_data[M*u+m]
 */
        __pyx_v_u = (__pyx_v_index_data[__pyx_v_i]);

        /* "cogent/evolve/_likelihood_tree.pyx":36
 *             for i from 0 <= i < S: # col of parent data
 *                 u = index_data[i] # col of childs data
 *                 for m from 0 <= m < M:             # <<<<<<<<<<<<<<
 *                     target_data[M*i+m] *= values_data[M*u+m]
 *         c += 1
 */
        __pyx_t_9 = __pyx_v_M;
        for (__pyx_v_m = 0; __pyx_v_m < __pyx_t_9; __pyx_v_m++) {

          /* "cogent/evolve/_likelihood_tree.pyx":37
 *                 u = index_data[i] # col of childs data
 *                 for m from 0 <= m < M:
 *                     target_data[M*i+m] *= values_data[M*u+m]             # <<<<<<<<<<<<<<
 *         c += 1
 *     return result
 */
          __pyx_t_10 = ((__pyx_v_M * __pyx_v_i) + __pyx_v_m);
          (__pyx_v_target_data[__pyx_t_10]) = ((__pyx_v_target_data[__pyx_t_10]) * (__pyx_v_values_data[((__pyx_v_M * __pyx_v_u) + __pyx_v_m)]));
        }
      }
    }
    __pyx_L5:;

    /* "cogent/evolve/_likelihood_tree.pyx":38
 *                 for m from 0 <= m < M:
 *                     target_data[M*i+m] *= values_data[M*u+m]
 *         c += 1             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
    __pyx_v_c = (__pyx_v_c + 1);
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":39
 *                     target_data[M*i+m] *= values_data[M*u+m]
 *         c += 1
 *     return result             # <<<<<<<<<<<<<<
 * 
 * def getTotalLogLikelihood(counts, input_likelihoods, mprobs):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  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_5);
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.sumInputLikelihoods", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_index);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_3getTotalLogLikelihood(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6cogent_6evolve_16_likelihood_tree_3getTotalLogLikelihood = {__Pyx_NAMESTR("getTotalLogLikelihood"), (PyCFunction)__pyx_pw_6cogent_6evolve_16_likelihood_tree_3getTotalLogLikelihood, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_3getTotalLogLikelihood(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_counts = 0;
  PyObject *__pyx_v_input_likelihoods = 0;
  PyObject *__pyx_v_mprobs = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__counts,&__pyx_n_s__input_likelihoods,&__pyx_n_s__mprobs,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getTotalLogLikelihood (wrapper)", 0);
  __pyx_self = __pyx_self;
  {
    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:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__counts);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__input_likelihoods);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getTotalLogLikelihood", 1, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mprobs);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getTotalLogLikelihood", 1, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getTotalLogLikelihood") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __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_counts = values[0];
    __pyx_v_input_likelihoods = values[1];
    __pyx_v_mprobs = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getTotalLogLikelihood", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.getTotalLogLikelihood", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cogent_6evolve_16_likelihood_tree_2getTotalLogLikelihood(__pyx_self, __pyx_v_counts, __pyx_v_input_likelihoods, __pyx_v_mprobs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cogent/evolve/_likelihood_tree.pyx":41
 *     return result
 * 
 * def getTotalLogLikelihood(counts, input_likelihoods, mprobs):             # <<<<<<<<<<<<<<
 *     cdef int S, M, i, m
 *     cdef double posn, total
 */

static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_2getTotalLogLikelihood(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_counts, PyObject *__pyx_v_input_likelihoods, PyObject *__pyx_v_mprobs) {
  int __pyx_v_S;
  int __pyx_v_M;
  int __pyx_v_i;
  int __pyx_v_m;
  double __pyx_v_posn;
  double __pyx_v_total;
  double *__pyx_v_likelihoods_data;
  double *__pyx_v_mprobs_data;
  double *__pyx_v_weights_data;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  double *__pyx_t_1;
  double *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getTotalLogLikelihood", 0);

  /* "cogent/evolve/_likelihood_tree.pyx":46
 *     cdef double *likelihoods_data, *mprobs_data, *weights_data
 * 
 *     S = M = 0             # <<<<<<<<<<<<<<
 *     mprobs_data = checkArrayDouble1D(mprobs, &M)
 *     weights_data = checkArrayDouble1D(counts, &S)
 */
  __pyx_v_S = 0;
  __pyx_v_M = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":47
 * 
 *     S = M = 0
 *     mprobs_data = checkArrayDouble1D(mprobs, &M)             # <<<<<<<<<<<<<<
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble2D(input_likelihoods, &S, &M)
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_mprobs), (&__pyx_v_M)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_mprobs_data = __pyx_t_1;

  /* "cogent/evolve/_likelihood_tree.pyx":48
 *     S = M = 0
 *     mprobs_data = checkArrayDouble1D(mprobs, &M)
 *     weights_data = checkArrayDouble1D(counts, &S)             # <<<<<<<<<<<<<<
 *     likelihoods_data = checkArrayDouble2D(input_likelihoods, &S, &M)
 *     total = 0.0
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_counts), (&__pyx_v_S)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_weights_data = __pyx_t_1;

  /* "cogent/evolve/_likelihood_tree.pyx":49
 *     mprobs_data = checkArrayDouble1D(mprobs, &M)
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble2D(input_likelihoods, &S, &M)             # <<<<<<<<<<<<<<
 *     total = 0.0
 *     for i from 0 <= i < S:
 */
  __pyx_t_2 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_input_likelihoods), (&__pyx_v_S), (&__pyx_v_M)); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_likelihoods_data = __pyx_t_2;

  /* "cogent/evolve/_likelihood_tree.pyx":50
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble2D(input_likelihoods, &S, &M)
 *     total = 0.0             # <<<<<<<<<<<<<<
 *     for i from 0 <= i < S:
 *         posn = 0.0
 */
  __pyx_v_total = 0.0;

  /* "cogent/evolve/_likelihood_tree.pyx":51
 *     likelihoods_data = checkArrayDouble2D(input_likelihoods, &S, &M)
 *     total = 0.0
 *     for i from 0 <= i < S:             # <<<<<<<<<<<<<<
 *         posn = 0.0
 *         for m from 0 <= m < M:
 */
  __pyx_t_3 = __pyx_v_S;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) {

    /* "cogent/evolve/_likelihood_tree.pyx":52
 *     total = 0.0
 *     for i from 0 <= i < S:
 *         posn = 0.0             # <<<<<<<<<<<<<<
 *         for m from 0 <= m < M:
 *             posn += likelihoods_data[i*M+m] * mprobs_data[m]
 */
    __pyx_v_posn = 0.0;

    /* "cogent/evolve/_likelihood_tree.pyx":53
 *     for i from 0 <= i < S:
 *         posn = 0.0
 *         for m from 0 <= m < M:             # <<<<<<<<<<<<<<
 *             posn += likelihoods_data[i*M+m] * mprobs_data[m]
 *         total += log(posn)*weights_data[i]
 */
    __pyx_t_4 = __pyx_v_M;
    for (__pyx_v_m = 0; __pyx_v_m < __pyx_t_4; __pyx_v_m++) {

      /* "cogent/evolve/_likelihood_tree.pyx":54
 *         posn = 0.0
 *         for m from 0 <= m < M:
 *             posn += likelihoods_data[i*M+m] * mprobs_data[m]             # <<<<<<<<<<<<<<
 *         total += log(posn)*weights_data[i]
 *     return total
 */
      __pyx_v_posn = (__pyx_v_posn + ((__pyx_v_likelihoods_data[((__pyx_v_i * __pyx_v_M) + __pyx_v_m)]) * (__pyx_v_mprobs_data[__pyx_v_m])));
    }

    /* "cogent/evolve/_likelihood_tree.pyx":55
 *         for m from 0 <= m < M:
 *             posn += likelihoods_data[i*M+m] * mprobs_data[m]
 *         total += log(posn)*weights_data[i]             # <<<<<<<<<<<<<<
 *     return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + (log(__pyx_v_posn) * (__pyx_v_weights_data[__pyx_v_i])));
  }

  /* "cogent/evolve/_likelihood_tree.pyx":56
 *             posn += likelihoods_data[i*M+m] * mprobs_data[m]
 *         total += log(posn)*weights_data[i]
 *     return total             # <<<<<<<<<<<<<<
 * 
 * def getLogSumAcrossSites(counts, input_likelihoods):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __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_5);
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.getTotalLogLikelihood", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_5getLogSumAcrossSites(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6cogent_6evolve_16_likelihood_tree_5getLogSumAcrossSites = {__Pyx_NAMESTR("getLogSumAcrossSites"), (PyCFunction)__pyx_pw_6cogent_6evolve_16_likelihood_tree_5getLogSumAcrossSites, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_5getLogSumAcrossSites(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_counts = 0;
  PyObject *__pyx_v_input_likelihoods = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__counts,&__pyx_n_s__input_likelihoods,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getLogSumAcrossSites (wrapper)", 0);
  __pyx_self = __pyx_self;
  {
    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:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__counts);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__input_likelihoods);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getLogSumAcrossSites", 1, 2, 2, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getLogSumAcrossSites") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __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_counts = values[0];
    __pyx_v_input_likelihoods = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getLogSumAcrossSites", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.getLogSumAcrossSites", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cogent_6evolve_16_likelihood_tree_4getLogSumAcrossSites(__pyx_self, __pyx_v_counts, __pyx_v_input_likelihoods);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cogent/evolve/_likelihood_tree.pyx":58
 *     return total
 * 
 * def getLogSumAcrossSites(counts, input_likelihoods):             # <<<<<<<<<<<<<<
 *     cdef int S, i
 *     cdef double total
 */

static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_4getLogSumAcrossSites(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_counts, PyObject *__pyx_v_input_likelihoods) {
  int __pyx_v_S;
  int __pyx_v_i;
  double __pyx_v_total;
  double *__pyx_v_likelihoods_data;
  double *__pyx_v_weights_data;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  double *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getLogSumAcrossSites", 0);

  /* "cogent/evolve/_likelihood_tree.pyx":62
 *     cdef double total
 *     cdef double *likelihoods_data,  *weights_data
 *     S = 0             # <<<<<<<<<<<<<<
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble1D(input_likelihoods, &S)
 */
  __pyx_v_S = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":63
 *     cdef double *likelihoods_data,  *weights_data
 *     S = 0
 *     weights_data = checkArrayDouble1D(counts, &S)             # <<<<<<<<<<<<<<
 *     likelihoods_data = checkArrayDouble1D(input_likelihoods, &S)
 *     total = 0.0
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_counts), (&__pyx_v_S)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_weights_data = __pyx_t_1;

  /* "cogent/evolve/_likelihood_tree.pyx":64
 *     S = 0
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble1D(input_likelihoods, &S)             # <<<<<<<<<<<<<<
 *     total = 0.0
 *     for i from 0 <= i < S:
 */
  __pyx_t_1 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_input_likelihoods), (&__pyx_v_S)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_likelihoods_data = __pyx_t_1;

  /* "cogent/evolve/_likelihood_tree.pyx":65
 *     weights_data = checkArrayDouble1D(counts, &S)
 *     likelihoods_data = checkArrayDouble1D(input_likelihoods, &S)
 *     total = 0.0             # <<<<<<<<<<<<<<
 *     for i from 0 <= i < S:
 *         total += log(likelihoods_data[i])*weights_data[i]
 */
  __pyx_v_total = 0.0;

  /* "cogent/evolve/_likelihood_tree.pyx":66
 *     likelihoods_data = checkArrayDouble1D(input_likelihoods, &S)
 *     total = 0.0
 *     for i from 0 <= i < S:             # <<<<<<<<<<<<<<
 *         total += log(likelihoods_data[i])*weights_data[i]
 *     return total
 */
  __pyx_t_2 = __pyx_v_S;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

    /* "cogent/evolve/_likelihood_tree.pyx":67
 *     total = 0.0
 *     for i from 0 <= i < S:
 *         total += log(likelihoods_data[i])*weights_data[i]             # <<<<<<<<<<<<<<
 *     return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + (log((__pyx_v_likelihoods_data[__pyx_v_i])) * (__pyx_v_weights_data[__pyx_v_i])));
  }

  /* "cogent/evolve/_likelihood_tree.pyx":68
 *     for i from 0 <= i < S:
 *         total += log(likelihoods_data[i])*weights_data[i]
 *     return total             # <<<<<<<<<<<<<<
 * 
 * def logDotReduce(index, patch_probs, switch_probs, plhs):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __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_3);
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.getLogSumAcrossSites", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_7logDotReduce(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_6cogent_6evolve_16_likelihood_tree_7logDotReduce = {__Pyx_NAMESTR("logDotReduce"), (PyCFunction)__pyx_pw_6cogent_6evolve_16_likelihood_tree_7logDotReduce, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_6cogent_6evolve_16_likelihood_tree_7logDotReduce(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_index = 0;
  PyObject *__pyx_v_patch_probs = 0;
  PyObject *__pyx_v_switch_probs = 0;
  PyObject *__pyx_v_plhs = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__index,&__pyx_n_s__patch_probs,&__pyx_n_s__switch_probs,&__pyx_n_s__plhs,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("logDotReduce (wrapper)", 0);
  __pyx_self = __pyx_self;
  {
    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:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__index);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__patch_probs);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("logDotReduce", 1, 4, 4, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__switch_probs);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("logDotReduce", 1, 4, 4, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__plhs);
        if (likely(values[3])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("logDotReduce", 1, 4, 4, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "logDotReduce") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __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_index = values[0];
    __pyx_v_patch_probs = values[1];
    __pyx_v_switch_probs = values[2];
    __pyx_v_plhs = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("logDotReduce", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.logDotReduce", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6cogent_6evolve_16_likelihood_tree_6logDotReduce(__pyx_self, __pyx_v_index, __pyx_v_patch_probs, __pyx_v_switch_probs, __pyx_v_plhs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cogent/evolve/_likelihood_tree.pyx":70
 *     return total
 * 
 * def logDotReduce(index, patch_probs, switch_probs, plhs):             # <<<<<<<<<<<<<<
 *     cdef int site, i, j, k, n, uniq, exponent, length, most_probable_state
 *     cdef double result, BASE
 */

static PyObject *__pyx_pf_6cogent_6evolve_16_likelihood_tree_6logDotReduce(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_index, PyObject *__pyx_v_patch_probs, PyObject *__pyx_v_switch_probs, PyObject *__pyx_v_plhs) {
  int __pyx_v_site;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_v_k;
  int __pyx_v_n;
  int __pyx_v_uniq;
  int __pyx_v_exponent;
  int __pyx_v_length;
  int __pyx_v_most_probable_state;
  double __pyx_v_result;
  double __pyx_v_BASE;
  double *__pyx_v_sp;
  double *__pyx_v_pl;
  double *__pyx_v_state;
  double *__pyx_v_prev;
  double *__pyx_v_tmp;
  long *__pyx_v_index_data;
  PyObject *__pyx_v_patch_probs1 = 0;
  PyObject *__pyx_v_patch_probs2 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  double *__pyx_t_3;
  double *__pyx_t_4;
  long *__pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("logDotReduce", 0);

  /* "cogent/evolve/_likelihood_tree.pyx":76
 *     cdef long *index_data
 *     cdef object patch_probs1, patch_probs2
 *     BASE = 2.0 ** 1000             # <<<<<<<<<<<<<<
 *     patch_probs1 = patch_probs.copy()
 *     patch_probs2 = patch_probs.copy()
 */
  __pyx_v_BASE = pow(2.0, 1000.0);

  /* "cogent/evolve/_likelihood_tree.pyx":77
 *     cdef object patch_probs1, patch_probs2
 *     BASE = 2.0 ** 1000
 *     patch_probs1 = patch_probs.copy()             # <<<<<<<<<<<<<<
 *     patch_probs2 = patch_probs.copy()
 *     n = uniq = length = 0
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_patch_probs, __pyx_n_s__copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __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[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_patch_probs1 = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":78
 *     BASE = 2.0 ** 1000
 *     patch_probs1 = patch_probs.copy()
 *     patch_probs2 = patch_probs.copy()             # <<<<<<<<<<<<<<
 *     n = uniq = length = 0
 *     state = checkArrayDouble1D(patch_probs1, &n)
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_patch_probs, __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_patch_probs2 = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":79
 *     patch_probs1 = patch_probs.copy()
 *     patch_probs2 = patch_probs.copy()
 *     n = uniq = length = 0             # <<<<<<<<<<<<<<
 *     state = checkArrayDouble1D(patch_probs1, &n)
 *     prev = checkArrayDouble1D(patch_probs2, &n)
 */
  __pyx_v_n = 0;
  __pyx_v_uniq = 0;
  __pyx_v_length = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":80
 *     patch_probs2 = patch_probs.copy()
 *     n = uniq = length = 0
 *     state = checkArrayDouble1D(patch_probs1, &n)             # <<<<<<<<<<<<<<
 *     prev = checkArrayDouble1D(patch_probs2, &n)
 *     sp = checkArrayDouble2D(switch_probs, &n, &n)
 */
  __pyx_t_3 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_patch_probs1), (&__pyx_v_n)); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_state = __pyx_t_3;

  /* "cogent/evolve/_likelihood_tree.pyx":81
 *     n = uniq = length = 0
 *     state = checkArrayDouble1D(patch_probs1, &n)
 *     prev = checkArrayDouble1D(patch_probs2, &n)             # <<<<<<<<<<<<<<
 *     sp = checkArrayDouble2D(switch_probs, &n, &n)
 *     pl = checkArrayDouble2D(plhs, &uniq, &n)
 */
  __pyx_t_3 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_patch_probs2), (&__pyx_v_n)); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_prev = __pyx_t_3;

  /* "cogent/evolve/_likelihood_tree.pyx":82
 *     state = checkArrayDouble1D(patch_probs1, &n)
 *     prev = checkArrayDouble1D(patch_probs2, &n)
 *     sp = checkArrayDouble2D(switch_probs, &n, &n)             # <<<<<<<<<<<<<<
 *     pl = checkArrayDouble2D(plhs, &uniq, &n)
 *     index_data = checkArrayLong1D(index, &length)
 */
  __pyx_t_4 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_switch_probs), (&__pyx_v_n), (&__pyx_v_n)); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_sp = __pyx_t_4;

  /* "cogent/evolve/_likelihood_tree.pyx":83
 *     prev = checkArrayDouble1D(patch_probs2, &n)
 *     sp = checkArrayDouble2D(switch_probs, &n, &n)
 *     pl = checkArrayDouble2D(plhs, &uniq, &n)             # <<<<<<<<<<<<<<
 *     index_data = checkArrayLong1D(index, &length)
 *     exponent = 0
 */
  __pyx_t_4 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayDouble2D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_plhs), (&__pyx_v_uniq), (&__pyx_v_n)); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_pl = __pyx_t_4;

  /* "cogent/evolve/_likelihood_tree.pyx":84
 *     sp = checkArrayDouble2D(switch_probs, &n, &n)
 *     pl = checkArrayDouble2D(plhs, &uniq, &n)
 *     index_data = checkArrayLong1D(index, &length)             # <<<<<<<<<<<<<<
 *     exponent = 0
 *     for site from 0 <= site < length:
 */
  __pyx_t_5 = __pyx_f_6cogent_6evolve_16_likelihood_tree_checkArrayLong1D(((__pyx_t_6cogent_6evolve_16_likelihood_tree_ArrayType)__pyx_v_index), (&__pyx_v_length)); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_index_data = __pyx_t_5;

  /* "cogent/evolve/_likelihood_tree.pyx":85
 *     pl = checkArrayDouble2D(plhs, &uniq, &n)
 *     index_data = checkArrayLong1D(index, &length)
 *     exponent = 0             # <<<<<<<<<<<<<<
 *     for site from 0 <= site < length:
 *         k = index_data[site]
 */
  __pyx_v_exponent = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":86
 *     index_data = checkArrayLong1D(index, &length)
 *     exponent = 0
 *     for site from 0 <= site < length:             # <<<<<<<<<<<<<<
 *         k = index_data[site]
 *         if k >= uniq:
 */
  __pyx_t_6 = __pyx_v_length;
  for (__pyx_v_site = 0; __pyx_v_site < __pyx_t_6; __pyx_v_site++) {

    /* "cogent/evolve/_likelihood_tree.pyx":87
 *     exponent = 0
 *     for site from 0 <= site < length:
 *         k = index_data[site]             # <<<<<<<<<<<<<<
 *         if k >= uniq:
 *             raise ValueError((k, uniq))
 */
    __pyx_v_k = (__pyx_v_index_data[__pyx_v_site]);

    /* "cogent/evolve/_likelihood_tree.pyx":88
 *     for site from 0 <= site < length:
 *         k = index_data[site]
 *         if k >= uniq:             # <<<<<<<<<<<<<<
 *             raise ValueError((k, uniq))
 *         tmp = prev
 */
    __pyx_t_7 = (__pyx_v_k >= __pyx_v_uniq);
    if (__pyx_t_7) {

      /* "cogent/evolve/_likelihood_tree.pyx":89
 *         k = index_data[site]
 *         if k >= uniq:
 *             raise ValueError((k, uniq))             # <<<<<<<<<<<<<<
 *         tmp = prev
 *         prev = state
 */
      __pyx_t_1 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_uniq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 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_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "cogent/evolve/_likelihood_tree.pyx":90
 *         if k >= uniq:
 *             raise ValueError((k, uniq))
 *         tmp = prev             # <<<<<<<<<<<<<<
 *         prev = state
 *         state = tmp
 */
    __pyx_v_tmp = __pyx_v_prev;

    /* "cogent/evolve/_likelihood_tree.pyx":91
 *             raise ValueError((k, uniq))
 *         tmp = prev
 *         prev = state             # <<<<<<<<<<<<<<
 *         state = tmp
 *         most_probable_state = 0
 */
    __pyx_v_prev = __pyx_v_state;

    /* "cogent/evolve/_likelihood_tree.pyx":92
 *         tmp = prev
 *         prev = state
 *         state = tmp             # <<<<<<<<<<<<<<
 *         most_probable_state = 0
 *         for i from 0 <= i < n:
 */
    __pyx_v_state = __pyx_v_tmp;

    /* "cogent/evolve/_likelihood_tree.pyx":93
 *         prev = state
 *         state = tmp
 *         most_probable_state = 0             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < n:
 *             state[i] = 0
 */
    __pyx_v_most_probable_state = 0;

    /* "cogent/evolve/_likelihood_tree.pyx":94
 *         state = tmp
 *         most_probable_state = 0
 *         for i from 0 <= i < n:             # <<<<<<<<<<<<<<
 *             state[i] = 0
 *             for j from 0 <= j < n:
 */
    __pyx_t_9 = __pyx_v_n;
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

      /* "cogent/evolve/_likelihood_tree.pyx":95
 *         most_probable_state = 0
 *         for i from 0 <= i < n:
 *             state[i] = 0             # <<<<<<<<<<<<<<
 *             for j from 0 <= j < n:
 *                 state[i] += prev[j] * sp[j*n+i]
 */
      (__pyx_v_state[__pyx_v_i]) = 0.0;

      /* "cogent/evolve/_likelihood_tree.pyx":96
 *         for i from 0 <= i < n:
 *             state[i] = 0
 *             for j from 0 <= j < n:             # <<<<<<<<<<<<<<
 *                 state[i] += prev[j] * sp[j*n+i]
 *             state[i] *= pl[k*n+i]
 */
      __pyx_t_10 = __pyx_v_n;
      for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_10; __pyx_v_j++) {

        /* "cogent/evolve/_likelihood_tree.pyx":97
 *             state[i] = 0
 *             for j from 0 <= j < n:
 *                 state[i] += prev[j] * sp[j*n+i]             # <<<<<<<<<<<<<<
 *             state[i] *= pl[k*n+i]
 *             if state[i] > state[most_probable_state]:
 */
        __pyx_t_11 = __pyx_v_i;
        (__pyx_v_state[__pyx_t_11]) = ((__pyx_v_state[__pyx_t_11]) + ((__pyx_v_prev[__pyx_v_j]) * (__pyx_v_sp[((__pyx_v_j * __pyx_v_n) + __pyx_v_i)])));
      }

      /* "cogent/evolve/_likelihood_tree.pyx":98
 *             for j from 0 <= j < n:
 *                 state[i] += prev[j] * sp[j*n+i]
 *             state[i] *= pl[k*n+i]             # <<<<<<<<<<<<<<
 *             if state[i] > state[most_probable_state]:
 *                 most_probable_state = i
 */
      __pyx_t_10 = __pyx_v_i;
      (__pyx_v_state[__pyx_t_10]) = ((__pyx_v_state[__pyx_t_10]) * (__pyx_v_pl[((__pyx_v_k * __pyx_v_n) + __pyx_v_i)]));

      /* "cogent/evolve/_likelihood_tree.pyx":99
 *                 state[i] += prev[j] * sp[j*n+i]
 *             state[i] *= pl[k*n+i]
 *             if state[i] > state[most_probable_state]:             # <<<<<<<<<<<<<<
 *                 most_probable_state = i
 *         while state[most_probable_state] < 1.0:
 */
      __pyx_t_7 = ((__pyx_v_state[__pyx_v_i]) > (__pyx_v_state[__pyx_v_most_probable_state]));
      if (__pyx_t_7) {

        /* "cogent/evolve/_likelihood_tree.pyx":100
 *             state[i] *= pl[k*n+i]
 *             if state[i] > state[most_probable_state]:
 *                 most_probable_state = i             # <<<<<<<<<<<<<<
 *         while state[most_probable_state] < 1.0:
 *             for i from 0 <= i < n:
 */
        __pyx_v_most_probable_state = __pyx_v_i;
        goto __pyx_L10;
      }
      __pyx_L10:;
    }

    /* "cogent/evolve/_likelihood_tree.pyx":101
 *             if state[i] > state[most_probable_state]:
 *                 most_probable_state = i
 *         while state[most_probable_state] < 1.0:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < n:
 *                 state[i] *= BASE
 */
    while (1) {
      __pyx_t_7 = ((__pyx_v_state[__pyx_v_most_probable_state]) < 1.0);
      if (!__pyx_t_7) break;

      /* "cogent/evolve/_likelihood_tree.pyx":102
 *                 most_probable_state = i
 *         while state[most_probable_state] < 1.0:
 *             for i from 0 <= i < n:             # <<<<<<<<<<<<<<
 *                 state[i] *= BASE
 *             exponent += -1
 */
      __pyx_t_9 = __pyx_v_n;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

        /* "cogent/evolve/_likelihood_tree.pyx":103
 *         while state[most_probable_state] < 1.0:
 *             for i from 0 <= i < n:
 *                 state[i] *= BASE             # <<<<<<<<<<<<<<
 *             exponent += -1
 *     result = 0.0
 */
        __pyx_t_10 = __pyx_v_i;
        (__pyx_v_state[__pyx_t_10]) = ((__pyx_v_state[__pyx_t_10]) * __pyx_v_BASE);
      }

      /* "cogent/evolve/_likelihood_tree.pyx":104
 *             for i from 0 <= i < n:
 *                 state[i] *= BASE
 *             exponent += -1             # <<<<<<<<<<<<<<
 *     result = 0.0
 *     for i from 0 <= i < n:
 */
      __pyx_v_exponent = (__pyx_v_exponent + -1);
    }
  }

  /* "cogent/evolve/_likelihood_tree.pyx":105
 *                 state[i] *= BASE
 *             exponent += -1
 *     result = 0.0             # <<<<<<<<<<<<<<
 *     for i from 0 <= i < n:
 *         result += state[i]
 */
  __pyx_v_result = 0.0;

  /* "cogent/evolve/_likelihood_tree.pyx":106
 *             exponent += -1
 *     result = 0.0
 *     for i from 0 <= i < n:             # <<<<<<<<<<<<<<
 *         result += state[i]
 * 
 */
  __pyx_t_6 = __pyx_v_n;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) {

    /* "cogent/evolve/_likelihood_tree.pyx":107
 *     result = 0.0
 *     for i from 0 <= i < n:
 *         result += state[i]             # <<<<<<<<<<<<<<
 * 
 *     return log(result) + exponent * log(BASE)
 */
    __pyx_v_result = (__pyx_v_result + (__pyx_v_state[__pyx_v_i]));
  }

  /* "cogent/evolve/_likelihood_tree.pyx":109
 *         result += state[i]
 * 
 *     return log(result) + exponent * log(BASE)             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = PyFloat_FromDouble((log(__pyx_v_result) + (__pyx_v_exponent * log(__pyx_v_BASE)))); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 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_8);
  __Pyx_AddTraceback("cogent.evolve._likelihood_tree.logDotReduce", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_patch_probs1);
  __Pyx_XDECREF(__pyx_v_patch_probs2);
  __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 = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_likelihood_tree"),
    0, /* 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_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1},
  {&__pyx_n_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 1},
  {&__pyx_n_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 1},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__BASE, __pyx_k__BASE, sizeof(__pyx_k__BASE), 0, 0, 1, 1},
  {&__pyx_n_s__M, __pyx_k__M, sizeof(__pyx_k__M), 0, 0, 1, 1},
  {&__pyx_n_s__S, __pyx_k__S, sizeof(__pyx_k__S), 0, 0, 1, 1},
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s__U, __pyx_k__U, sizeof(__pyx_k__U), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____array_struct__, __pyx_k____array_struct__, sizeof(__pyx_k____array_struct__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1},
  {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1},
  {&__pyx_n_s__child_indexes, __pyx_k__child_indexes, sizeof(__pyx_k__child_indexes), 0, 0, 1, 1},
  {&__pyx_n_s__chr, __pyx_k__chr, sizeof(__pyx_k__chr), 0, 0, 1, 1},
  {&__pyx_n_s__copy, __pyx_k__copy, sizeof(__pyx_k__copy), 0, 0, 1, 1},
  {&__pyx_n_s__counts, __pyx_k__counts, sizeof(__pyx_k__counts), 0, 0, 1, 1},
  {&__pyx_n_s__exponent, __pyx_k__exponent, sizeof(__pyx_k__exponent), 0, 0, 1, 1},
  {&__pyx_n_s__first, __pyx_k__first, sizeof(__pyx_k__first), 0, 0, 1, 1},
  {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
  {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1},
  {&__pyx_n_s__index_data, __pyx_k__index_data, sizeof(__pyx_k__index_data), 0, 0, 1, 1},
  {&__pyx_n_s__input_likelihoods, __pyx_k__input_likelihoods, sizeof(__pyx_k__input_likelihoods), 0, 0, 1, 1},
  {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1},
  {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1},
  {&__pyx_n_s__length, __pyx_k__length, sizeof(__pyx_k__length), 0, 0, 1, 1},
  {&__pyx_n_s__likelihoods, __pyx_k__likelihoods, sizeof(__pyx_k__likelihoods), 0, 0, 1, 1},
  {&__pyx_n_s__likelihoods_data, __pyx_k__likelihoods_data, sizeof(__pyx_k__likelihoods_data), 0, 0, 1, 1},
  {&__pyx_n_s__logDotReduce, __pyx_k__logDotReduce, sizeof(__pyx_k__logDotReduce), 0, 0, 1, 1},
  {&__pyx_n_s__m, __pyx_k__m, sizeof(__pyx_k__m), 0, 0, 1, 1},
  {&__pyx_n_s__most_probable_state, __pyx_k__most_probable_state, sizeof(__pyx_k__most_probable_state), 0, 0, 1, 1},
  {&__pyx_n_s__mprobs, __pyx_k__mprobs, sizeof(__pyx_k__mprobs), 0, 0, 1, 1},
  {&__pyx_n_s__mprobs_data, __pyx_k__mprobs_data, sizeof(__pyx_k__mprobs_data), 0, 0, 1, 1},
  {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
  {&__pyx_n_s__patch_probs, __pyx_k__patch_probs, sizeof(__pyx_k__patch_probs), 0, 0, 1, 1},
  {&__pyx_n_s__patch_probs1, __pyx_k__patch_probs1, sizeof(__pyx_k__patch_probs1), 0, 0, 1, 1},
  {&__pyx_n_s__patch_probs2, __pyx_k__patch_probs2, sizeof(__pyx_k__patch_probs2), 0, 0, 1, 1},
  {&__pyx_n_s__pl, __pyx_k__pl, sizeof(__pyx_k__pl), 0, 0, 1, 1},
  {&__pyx_n_s__plhs, __pyx_k__plhs, sizeof(__pyx_k__plhs), 0, 0, 1, 1},
  {&__pyx_n_s__posn, __pyx_k__posn, sizeof(__pyx_k__posn), 0, 0, 1, 1},
  {&__pyx_n_s__prev, __pyx_k__prev, sizeof(__pyx_k__prev), 0, 0, 1, 1},
  {&__pyx_n_s__result, __pyx_k__result, sizeof(__pyx_k__result), 0, 0, 1, 1},
  {&__pyx_n_s__site, __pyx_k__site, sizeof(__pyx_k__site), 0, 0, 1, 1},
  {&__pyx_n_s__sp, __pyx_k__sp, sizeof(__pyx_k__sp), 0, 0, 1, 1},
  {&__pyx_n_s__state, __pyx_k__state, sizeof(__pyx_k__state), 0, 0, 1, 1},
  {&__pyx_n_s__sumInputLikelihoods, __pyx_k__sumInputLikelihoods, sizeof(__pyx_k__sumInputLikelihoods), 0, 0, 1, 1},
  {&__pyx_n_s__switch_probs, __pyx_k__switch_probs, sizeof(__pyx_k__switch_probs), 0, 0, 1, 1},
  {&__pyx_n_s__target_data, __pyx_k__target_data, sizeof(__pyx_k__target_data), 0, 0, 1, 1},
  {&__pyx_n_s__tmp, __pyx_k__tmp, sizeof(__pyx_k__tmp), 0, 0, 1, 1},
  {&__pyx_n_s__total, __pyx_k__total, sizeof(__pyx_k__total), 0, 0, 1, 1},
  {&__pyx_n_s__u, __pyx_k__u, sizeof(__pyx_k__u), 0, 0, 1, 1},
  {&__pyx_n_s__uniq, __pyx_k__uniq, sizeof(__pyx_k__uniq), 0, 0, 1, 1},
  {&__pyx_n_s__values_data, __pyx_k__values_data, sizeof(__pyx_k__values_data), 0, 0, 1, 1},
  {&__pyx_n_s__version_info, __pyx_k__version_info, sizeof(__pyx_k__version_info), 0, 0, 1, 1},
  {&__pyx_n_s__weights_data, __pyx_k__weights_data, sizeof(__pyx_k__weights_data), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __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);

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":44
 *     cdef char kind
 *     if A is None:
 *         raise TypeError("Array required, got None")             # <<<<<<<<<<<<<<
 *     cobj = A.__array_struct__
 *     a = <PyArrayInterface *> PyCObject_AsVoidPtr(cobj)
 */
  __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_2);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":62
 *                 (nd, a.nd))
 *     if not a.flags & CONTIGUOUS:
 *         raise ValueError ('Noncontiguous array')             # <<<<<<<<<<<<<<
 * 
 *     cdef int dimension, val
 */
  __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_8);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_7));
  PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));

  /* "cogent/evolve/_likelihood_tree.pyx":2
 * include "../../include/numerical_pyrex.pyx"
 * version_info = (2, 1)             # <<<<<<<<<<<<<<
 * __version__ = "('1', '5', '3')"
 * 
 */
  __pyx_k_tuple_11 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_11);
  __Pyx_INCREF(__pyx_int_2);
  PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, __pyx_int_2);
  __Pyx_GIVEREF(__pyx_int_2);
  __Pyx_INCREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_k_tuple_11, 1, __pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));

  /* "cogent/evolve/_likelihood_tree.pyx":8
 *     double log (double x)
 * 
 * def sumInputLikelihoods(child_indexes, result, likelihoods):             # <<<<<<<<<<<<<<
 *     # M is dim of alphabet, S is non-redundandt parent seq length,
 *     # U is length
 */
  __pyx_k_tuple_12 = PyTuple_New(15); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_12);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__child_indexes));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_n_s__child_indexes));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__child_indexes));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__result));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 1, ((PyObject *)__pyx_n_s__result));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__result));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__likelihoods));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 2, ((PyObject *)__pyx_n_s__likelihoods));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__likelihoods));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__M));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 3, ((PyObject *)__pyx_n_s__M));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__M));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__S));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 4, ((PyObject *)__pyx_n_s__S));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__S));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__U));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 5, ((PyObject *)__pyx_n_s__U));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__U));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__m));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 6, ((PyObject *)__pyx_n_s__m));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__m));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 7, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__u));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 8, ((PyObject *)__pyx_n_s__u));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__u));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__c));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 9, ((PyObject *)__pyx_n_s__c));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__c));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__values_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 10, ((PyObject *)__pyx_n_s__values_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__values_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__index_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 11, ((PyObject *)__pyx_n_s__index_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__index_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__target_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 12, ((PyObject *)__pyx_n_s__target_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__target_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__first));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 13, ((PyObject *)__pyx_n_s__first));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__first));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__index));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 14, ((PyObject *)__pyx_n_s__index));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__index));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
  __pyx_k_codeobj_13 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_14, __pyx_n_s__sumInputLikelihoods, 8, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":41
 *     return result
 * 
 * def getTotalLogLikelihood(counts, input_likelihoods, mprobs):             # <<<<<<<<<<<<<<
 *     cdef int S, M, i, m
 *     cdef double posn, total
 */
  __pyx_k_tuple_16 = PyTuple_New(12); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_16);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__counts));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_n_s__counts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__counts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__input_likelihoods));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 1, ((PyObject *)__pyx_n_s__input_likelihoods));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__input_likelihoods));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mprobs));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 2, ((PyObject *)__pyx_n_s__mprobs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mprobs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__S));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 3, ((PyObject *)__pyx_n_s__S));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__S));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__M));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 4, ((PyObject *)__pyx_n_s__M));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__M));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 5, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__m));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 6, ((PyObject *)__pyx_n_s__m));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__m));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__posn));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 7, ((PyObject *)__pyx_n_s__posn));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__posn));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__total));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 8, ((PyObject *)__pyx_n_s__total));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__total));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__likelihoods_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 9, ((PyObject *)__pyx_n_s__likelihoods_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__likelihoods_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mprobs_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 10, ((PyObject *)__pyx_n_s__mprobs_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mprobs_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__weights_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 11, ((PyObject *)__pyx_n_s__weights_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__weights_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16));
  __pyx_k_codeobj_17 = (PyObject*)__Pyx_PyCode_New(3, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_14, __pyx_n_s_18, 41, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_17)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":58
 *     return total
 * 
 * def getLogSumAcrossSites(counts, input_likelihoods):             # <<<<<<<<<<<<<<
 *     cdef int S, i
 *     cdef double total
 */
  __pyx_k_tuple_19 = PyTuple_New(7); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_19);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__counts));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_n_s__counts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__counts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__input_likelihoods));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 1, ((PyObject *)__pyx_n_s__input_likelihoods));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__input_likelihoods));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__S));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 2, ((PyObject *)__pyx_n_s__S));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__S));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 3, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__total));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 4, ((PyObject *)__pyx_n_s__total));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__total));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__likelihoods_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 5, ((PyObject *)__pyx_n_s__likelihoods_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__likelihoods_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__weights_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 6, ((PyObject *)__pyx_n_s__weights_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__weights_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19));
  __pyx_k_codeobj_20 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_14, __pyx_n_s_21, 58, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_20)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":70
 *     return total
 * 
 * def logDotReduce(index, patch_probs, switch_probs, plhs):             # <<<<<<<<<<<<<<
 *     cdef int site, i, j, k, n, uniq, exponent, length, most_probable_state
 *     cdef double result, BASE
 */
  __pyx_k_tuple_22 = PyTuple_New(23); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_22);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__index));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__index));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__index));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__patch_probs));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 1, ((PyObject *)__pyx_n_s__patch_probs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__patch_probs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__switch_probs));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 2, ((PyObject *)__pyx_n_s__switch_probs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__switch_probs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__plhs));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 3, ((PyObject *)__pyx_n_s__plhs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__plhs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__site));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 4, ((PyObject *)__pyx_n_s__site));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__site));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 5, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__j));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 6, ((PyObject *)__pyx_n_s__j));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__j));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__k));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 7, ((PyObject *)__pyx_n_s__k));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__k));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__n));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 8, ((PyObject *)__pyx_n_s__n));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__uniq));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 9, ((PyObject *)__pyx_n_s__uniq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__uniq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__exponent));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 10, ((PyObject *)__pyx_n_s__exponent));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exponent));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__length));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 11, ((PyObject *)__pyx_n_s__length));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__length));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__most_probable_state));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 12, ((PyObject *)__pyx_n_s__most_probable_state));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__most_probable_state));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__result));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 13, ((PyObject *)__pyx_n_s__result));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__result));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__BASE));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 14, ((PyObject *)__pyx_n_s__BASE));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__BASE));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__sp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 15, ((PyObject *)__pyx_n_s__sp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pl));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 16, ((PyObject *)__pyx_n_s__pl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__state));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 17, ((PyObject *)__pyx_n_s__state));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__state));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__prev));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 18, ((PyObject *)__pyx_n_s__prev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__prev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__tmp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 19, ((PyObject *)__pyx_n_s__tmp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tmp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__index_data));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 20, ((PyObject *)__pyx_n_s__index_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__index_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__patch_probs1));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 21, ((PyObject *)__pyx_n_s__patch_probs1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__patch_probs1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__patch_probs2));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 22, ((PyObject *)__pyx_n_s__patch_probs2));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__patch_probs2));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));
  __pyx_k_codeobj_23 = (PyObject*)__Pyx_PyCode_New(4, 0, 23, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_14, __pyx_n_s__logDotReduce, 70, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_23)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __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[1]; __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[1]; __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[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_likelihood_tree(void); /*proto*/
PyMODINIT_FUNC init_likelihood_tree(void)
#else
PyMODINIT_FUNC PyInit__likelihood_tree(void); /*proto*/
PyMODINIT_FUNC PyInit__likelihood_tree(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  __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__likelihood_tree(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[1]; __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[1]; __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[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[1]; __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("_likelihood_tree"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_cogent__evolve___likelihood_tree) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[1]; __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 ---*/
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/Users/jrideout/.virtualenvs/pycogent/trunk/cogent/evolve/../../include/numerical_pyrex.pyx":13
 * #
 * 
 * __version__ = "('1', '5', '3')"             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "Python.h":
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_10)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":2
 * include "../../include/numerical_pyrex.pyx"
 * version_info = (2, 1)             # <<<<<<<<<<<<<<
 * __version__ = "('1', '5', '3')"
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__version_info, ((PyObject *)__pyx_k_tuple_11)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":3
 * include "../../include/numerical_pyrex.pyx"
 * version_info = (2, 1)
 * __version__ = "('1', '5', '3')"             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "math.h":
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_10)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "cogent/evolve/_likelihood_tree.pyx":8
 *     double log (double x)
 * 
 * def sumInputLikelihoods(child_indexes, result, likelihoods):             # <<<<<<<<<<<<<<
 *     # M is dim of alphabet, S is non-redundandt parent seq length,
 *     # U is length
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_6evolve_16_likelihood_tree_1sumInputLikelihoods, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sumInputLikelihoods, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":41
 *     return result
 * 
 * def getTotalLogLikelihood(counts, input_likelihoods, mprobs):             # <<<<<<<<<<<<<<
 *     cdef int S, M, i, m
 *     cdef double posn, total
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_6evolve_16_likelihood_tree_3getTotalLogLikelihood, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_18, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":58
 *     return total
 * 
 * def getLogSumAcrossSites(counts, input_likelihoods):             # <<<<<<<<<<<<<<
 *     cdef int S, i
 *     cdef double total
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_6evolve_16_likelihood_tree_5getLogSumAcrossSites, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_21, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":70
 *     return total
 * 
 * def logDotReduce(index, patch_probs, switch_probs, plhs):             # <<<<<<<<<<<<<<
 *     cdef int site, i, j, k, n, uniq, exponent, length, most_probable_state
 *     cdef double result, BASE
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6cogent_6evolve_16_likelihood_tree_7logDotReduce, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logDotReduce, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cogent/evolve/_likelihood_tree.pyx":1
 * include "../../include/numerical_pyrex.pyx"             # <<<<<<<<<<<<<<
 * version_info = (2, 1)
 * __version__ = "('1', '5', '3')"
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  if (__pyx_m) {
    __Pyx_AddTraceback("init cogent.evolve._likelihood_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init cogent.evolve._likelihood_tree");
  }
  __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_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result) {
        if (dict != __pyx_b) {
            PyErr_Clear();
            result = PyObject_GetAttr(__pyx_b, name);
        }
        if (!result) {
            PyErr_SetObject(PyExc_NameError, name);
        }
    }
    return result;
}

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);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    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;
    }
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        Py_DECREF(value);
        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) {
    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)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        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;
        }
        if (!value) {
            value = PyObject_CallObject(type, NULL);
        }
        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:
    return;
}
#endif

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 %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_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_AS_STRING(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;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    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 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);
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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;
    }
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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;
    }
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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;
    }
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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;
    }
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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;
    }
}

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_VERSION_HEX < 0x03000000
    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 (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 {
            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 void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

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;
}

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;
}


/* Type Conversion Functions */

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_VERSION_HEX < 0x03000000
  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_VERSION_HEX < 0x03000000
  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_VERSION_HEX < 0x03000000
    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)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
